use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class DirectoryServicesImpl method getMembers.
/**
* Get members for roles, dynamic group or static group
*
* @param token
* SSOToken
* @param entryDN
* DN of the role or group
* @param objectType
* objectType of the target object, AMObject.ROLE or
* AMObject.GROUP
* @return Set Member DNs
*/
public Set getMembers(SSOToken token, String entryDN, int objectType) throws AMException {
try {
SearchResults results;
switch(objectType) {
case AMObject.ROLE:
case AMObject.MANAGED_ROLE:
ManagedRole role = (ManagedRole) UMSObject.getObject(token, new Guid(entryDN));
results = role.getMemberIDs();
return searchResultsToSet(results);
case AMObject.FILTERED_ROLE:
FilteredRole filteredRole = (FilteredRole) UMSObject.getObject(token, new Guid(entryDN));
results = filteredRole.getMemberIDs();
return searchResultsToSet(results);
case AMObject.GROUP:
case AMObject.STATIC_GROUP:
StaticGroup group = (StaticGroup) UMSObject.getObject(token, new Guid(entryDN));
results = group.getMemberIDs();
return searchResultsToSet(results);
case AMObject.DYNAMIC_GROUP:
DynamicGroup dynamicGroup = (DynamicGroup) UMSObject.getObject(token, new Guid(entryDN));
results = dynamicGroup.getMemberIDs();
return searchResultsToSet(results);
case AMObject.ASSIGNABLE_DYNAMIC_GROUP:
// TODO: See if it works after removing this workaround
// fake object to get around UMS problem.
// UMS AssignableDynamicGroup has a class resolver, it is
// added to resolver list in static block. So I need to
// construct a dummy AssignableDynamicGroup
AssignableDynamicGroup adgroup = (AssignableDynamicGroup) UMSObject.getObject(token, new Guid(entryDN));
results = adgroup.getMemberIDs();
return searchResultsToSet(results);
default:
throw new AMException(token, "114");
}
} catch (EntryNotFoundException e) {
debug.error("DirectoryServicesImpl.getMembers() entryDN " + entryDN + " objectType: " + objectType + " Unable to get members: ", e);
String msgid = getEntryNotFoundMsgID(objectType);
String entryName = getEntryName(e);
Object[] args = { entryName };
throw new AMException(AMSDKBundle.getString(msgid, args), msgid, args);
} catch (UMSException e) {
debug.error("DirectoryServicesImpl.getMembers() entryDN " + entryDN + " objectType: " + objectType + " Unable to get members: ", e);
LdapException le = (LdapException) e.getRootCause();
if (le != null) {
ResultCode resultCode = le.getResult().getResultCode();
if (ResultCode.SIZE_LIMIT_EXCEEDED.equals(resultCode) || ResultCode.ADMIN_LIMIT_EXCEEDED.equals(resultCode)) {
throw new AMException(token, "505", e);
}
}
throw new AMException(token, "454", e);
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class DataLayer method rename.
public void rename(java.security.Principal principal, Guid guid, String newName, boolean deleteOldName) throws UMSException {
String id = guid.getDn();
ResultCode errorCode;
try {
ModifyDNRequest request = LDAPRequests.newModifyDNRequest(id, newName);
int retry = 0;
while (retry <= connNumRetry) {
if (debug.messageEnabled()) {
debug.message("DataLayer.rename retry: " + retry);
}
try (Connection conn = getConnection(principal)) {
conn.applyChange(request);
return;
} catch (LdapException e) {
errorCode = e.getResult().getResultCode();
if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
throw e;
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
}
}
}
} catch (LdapException e) {
if (debug.warningEnabled()) {
debug.warning("Exception in DataLayer.rename 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 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();
}
}
Aggregations