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();
}
Aggregations