use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class DataLayer method modify.
/**
* Modifies an ldap entry.
*
* @param principal Authentication Principal.
* @param guid globally unique identifier for the entry.
* @param modifications Set of modifications for the entry.
* @exception AccessRightsException if insufficient access
* @exception EntryNotFoundException if the entry is not found.
* @exception UMSException if failure
*
* @supported.api
*/
public void modify(Principal principal, Guid guid, Collection<Modification> modifications) throws UMSException {
String id = guid.getDn();
ResultCode errorCode;
try {
ModifyRequest request = LDAPRequests.newModifyRequest(id);
for (Modification modification : modifications) {
request.addModification(modification);
}
int retry = 0;
while (retry <= connNumRetry) {
if (debug.messageEnabled()) {
debug.message("DataLayer.modify retry: " + retry);
}
try (Connection conn = getConnection(principal)) {
conn.modify(request);
return;
} catch (LdapException e) {
if (!retryErrorCodes.contains("" + e.getResult().getResultCode().toString()) || retry == connNumRetry) {
throw e;
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
}
}
}
} catch (LdapException e) {
if (debug.warningEnabled()) {
debug.warning("Exception in DataLayer.modify for DN: " + id, e);
}
errorCode = e.getResult().getResultCode();
if (ResultCode.NO_SUCH_OBJECT.equals(errorCode)) {
throw new EntryNotFoundException(id, e);
} else if (ResultCode.INSUFFICIENT_ACCESS_RIGHTS.equals(errorCode)) {
throw new AccessRightsException(id, e);
} else {
throw new UMSException(id, e);
}
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SMSLdapObject method create.
/**
* Create an entry in the directory using the principal name
*/
private static void create(Principal p, String dn, Map attrs) throws SMSException, SSOException {
int retry = 0;
Entry entry = copyMapToEntry(attrs).setName(dn);
while (retry <= connNumRetry) {
debug.message("SMSLdapObject.create() retry: {}", retry);
try (Connection conn = getConnection(p)) {
conn.add(LDAPRequests.newAddRequest(entry));
debug.message("SMSLdapObject.create Successfully created entry: {}", dn);
break;
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.ENTRY_ALREADY_EXISTS) && retry > 0) {
// During install time and other times,
// this error gets throws due to unknown issue. Issue:
// Hence mask it.
debug.warning("SMSLdapObject.create() Entry Already Exists Error for DN {}", dn);
break;
}
if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
debug.error("SMSLdapObject.create() Error in creating: {} By Principal: {}", dn, p.getName(), e);
throw new SMSException(e, "sms-entry-cannot-create");
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
//ignored
}
}
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method delete.
/**
* Delete the entry in the directory. This will delete sub-entries also!
*/
public void delete(SSOToken token, String dn) throws SMSException, SSOException {
SMSAuditor auditor = newAuditor(token, dn, readCurrentState(dn));
// Check if there are sub-entries, delete if present
Iterator se = subEntries(token, dn, "*", 0, false, false).iterator();
while (se.hasNext()) {
String entry = (String) se.next();
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject: deleting sub-entry: " + entry);
}
delete(token, getNamingAttribute() + "=" + entry + "," + dn);
}
// Check if there are suborganizations, delete if present
// The recursive 'false' here has the scope SCOPE_ONE
// while searching for the suborgs.
// Loop through the suborg at the first level and if there
// is no next suborg, delete that.
Set subOrgNames = searchSubOrgNames(token, dn, "*", 0, false, false, false);
for (Iterator so = subOrgNames.iterator(); so.hasNext(); ) {
String subOrg = (String) so.next();
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject: deleting " + "suborganization: " + subOrg);
}
delete(token, subOrg);
}
DeleteOperation dop = icConn.processDelete(dn);
ResultCode resultCode = dop.getResultCode();
if (resultCode != ResultCode.SUCCESS) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.delete: " + "Unable to delete entry:" + dn);
}
throw (new SMSException("", "sms-entry-cannot-delete"));
}
objectChanged(dn, DELETE);
if (auditor != null) {
auditor.auditDelete();
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method internalCreate.
/**
* Create an entry in the directory using the principal name
*/
private void internalCreate(SSOToken token, String dn, Map attrs) throws SMSException, SSOException {
SMSAuditor auditor = newAuditor(token, dn, null);
List attrList = copyMapToAttrList(attrs);
AddOperation ao = icConn.processAdd(dn, attrList);
ResultCode resultCode = ao.getResultCode();
if (resultCode == ResultCode.SUCCESS) {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.create: Successfully created" + " entry: " + dn);
}
if (auditor != null) {
auditor.auditCreate(attrs);
}
} else if (resultCode == ResultCode.ENTRY_ALREADY_EXISTS) {
// During install time and other times,
// this error gets throws due to unknown issue. Issue:
// Hence mask it.
debug.warning("SMSEmbeddedLdapObject.create: Entry " + "Already Exists Error for DN" + dn);
} else {
debug.error("SMSEmbeddedLdapObject.create: Error creating entry: " + dn + ", error code = " + resultCode);
throw new SMSException("", "sms-entry-cannot-create");
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SearchResultIterator method hasNext.
public boolean hasNext() {
try {
if (results.hasNext()) {
if (current == null) {
if (results.isReference()) {
debug.warning("SearchResultIterator: ignoring reference: {}", results.readReference());
return hasNext();
}
SearchResultEntry entry = results.readEntry();
String dn = entry.getName().toString();
if (hasExcludeDNs && excludeDNs.contains(dn)) {
return hasNext();
}
current = new SMSDataEntry(dn, SMSUtils.convertEntryToAttributesMap(entry));
}
return true;
}
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
debug.message("SearchResultIterator: size limit exceeded");
} else {
debug.error("SearchResultIterator.hasNext", e);
}
} catch (SearchResultReferenceIOException e) {
debug.error("SearchResultIterator.hasNext: reference should be already handled", e);
return hasNext();
}
conn.close();
return false;
}
Aggregations