Search in sources :

Example 21 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project gitblit by gitblit.

the class LdapConnection method search.

public SearchResult search(String base, boolean dereferenceAliases, String filter, List<String> attributes) {
    try {
        SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
        if (dereferenceAliases) {
            searchRequest.setDerefPolicy(DereferencePolicy.SEARCHING);
        }
        if (attributes != null) {
            searchRequest.setAttributes(attributes);
        }
        SearchResult result = search(searchRequest);
        return result;
    } catch (LDAPException e) {
        logger.error("Problem creating LDAP search", e);
        return null;
    }
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult)

Example 22 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project zm-mailbox by Zimbra.

the class UBIDLdapContext method renameEntry.

@Override
public void renameEntry(String oldDn, String newDn) throws LdapException {
    try {
        DN newDN = new DN(newDn);
        String newRDN = newDN.getRDNString();
        String newSuperiorDN = newDN.getParentString();
        UBIDLdapOperation.MODIFY_DN.execute(this, oldDn, newRDN, true, newSuperiorDN);
    } catch (LDAPException e) {
        throw mapToLdapException("unable to rename entry", e);
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) DN(com.unboundid.ldap.sdk.DN) ASN1OctetString(com.unboundid.asn1.ASN1OctetString)

Example 23 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project zm-mailbox by Zimbra.

the class UBIDLdapContext method compare.

/**
 * Perform an LDAPv3 compare operation, which may be used to determine whether a specified entry contains a given
 * attribute value.  Compare requests include the DN of the target entry, the name of the target attribute,
 * and the value for which to make the determination.
 *
 * @param  dn The DN of the entry in which the comparison is to be performed.  It must not be {@code null}.
 * @param  attributeName   The name of the target attribute for which the comparison is to be performed.
 *         It must not be {@code null}.
 * @param  assertionValue  The assertion value to verify within the entry.  It must not be {@code null}.
 */
@Override
public boolean compare(final String dn, final String attributeName, final String assertionValue) throws ServiceException {
    CompareRequest compareRequest = new CompareRequest(dn, attributeName, assertionValue);
    CompareResult compareResult;
    try {
        compareResult = UBIDLdapOperation.COMPARE.execute(this, compareRequest);
        // determine whether the compare matched.
        return compareResult.compareMatched();
    } catch (LDAPException le) {
        ZimbraLog.ldap.debug("Compare failed result code='%s' error message='%s'", le.getResultCode(), le.getDiagnosticMessage(), le);
    }
    return false;
}
Also used : CompareRequest(com.unboundid.ldap.sdk.CompareRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) CompareResult(com.unboundid.ldap.sdk.CompareResult)

Example 24 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project zm-mailbox by Zimbra.

the class UBIDLdapContext method moveChildren.

@Override
public void moveChildren(String oldDn, String newDn) throws ServiceException {
    try {
        // use ZLdapFilter instead of just the native Filter so it's
        // convenient for stating
        ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
        // Filter filter = Filter.createPresenceFilter(LdapConstants.ATTR_OBJECTCLASS);
        SearchRequest searchRequest = new SearchRequest(oldDn, SearchScope.ONE, derefAliasPolicy, // size limit
        0, // time limit
        0, // getTypesOnly
        false, ((UBIDLdapFilter) filter).getNative());
        searchRequest.setAttributes("dn");
        SearchResult result = UBIDLdapOperation.SEARCH.execute(this, searchRequest, filter);
        List<SearchResultEntry> entries = result.getSearchEntries();
        for (SearchResultEntry entry : entries) {
            DN entryDN = entry.getParsedDN();
            String childDn = entryDN.toNormalizedString();
            String childRdn = entryDN.getRDNString();
            UBIDLdapOperation.MODIFY_DN.execute(this, childDn, childRdn, true, newDn);
        }
    } catch (LDAPException e) {
        throw mapToLdapException("unable to move children", e);
    }
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult) DN(com.unboundid.ldap.sdk.DN) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 25 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project zm-mailbox by Zimbra.

the class UBIDLdapContext method testAndModifyAttributes.

@Override
public boolean testAndModifyAttributes(String dn, ZModificationList modList, ZLdapFilter testFilter) throws LdapException {
    try {
        ModifyRequest modReq = new ModifyRequest(dn, ((UBIDModificationList) modList).getModList());
        modReq.addControl(new AssertionRequestControl(((UBIDLdapFilter) testFilter).getNative()));
        LDAPResult result = UBIDLdapOperation.TEST_AND_MODIFY_ATTRS.execute(this, modReq);
        return true;
    } catch (LDAPException e) {
        if (e.getResultCode() == ResultCode.ASSERTION_FAILED) {
            // The modification failed because the the filter does not match the target entry
            return false;
        } else {
            // The modification failed for some other reason.
            throw mapToLdapException("unable to test and modify attributes", e);
        }
    }
}
Also used : AssertionRequestControl(com.unboundid.ldap.sdk.controls.AssertionRequestControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)59 SearchResult (com.unboundid.ldap.sdk.SearchResult)15 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)13 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)11 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)11 IOException (java.io.IOException)11 ResultCode (com.unboundid.ldap.sdk.ResultCode)9 LDIFReader (com.unboundid.ldif.LDIFReader)8 GeneralSecurityException (java.security.GeneralSecurityException)8 DN (com.unboundid.ldap.sdk.DN)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 Entry (com.unboundid.ldap.sdk.Entry)5 Filter (com.unboundid.ldap.sdk.Filter)5 LDAPConnectionPool (com.unboundid.ldap.sdk.LDAPConnectionPool)5 ArrayList (java.util.ArrayList)5 LdifDataUtility (org.gluu.persist.ldap.impl.LdifDataUtility)5 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)4 BindResult (com.unboundid.ldap.sdk.BindResult)4 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)4