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