Search in sources :

Example 1 with LdapOperationException

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);
    }
}
Also used : LdapOperationException(org.codelibs.fess.exception.LdapOperationException) NamingException(javax.naming.NamingException)

Example 2 with LdapOperationException

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);
    }
}
Also used : LdapOperationException(org.codelibs.fess.exception.LdapOperationException) SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException)

Example 3 with LdapOperationException

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);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) ArrayList(java.util.ArrayList) LdapOperationException(org.codelibs.fess.exception.LdapOperationException) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException)

Example 4 with LdapOperationException

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);
    }
}
Also used : LdapOperationException(org.codelibs.fess.exception.LdapOperationException) NamingException(javax.naming.NamingException)

Example 5 with LdapOperationException

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;
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) LdapOperationException(org.codelibs.fess.exception.LdapOperationException) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

LdapOperationException (org.codelibs.fess.exception.LdapOperationException)6 NamingException (javax.naming.NamingException)5 ArrayList (java.util.ArrayList)2 Hashtable (java.util.Hashtable)1 Attribute (javax.naming.directory.Attribute)1 Attributes (javax.naming.directory.Attributes)1 BasicAttribute (javax.naming.directory.BasicAttribute)1 BasicAttributes (javax.naming.directory.BasicAttributes)1 InitialDirContext (javax.naming.directory.InitialDirContext)1 ModificationItem (javax.naming.directory.ModificationItem)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1