Java Code Examples for javax.naming.ldap.LdapContext#addToEnvironment()

The following examples show how to use javax.naming.ldap.LdapContext#addToEnvironment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadOnlyLDAPUser.java    From james-project with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that the password supplied is actually the user's password, by
 * attempting to rebind to a copy of the LDAP server context using the user's 
 * username and the supplied password.
 * 
 * @param password
 *            The password to validate.
 * @return <code>True</code> if a connection can successfully be established
 *         to the LDAP host using the user's id and the supplied password,
 *         and <code>False</code> otherwise.
 */
@Override
public boolean verifyPassword(String password) {
    boolean result = false;
    LdapContext ldapContext = null;
    try {
        ldapContext = this.ldapContext.newInstance(null);
        ldapContext.addToEnvironment(Context.SECURITY_AUTHENTICATION,
                LdapConstants.SECURITY_AUTHENTICATION_SIMPLE);
        ldapContext.addToEnvironment(Context.SECURITY_PRINCIPAL, userDN);
        ldapContext.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
        ldapContext.reconnect(null);
        result = true;
    } catch (NamingException exception) {
        // no-op
    } finally {
        if (null != ldapContext) {
            try {
                ldapContext.close();
            } catch (NamingException ex) {
                // no-op
            }
        }
    }
    return result;
}
 
Example 2
Source File: DefaultTlsDirContextAuthenticationStrategy.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
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 a server call as we have updated the environment (gh-430, gh-502)
	ctx.lookup("");
}
 
Example 3
Source File: ExternalTlsDirContextAuthenticationStrategy.java    From spring-ldap with Apache License 2.0 4 votes vote down vote up
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
	ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, EXTERNAL_AUTHENTICATION);
}