use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.
the class SelectRealmModelImpl method getRealmNames.
/**
* Returns realms that have names matching with a filter.
*
* @param base Base realm name for this search. null indicates root
* suffix.
* @param filter Filter string.
* @return realms that have names matching with a filter.
* @throws AMConsoleException if search fails.
*/
public Set getRealmNames(String base, String filter) throws AMConsoleException {
if ((base == null) || (base.length() == 0)) {
base = getStartDN();
}
String[] param = { base };
logEvent("ATTEMPT_GET_REALM_NAMES", param);
try {
OrganizationConfigManager orgMgr = new OrganizationConfigManager(getUserSSOToken(), base);
logEvent("SUCCEED_GET_REALM_NAMES", param);
return PolicyModelImpl.appendBaseDN(base, orgMgr.getSubOrganizationNames(filter, true), filter, this);
} catch (SMSException e) {
String strError = getErrorString(e);
String[] paramsEx = { base, strError };
logEvent("SMS_EXCEPTION_GET_REALM_NAMES", paramsEx);
throw new AMConsoleException(strError);
}
}
use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.
the class SmsRealmProvider method handleDelete.
@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context serverContext, DeleteRequest request) {
RealmContext realmContext = serverContext.asContext(RealmContext.class);
String realmPath = realmContext.getResolvedRealm();
try {
OrganizationConfigManager realmManager = new OrganizationConfigManager(getSSOToken(), realmPath);
final ResourceResponse resource = getResource(getJsonValue(realmPath));
realmManager.deleteSubOrganization(null, false);
String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
debug.message("RealmResource.deleteInstance :: DELETE of realm " + realmPath + " performed by " + principalName);
return newResultPromise(resource);
} catch (SMSException smse) {
ResourceException exception = configureErrorMessage(smse);
if (exception instanceof NotFoundException) {
debug.warning("RealmResource.deleteInstance() : Cannot find {}", realmPath, smse);
return exception.asPromise();
} else if (exception instanceof ForbiddenException || exception instanceof PermanentException || exception instanceof ConflictException || exception instanceof BadRequestException) {
debug.warning("RealmResource.deleteInstance() : Cannot DELETE {}", realmPath, smse);
return exception.asPromise();
} else {
return new BadRequestException(exception.getMessage(), exception).asPromise();
}
} catch (Exception e) {
return new BadRequestException(e.getMessage(), e).asPromise();
}
}
use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.
the class SearchIdentities method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
String filter = getStringOptionValue(IArgument.FILTER);
String[] params = { realm, type, filter };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SEARCH_IDENTITIES", params);
// test if realm exists
try {
new OrganizationConfigManager(adminSSOToken, realm);
} catch (SMSException e) {
String[] args = { realm, type, filter, e.getMessage() };
debugError("SearchIdentities.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_IDENTITIES", args);
Object[] msgArg = { realm };
throw new CLIException(MessageFormat.format(getResourceString("realm-does-not-exist"), msgArg), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
IdType idType = convert2IdType(type);
IdSearchResults isr = amir.searchIdentities(idType, filter, new IdSearchControl());
Set results = isr.getSearchResults();
if ((results != null) && !results.isEmpty()) {
if (idType.equals(IdType.USER)) {
IdSearchResults specialUsersResults = amir.getSpecialIdentities(IdType.USER);
results.removeAll(specialUsersResults.getSearchResults());
}
for (Iterator i = results.iterator(); i.hasNext(); ) {
AMIdentity amid = (AMIdentity) i.next();
String[] args = { amid.getName(), amid.getUniversalId() };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("format-search-identities-results"), (Object[]) args));
}
} else {
outputWriter.printlnMessage(getResourceString("search-identities-no-entries"));
}
outputWriter.printlnMessage(MessageFormat.format(getResourceString("search-identities-succeed"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SEARCH_IDENTITIES", params);
} catch (IdRepoException e) {
String[] args = { realm, type, filter, e.getMessage() };
debugError("SearchIdentities.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_IDENTITIES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, filter, e.getMessage() };
debugError("SearchIdentities.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_IDENTITIES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.
the class DeleteRealm method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
boolean recursive = isOptionSet(IArgument.RECURSIVE);
String strRecursive = (recursive) ? "recursive" : "non recursive";
String[] params = { realm, strRecursive };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_REALM", params);
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
ocm.deleteSubOrganization(null, recursive);
getOutputWriter().printlnMessage(getResourceString("delete-realm-succeed"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_REALM", params);
} catch (SMSException e) {
String[] args = { realm, strRecursive, e.getMessage() };
debugError("DeleteRealm.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.
the class AllowedModulesChoiceValues method getChoiceValues.
/**
* Returns choice values from environment parameters
* @param envParams map of environment parameters
* @return choice values from environment parameters
*/
public Map getChoiceValues(Map envParams) {
// Get default choice values
getChoiceValues();
Set serviceNames = null;
String orgDN = null;
Map registeredServices = new HashMap();
if (envParams != null) {
orgDN = (String) envParams.get(Constants.ORGANIZATION_NAME);
}
if (orgDN == null || orgDN.length() == 0) {
orgDN = SMSEntry.getRootSuffix();
}
SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
try {
OrganizationConfigManager orgConfig = getOrgConfigManager(orgDN, adminToken);
serviceNames = orgConfig.getAssignedServices();
} catch (Exception e) {
// this Exception should have been (or will be) caught by the
// caller of of this plugin(console). it does not worth to
// duplicate log/debug here.
}
if (serviceNames != null) {
for (Iterator ite = choiceValues.keySet().iterator(); ite.hasNext(); ) {
String value = (String) ite.next();
if (serviceRegistered(value, serviceNames)) {
registeredServices.put(value, value);
} else {
String serviceName = AuthUtils.getModuleServiceName(value);
try {
new ServiceConfigManager(serviceName, adminToken);
} catch (SMSException e) {
// services don't have template.
registeredServices.put(value, value);
} catch (Exception e) {
// SSO, do nothing
}
}
}
}
return registeredServices;
}
Aggregations