use of org.codelibs.fess.exception.LdapOperationException in project fess by codelibs.
the class LdapManager method insert.
protected void insert(final String entryDN, final Attributes entry, final Supplier<Hashtable<String, String>> envSupplier) {
try (DirContextHolder holder = getDirContext(envSupplier)) {
logger.debug("Inserting {}", entryDN);
holder.get().createSubcontext(entryDN, entry);
} catch (final NamingException e) {
throw new LdapOperationException("Failed to add " + entryDN, e);
}
}
use of org.codelibs.fess.exception.LdapOperationException in project fess by codelibs.
the class LdapManager method search.
protected void search(final String baseDn, final String filter, final String[] returningAttrs, final Supplier<Hashtable<String, String>> envSupplier, final SearcConsumer consumer) {
try (DirContextHolder holder = getDirContext(envSupplier)) {
final SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
if (returningAttrs != null) {
controls.setReturningAttributes(returningAttrs);
}
consumer.accept(Collections.list(holder.get().search(baseDn, filter, controls)));
} catch (final NamingException e) {
throw new LdapOperationException("Failed to search " + baseDn + " with " + filter, e);
}
}
use of org.codelibs.fess.exception.LdapOperationException in project fess by codelibs.
the class LdapManager method getAttributeValueList.
protected List<Object> getAttributeValueList(final List<SearchResult> result, final String name) {
try {
for (final SearchResult srcrslt : result) {
final Attributes attrs = srcrslt.getAttributes();
final Attribute attr = attrs.get(name);
if (attr == null) {
continue;
}
final List<Object> attrList = new ArrayList<>();
for (int i = 0; i < attr.size(); i++) {
final Object attrValue = attr.get(i);
if (attrValue != null) {
attrList.add(attrValue);
}
}
return attrList;
}
return Collections.emptyList();
} catch (final NamingException e) {
throw new LdapOperationException("Failed to parse attribute values for " + name, e);
}
}
use of org.codelibs.fess.exception.LdapOperationException in project fess by codelibs.
the class LdapManager method delete.
protected void delete(final String entryDN, final Supplier<Hashtable<String, String>> envSupplier) {
try (DirContextHolder holder = getDirContext(envSupplier)) {
logger.debug("Deleting {}", entryDN);
holder.get().destroySubcontext(entryDN);
} catch (final NamingException e) {
throw new LdapOperationException("Failed to delete " + entryDN, e);
}
}
use of org.codelibs.fess.exception.LdapOperationException in project fess by codelibs.
the class LdapManager method changePassword.
public boolean changePassword(final String username, final String password) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
if (!fessConfig.isLdapAdminEnabled(username)) {
return false;
}
final Supplier<Hashtable<String, String>> adminEnv = () -> createAdminEnv();
final String userDN = fessConfig.getLdapAdminUserSecurityPrincipal(username);
search(fessConfig.getLdapAdminUserBaseDn(), fessConfig.getLdapAdminUserFilter(username), null, adminEnv, result -> {
if (!result.isEmpty()) {
final List<ModificationItem> modifyList = new ArrayList<>();
modifyReplaceEntry(modifyList, "userPassword", password);
modify(userDN, modifyList, adminEnv);
} else {
throw new LdapOperationException("User is not found: " + username);
}
});
return true;
}
Aggregations