use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.
the class EntityObjectImpl method createEntity.
/**
* Creates entities.
*
* @param ssotoken
* String representing user's SSO Token.
* @param entityName
* Name of this entity.eg.cn=websphereAgent
* @param entityType
* Type of entity being created. eg. Agent The types supported by
* SDK are configured in the list of Managed Objects in the
* <code>DAI</code> service.
* @param entityLocation
* Location of the entity creation.eg.www.abc.com
* @param attributes
* Map to represent Attribute-Value Pairs
* @return Returns a set of Entity DNs created.
* @throws EntityException
* if there is an internal error in the AM Store
* @throws SSOException
* if the sign on is no longer valid
*/
public Set createEntity(String ssotoken, String entityName, String entityType, String entityLocation, Map attributes) throws EntityException, SSOException {
Set entitySet = new HashSet();
initializeObject(ssotoken, entityLocation);
try {
int type = 0;
type = getIntTypeFromStr(entityType);
Map input = new HashMap(2);
input.put(entityName, attributes);
if (entity != null) {
Set entityObjs = entity.createEntities(type, input);
Iterator it = entityObjs.iterator();
while (it.hasNext()) {
entitySet.add(((AMEntity) it.next()).getDN());
}
}
} catch (AMException amex) {
EntityUtils.debug.error("EntityObjectImpl.createEntity() : " + "Create Entity Failed. " + amex);
throw EntityUtils.convertException(amex);
}
return entitySet;
}
use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.
the class EntityObjectImpl method initializeObject.
/**
* Method to initialize the object. The AMStoreConnection handle is obtained
* by creating a valid SSOToken.
*/
protected void initializeObject(String ssoToken, String entityLocation) throws EntityException, SSOException {
checkInitialization();
try {
token = tokenManager.createSSOToken(ssoToken);
amsc = new AMStoreConnection(token);
String orgDN = amsc.getOrganizationDN(entityLocation, null);
entity = amsc.getOrganization(orgDN);
} catch (AMException amex) {
EntityUtils.debug.error("EntityObjectImpl.initializeObject() : " + "Unable to get Organization DN " + amex);
throw EntityUtils.convertException(amex);
} catch (SSOException ssoe) {
EntityUtils.debug.error("EntityObjectImpl.initializeObject() : " + "Unable to convert SSOToken: " + ssoToken, ssoe);
throw ssoe;
}
if (EntityUtils.debug.messageEnabled()) {
EntityUtils.debug.message("EntityObjectImpl.getAMEntity(): " + "Obtained ssotoken: " + ssoToken);
EntityUtils.debug.message("EntityObjectImpl.getAMEntity(): " + "Obtained AMSToreConnection object for SSOToken: " + ssoToken);
}
}
use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.
the class UpgradeUtils method deleteService.
public static void deleteService(String serviceName, SSOToken adminToken) throws UpgradeException {
String classMethod = "UpgradeUtils:deleteService : ";
try {
ServiceManager sm = new ServiceManager(adminToken);
ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminToken);
if (scm.getGlobalConfig(null) != null) {
scm.removeGlobalConfiguration(null);
}
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, adminToken);
Set<String> versions = sm.getServiceVersions(serviceName);
if (ssm.getPolicySchema() == null) {
if (debug.messageEnabled()) {
debug.message("Service has policy schema; matching policy schema will be removed");
}
deletePolicyRule(serviceName, adminToken);
}
for (String version : versions) {
sm.removeService(serviceName, version);
}
} catch (SSOException ssoe) {
debug.error(classMethod + ssoe.getMessage());
throw new UpgradeException(ssoe);
} catch (SMSException smse) {
debug.error(classMethod + smse.getMessage());
throw new UpgradeException(smse);
} catch (AMException ame) {
debug.error(classMethod + ame.getMessage());
throw new UpgradeException(ame);
}
}
use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.
the class DirectoryServicesImpl method removeSubtree.
/**
* Private method used by "removeEntry" to delete an entire subtree
*/
private void removeSubtree(SSOToken token, String entryDN, boolean softDelete) throws AMException, SSOException {
int type = AMObject.UNKNOWN_OBJECT_TYPE;
try {
Guid guid = new Guid(entryDN);
PersistentObject po = UMSObject.getObjectHandle(internalToken, guid);
// first get all the children of the object
SearchControl control = new SearchControl();
control.setSearchScope(SearchControl.SCOPE_SUB);
String searchFilter = "(|(objectclass=*)(objectclass=ldapsubEntry))";
List list = new ArrayList();
// get number of RDNs in the entry itself
int entryRDNs = DN.valueOf(entryDN).size();
// to count maximum level of RDNs in the search return
int maxRDNCount = entryRDNs;
// go through all search results, add DN to the list, and
// set the maximun RDN count, will be used to remove DNs
SearchResults children = po.getChildren(searchFilter, control);
while (children.hasMoreElements()) {
PersistentObject object = children.next();
DN dn = DN.valueOf(object.getDN());
if (debug.messageEnabled()) {
debug.message("DirectoryServicesImpl.removeEntry(): " + "found child: " + object.getDN());
}
int count = dn.size();
if (count > maxRDNCount) {
maxRDNCount = count;
}
list.add(dn);
}
if (debug.messageEnabled()) {
debug.message("DirectoryServicesImpl.removeEntry(): max " + "RDNs: " + maxRDNCount);
}
// go through all search results, delete entries from the
// bottom up, starting from entries whose's RDN count
// equals the maxRDNCount
// TODO : If the list has too many entries, then the multiple
// iteration in the inner for loop may be the bottleneck.
// One enhancement to the existing algorithm is to store all
// the entries by level in a different List. Per Sai's comments
int len = list.size();
for (int i = maxRDNCount; i >= entryRDNs; i--) {
for (int j = 0; j < len; j++) {
DN dn = (DN) list.get(j);
// check if we need delete it now
if (dn.size() == i) {
// remove the entry
if (debug.messageEnabled()) {
debug.message("DirectoryServicesImpl." + "removeEntry(): del " + dn.toString());
}
String rfcDN = dn.toString();
type = AMObject.UNKNOWN_OBJECT_TYPE;
try {
type = getObjectType(internalToken, rfcDN);
} catch (AMException ae) {
// Not a managed type, just delete it.
Guid g = new Guid(rfcDN);
UMSObject.removeObject(token, g);
}
// Do a non-recursive delete
if (type != AMObject.UNKNOWN_OBJECT_TYPE && type != AMObject.UNDETERMINED_OBJECT_TYPE) {
try {
removeSingleEntry(token, rfcDN, type, softDelete);
} catch (AMPreCallBackException amp) {
debug.error("DirectoryServicesImpl." + "removeSubTree: Aborting delete of: " + rfcDN + " due to pre-callback exception", amp);
}
}
// remove the deleted entry from the list
list.remove(j);
// move back pointer, as current element is removed
j--;
// reduce list length
len--;
}
}
}
} catch (AccessRightsException e) {
debug.error("DirectoryServicesImpl.removeEntry() Insufficient " + "access rights to remove entry: " + entryDN, e);
throw new AMException(token, "460");
} catch (EntryNotFoundException e) {
String entry = getEntryName(e);
debug.error("DirectoryServicesImpl.removeEntry() Entry not found: " + entry, e);
String msgid = getEntryNotFoundMsgID(type);
Object[] args = { entry };
String locale = CommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString(msgid, args, locale), msgid, args);
} catch (UMSException e) {
debug.error("DirectoryServicesImpl.removeEntry() Unable to remove: " + " Internal error occurred: ", e);
throw new AMException(token, "325", e);
}
}
use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.
the class DirectoryServicesImpl method verifyAndGetOrgDN.
/**
* Gets the Organization DN for the specified entryDN. If the entry itself
* is an org, then same DN is returned.
*
* @param token
* a valid SSOToken
* @param entryDN
* the entry whose parent Organization is to be obtained
* @param childDN
* the immediate entry whose parent Organization is to be
* obtained
* @return the DN String of the parent Organization
* @throws AMException
* if an error occured while obtaining the parent Organization
*/
public String verifyAndGetOrgDN(SSOToken token, String entryDN, String childDN) throws AMException {
if (entryDN.isEmpty() || DN.valueOf(entryDN).size() <= 0) {
debug.error("DirectoryServicesImpl.verifyAndGetOrgDN() Invalid " + "DN: " + entryDN);
throw new AMException(token, "157");
}
String organizationDN = null;
boolean errorCondition = false;
try {
PersistentObject po = UMSObject.getObjectHandle(internalToken, new Guid(childDN));
String searchFilter = getOrgSearchFilter(entryDN);
SearchResults result = po.search(searchFilter, aName, scontrol);
if (result.hasMoreElements()) {
// ABANDON logged in directory server access logs.
while (result.hasMoreElements()) {
result.next();
}
organizationDN = po.getGuid().toString().toLowerCase();
}
} catch (InvalidSearchFilterException e) {
errorCondition = true;
debug.error("DirectoryServicesImpl.verifyAndGetOrgDN(): Invalid " + "search filter, unable to get Parent Organization: ", e);
} catch (UMSException ue) {
errorCondition = true;
if (debug.warningEnabled()) {
debug.warning("DirectoryServicesImpl.verifyAndGetOrgDN(): " + "Unable to Obtain Parent Organization", ue);
}
LdapException lex = (LdapException) ue.getRootCause();
ResultCode errorCode = lex.getResult().getResultCode();
if (retryErrorCodes.contains("" + errorCode)) {
throw new AMException(token, Integer.toString(errorCode.intValue()), ue);
}
}
if (errorCondition) {
String locale = CommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("124", locale), "124");
}
return organizationDN;
}
Aggregations