@Override protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException { super.applyAuthentication(ctx, userDn, password); ctx.reconnect(ctx.getConnectControls()); } }
@Override protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException { super.applyAuthentication(ctx, userDn, password); ctx.reconnect(ctx.getConnectControls()); } }
@Override public void reconnect(Control[] controls) throws NamingException { if ( ! (delegating instanceof LdapContext)) throw Assert.unsupported(); ClassLoader previous = setSocketFactory(); try { ((LdapContext) delegating).reconnect(controls); } finally { unsetSocketFactory(previous); } }
@Test(expected = UncategorizedLdapException.class) public void standardExceptionIsPropagatedWhenExceptionRaisedAndNoControlsAreSet() throws Exception { doThrow(new NamingException("some LDAP exception")).when(ctx).reconnect( any(Control[].class)); ctxSource.getContext("user", "ignored"); }
@Test(expected = PasswordPolicyException.class) public void lockedPasswordPolicyControlRaisesPasswordPolicyException() throws Exception { when(ctx.getResponseControls()).thenReturn( new Control[] { new PasswordPolicyResponseControl( PasswordPolicyResponseControlTests.OPENLDAP_LOCKED_CTRL) }); doThrow(new NamingException("locked message")).when(ctx).reconnect( any(Control[].class)); ctxSource.getContext("user", "ignored"); } }
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, principal); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials); ctx.reconnect(rctls);
userContext.addToEnvironment(LdapContext.SECURITY_PRINCIPAL, distinguishedName); userContext.addToEnvironment(LdapContext.SECURITY_CREDENTIALS, password); userContext.reconnect(null); userContext.close();
private void changePasswordUsingAttributeModification (DistinguishedName userDn, String oldPassword, String newPassword) { final ModificationItem[] passwordChange = new ModificationItem[] { new ModificationItem( DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(passwordAttributeName, newPassword)) }; if (oldPassword == null) { template.modifyAttributes(userDn, passwordChange); return; } template.executeReadWrite(dirCtx -> { LdapContext ctx = (LdapContext) dirCtx; ctx.removeFromEnvironment("com.sun.jndi.ldap.connect.pool"); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, LdapUtils.getFullDn(userDn, ctx).toString()); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, oldPassword); // TODO: reconnect doesn't appear to actually change the credentials try { ctx.reconnect(null); } catch (javax.naming.AuthenticationException e) { throw new BadCredentialsException( "Authentication for password change failed."); } ctx.modifyAttributes(userDn, passwordChange); return null; }); }
@Override public Object operation() throws NamingException { ((LdapContext) getDelegate()).reconnect(connCtls); return null; } }.perform();
@Override public Object operation() throws NamingException { ((LdapContext) getDelegate()).reconnect(connCtls); return null; } }.perform();
public void reconnect(Control[] connCtls) throws NamingException { check(); getOriginal().reconnect(connCtls); }
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException { ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password); // Force reconnect with user credentials ctx.reconnect(null); }
@Override public void reconnect(Control[] controls) throws NamingException { if ( ! (delegating instanceof LdapContext)) throw Assert.unsupported(); ClassLoader previous = setSocketFactory(); try { ((LdapContext) delegating).reconnect(controls); } finally { unsetSocketFactory(previous); } }
@Override public void reconnect(Control[] controls) throws NamingException { if ( ! (delegating instanceof LdapContext)) throw Assert.unsupported(); if (socketFactory != null) ThreadLocalSSLSocketFactory.set(socketFactory); try { ((LdapContext) delegating).reconnect(controls); } finally { if (socketFactory != null) ThreadLocalSSLSocketFactory.unset(); } }
@Override public void reconnect(Control[] controls) throws NamingException { if ( ! (delegating instanceof LdapContext)) throw Assert.unsupported(); ClassLoader previous = setSocketFactory(); try { ((LdapContext) delegating).reconnect(controls); } finally { unsetSocketFactory(previous); } }
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException { ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password); // Force reconnect with user credentials ctx.reconnect(null); }
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException { ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password); // Force reconnect with user credentials ctx.reconnect(null); }
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException { ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password); // Force reconnect with user credentials ctx.reconnect(null); }
LdapContext userContext = ldapContext.newInstance(null); // copy context userContext.addToEnvironment(InitialDirContext.SECURITY_PRINCIPAL, userDn); userContext.addToEnvironment(InitialDirContext.SECURITY_CREDENTIALS, password); userContext.reconnect(null); // throws NamingException if creds wrong userContext.close();
@Test public void applyAuthenticationThenReconnectInvoked() throws Exception { this.strategy.applyAuthentication(this.context, "username", "password"); verify(this.context).reconnect(null); } }