Search in sources :

Example 76 with DirContext

use of javax.naming.directory.DirContext in project fess by codelibs.

the class LdapManager method login.

public OptionalEntity<FessUser> login(final String username, final String password) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (StringUtil.isBlank(fessConfig.getLdapProviderUrl())) {
        return OptionalEntity.empty();
    }
    if (!validate()) {
        return OptionalEntity.empty();
    }
    final Hashtable<String, String> env = createSearchEnv(username, password);
    try (DirContextHolder holder = getDirContext(() -> env)) {
        final DirContext context = holder.get();
        if (logger.isDebugEnabled()) {
            logger.debug("Logged in.", context);
        }
        return OptionalEntity.of(createLdapUser(username, env));
    } catch (final Exception e) {
        logger.debug("Login failed.", e);
    }
    return OptionalEntity.empty();
}
Also used : InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) NamingException(javax.naming.NamingException) LdapOperationException(org.codelibs.fess.exception.LdapOperationException)

Aggregations

DirContext (javax.naming.directory.DirContext)76 NamingException (javax.naming.NamingException)32 InitialDirContext (javax.naming.directory.InitialDirContext)32 SearchResult (javax.naming.directory.SearchResult)26 SearchControls (javax.naming.directory.SearchControls)22 Attributes (javax.naming.directory.Attributes)18 Attribute (javax.naming.directory.Attribute)16 NamingEnumeration (javax.naming.NamingEnumeration)14 Test (org.junit.Test)14 Hashtable (java.util.Hashtable)12 DistinguishedName (org.springframework.ldap.core.DistinguishedName)11 Name (javax.naming.Name)7 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 BasicAttribute (javax.naming.directory.BasicAttribute)6 BasicAttributes (javax.naming.directory.BasicAttributes)6 Authentication (org.springframework.security.core.Authentication)5 Principal (java.security.Principal)3 LdapContext (javax.naming.ldap.LdapContext)3