use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class DeleteService 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();
boolean continueFlag = isOptionSet(IArgument.CONTINUE);
IOutput outputWriter = getOutputWriter();
List serviceNames = (List) rc.getOption(IArgument.SERVICE_NAME);
ServiceManager ssm = null;
boolean bError = false;
try {
ssm = new ServiceManager(adminSSOToken);
} catch (SMSException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
for (Iterator i = serviceNames.iterator(); i.hasNext(); ) {
String name = (String) i.next();
String[] param = { name };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_SERVICE", param);
deleteService(rc, ssm, name, adminSSOToken);
outputWriter.printlnMessage(getResourceString("service-deleted"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_DELETE_SERVICE", param);
} catch (CLIException e) {
bError = true;
if (continueFlag) {
outputWriter.printlnError(getResourceString("service-deletion-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw e;
}
}
}
if (bError) {
throw new CLIException(getResourceString("one-or-more-services-not-deleted"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class RemovePluginSchema 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String interfaceName = getStringOptionValue(ARGUMENT_INTERFACE_NAME);
String pluginName = getStringOptionValue(ARGUMENT_PLUGIN_NAME);
ServiceManager sm = null;
try {
sm = new ServiceManager(adminSSOToken);
} catch (SMSException smse) {
throw new CLIException(smse, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException ssoe) {
throw new CLIException(ssoe, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
IOutput outputWriter = getOutputWriter();
try {
String[] params = { serviceName, interfaceName, pluginName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_PLUGIN_SCHEMA", params);
sm.removePluginSchema(serviceName, interfaceName, pluginName);
String[] params2 = { serviceName, pluginName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_PLUGIN_SCHEMA", params2);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-plugin-schema-succeed"), (Object[]) params));
} catch (SSOException ssoe) {
String[] args = { serviceName, pluginName, ssoe.getMessage() };
debugError("RemovePluginSchema.handleRequest", ssoe);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_PLUGIN_SCHEMA", args);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-plugin-schema-failed"), (Object[]) args));
throw new CLIException(ssoe, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException smse) {
String[] args = { serviceName, pluginName, smse.getMessage() };
debugError("RemovePluginSchema.handleRequest", smse);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_PLUGIN_SCHEMA", args);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-plugin-schema-failed"), (Object[]) args));
throw new CLIException(smse, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class IdUtils method getOrganization.
/**
* Returns an organization which maps to the identifier used by application
*
* @param orgIdentifier Organization identifier
* @return Organization mapping to that identifier.
*/
public static String getOrganization(SSOToken token, String orgIdentifier) throws IdRepoException, SSOException {
// Check in cache first
String id = null;
if ((id = (String) orgIdentifierToOrgName.get(orgIdentifier)) != null) {
return (id);
}
// Compute the organization name
if (debug.messageEnabled()) {
debug.message("IdUtils:getOrganization Input orgname: " + orgIdentifier);
}
if (orgIdentifier == null || orgIdentifier.length() == 0 || orgIdentifier.equals("/")) {
// Return base DN
id = DNMapper.orgNameToDN("/");
} else if (orgIdentifier.startsWith("/")) {
// If orgIdentifier is in "/" format covert to DN and return
id = DNMapper.orgNameToDN(orgIdentifier);
try {
new OrganizationConfigManager(token, orgIdentifier);
} catch (SMSException e) {
debug.message("IdUtils.getOrganization Exception in getting org name from SMS", e);
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
}
} else if (LDAPUtils.isDN(orgIdentifier)) {
id = orgIdentifier;
try {
// Search for realms with orgIdentifier name
OrganizationConfigManager ocm = new OrganizationConfigManager(token, orgIdentifier);
} catch (SMSException smse) {
// debug message here.
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization Exception in " + "getting org name from SMS", smse);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
}
} else if (ServiceManager.isCoexistenceMode()) {
// Return the org DN as determined by AMStoreConnection
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization: getting from AMSDK");
}
try {
AMStoreConnection amsc = new AMStoreConnection(token);
id = amsc.getOrganizationDN(orgIdentifier, null);
} catch (AMException ame) {
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization Exception in " + "getting org name from AMSDK", ame);
}
throw convertAMException(ame);
}
} else {
// Get the realm name from SMS
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization: getting from " + "SMS realms");
}
try {
boolean foundOrg = false;
ServiceManager sm = new ServiceManager(token);
// First search for realms with orgIdentifier name
OrganizationConfigManager ocm = sm.getOrganizationConfigManager("/");
Set subOrgNames = ocm.getSubOrganizationNames(orgIdentifier, true);
if (subOrgNames != null && !subOrgNames.isEmpty()) {
if (subOrgNames.size() == 1) {
id = DNMapper.orgNameToDN((String) subOrgNames.iterator().next());
foundOrg = true;
} else {
for (Iterator items = subOrgNames.iterator(); items.hasNext(); ) {
// check for orgIdentifier
String subRealmName = (String) items.next();
StringTokenizer st = new StringTokenizer(subRealmName, "/");
// allowed
while (st.hasMoreTokens()) {
if (st.nextToken().equalsIgnoreCase(orgIdentifier)) {
if (!foundOrg) {
id = DNMapper.orgNameToDN(subRealmName);
foundOrg = true;
} else {
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.MULTIPLE_MAPPINGS_FOUND, args);
}
}
}
}
}
}
// Check if organization name has been determined
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization: getting from " + "SMS realms aliases");
}
// perform organization alias search
Set vals = new HashSet();
vals.add(orgIdentifier);
Set orgAliases = sm.searchOrganizationNames(IdConstants.REPO_SERVICE, IdConstants.ORGANIZATION_ALIAS_ATTR, vals);
if (!foundOrg && ((orgAliases == null) || orgAliases.isEmpty())) {
if (debug.warningEnabled()) {
debug.warning("IdUtils.getOrganization Unable" + " to find Org name for: " + orgIdentifier);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
} else if ((orgAliases != null) && (orgAliases.size() > 0) && (foundOrg || orgAliases.size() > 1)) {
// Multiple realms should not have the same alias
if (debug.warningEnabled()) {
debug.warning("IdUtils.getOrganization Multiple " + " matching Orgs found for: " + orgIdentifier);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.MULTIPLE_MAPPINGS_FOUND, args);
}
if (!foundOrg) {
String tmpS = (String) orgAliases.iterator().next();
id = DNMapper.orgNameToDN(tmpS);
}
} catch (SMSException smse) {
// debug message here.
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization Exception in " + "getting org name from SMS", smse);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
}
}
if (debug.messageEnabled()) {
debug.message("IdUtils:getOrganization Search for OrgIdentifier:" + orgIdentifier + " returning realm DN: " + id);
}
// Add to cache and return id
orgIdentifierToOrgName.put(orgIdentifier, id);
return id;
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class ServiceTypeManager method getServiceTypeNames.
/**
* Returns a set of service names that have policy privileges.
*
* @return set of service type names that have policy privileges
*
* @exception SSOException single-sign-on token has either expired
* or is invalid
* @exception NoPermissionException user does not have privileges
* to access service names
*/
public Set getServiceTypeNames() throws SSOException, NoPermissionException {
SSOTokenManager.getInstance().validateToken(token);
try {
ServiceManager sm = new ServiceManager(token);
Iterator items = sm.getServiceNames().iterator();
// Check if the service names have policy schema
HashSet answer = new HashSet();
while (items.hasNext()) {
String serviceName = (String) items.next();
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
if (ssm.getPolicySchema() != null)
answer.add(serviceName);
} catch (Exception e) {
PolicyManager.debug.error("ServiceTypeManager.getServiceTypeNames:", e);
}
}
return (answer);
} catch (SMSException se) {
throw (new NoPermissionException(se));
}
}
Aggregations