use of org.forgerock.opendj.ldap.LdapException 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.LdapException 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.LdapException in project OpenAM by OpenRock.
the class UpgradeUtils method getLDAPConnection.
/**
* Helper method to return Ldap connection
*
* @return Ldap connection
*/
private static Connection getLDAPConnection() {
String classMethod = "UpgradeUtils:getLDAPConnection : ";
if (debug.messageEnabled()) {
debug.message(classMethod + "Directory Server Host: " + dsHostName);
debug.message(classMethod + "Directory Server Port: " + dsPort);
debug.message(classMethod + "Direcotry Server DN: " + dsManager);
}
try {
// All connections will use authentication.
Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray())).set(CONNECT_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS));
return getLDAPConnectionFactory(dsHostName, dsPort, options).getConnection();
} catch (LdapException e) {
debug.error(classMethod + " Error getting LDAP Connection");
}
return null;
}
use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class SMSLdapObject method entryExists.
/**
* Checks if the provided DN exists.
*/
private static boolean entryExists(String dn) throws SMSException {
boolean entryExists = false;
try (Connection conn = getConnection(adminPrincipal)) {
// Use the Admin Principal to check if entry exists
conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn, OU_ATTR));
entryExists = true;
} catch (EntryNotFoundException e) {
debug.warning("SMSLdapObject:entryExists: {} does not exist", dn);
} catch (LdapException e) {
throw new SMSException("Unable to find entry with DN: " + dn, e, IUMSConstants.SMS_LDAP_OPERATION_FAILED);
}
return entryExists;
}
use of org.forgerock.opendj.ldap.LdapException 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
}
}
}
}
Aggregations