use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class AuthUtils method getGlobalAttributes.
/**
* Returns <code>Map</code> attributes
*
* @param serviceName Service Name
* @return <code>Map</code> of global attributes.
*/
public static Map getGlobalAttributes(String serviceName) {
Map attrs = null;
try {
SSOToken dUserToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
ServiceSchemaManager scm = new ServiceSchemaManager(serviceName, dUserToken);
ServiceSchema schema = scm.getGlobalSchema();
if (schema != null) {
attrs = schema.getAttributeDefaults();
}
} catch (SMSException smsExp) {
utilDebug.error("AuthUtils.getGlobalAttributes: SMS Error", smsExp);
} catch (SSOException ssoExp) {
utilDebug.error("AuthUtils.getGlobalAttributes: SSO Error", ssoExp);
}
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils.getGlobalAttributes: attrs=" + attrs);
}
return attrs;
}
use of com.sun.identity.sm.SMSException 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;
}
use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class ListXACML method getPolicies.
/**
* Uses the Realm and Search Filters to identify all Privileges in the Entitlement
* framework to export.
*
* @throws CLIException If there was an unexpected error.
*/
private void getPolicies() throws CLIException {
FileOutputStream fout = null;
PrintWriter pwout = null;
if (outfile != null) {
try {
fout = new FileOutputStream(outfile, true);
pwout = new PrintWriter(fout, true);
} catch (FileNotFoundException e) {
debugError("ListXACML.handleXACMLPolicyRequest", e);
try {
if (fout != null) {
fout.close();
}
} catch (IOException ex) {
//do nothing
}
throw new CLIException(e, ExitCodes.IO_EXCEPTION);
} catch (SecurityException e) {
debugError("ListXACML.handleXACMLPolicyRequest", e);
try {
if (fout != null) {
fout.close();
}
} catch (IOException ex) {
//do nothing
}
throw new CLIException(e, ExitCodes.IO_EXCEPTION);
}
}
PolicySet policySet = null;
try {
PrivilegeValidator privilegeValidator = new PrivilegeValidator(new RealmValidator(new OrganizationConfigManager(adminSSOToken, "/")));
XACMLExportImport importExport = new XACMLExportImport(new XACMLExportImport.PrivilegeManagerFactory(), new XACMLReaderWriter(), privilegeValidator, new SearchFilterFactory(), PrivilegeManager.debug);
policySet = importExport.exportXACML(realm, adminSubject, filters);
} catch (EntitlementException e) {
String[] args = { realm, e.getMessage() };
debugError("ListXACML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_POLICY_IN_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, e.getMessage() };
debugError("ListXACML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_POLICY_IN_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
if (policySet == null || policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) {
String[] arg = { realm };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-policy-in-realm-no-policies"), (Object[]) arg));
} else {
try {
if (pwout != null) {
pwout.write(XACMLPrivilegeUtils.toXML(policySet));
} else {
outputWriter.printlnMessage(XACMLPrivilegeUtils.toXML(policySet));
}
} catch (EntitlementException e) {
throw new CLIException(e, ExitCodes.IO_EXCEPTION);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_POLICY_IN_REALM", new String[] { realm });
String[] arg = { realm };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-policy-in-realm-succeed"), (Object[]) arg));
if (pwout != null) {
try {
pwout.close();
fout.close();
} catch (IOException e) {
//do nothing
}
}
}
}
use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class DeleteDataStores method handleRequest.
/**
* Handles request.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
List names = (List) rc.getOption(DatastoreOptions.DATASTORE_NAMES);
validateRealm(realm);
String[] params = { realm, names.toString() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_DATASTORES", params);
try {
ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
if (cfg != null) {
for (Iterator i = names.iterator(); i.hasNext(); ) {
cfg.removeSubConfig((String) i.next());
}
if (names.size() > 1) {
getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastores-succeeded"));
} else {
getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-succeeded"));
}
} else {
getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-not-found"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_DATASTORES", params);
} catch (SMSException e) {
debugError("DeleteDataStores.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
debugError("DeleteDataStores.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class ListDataStores method handleRequest.
/**
* Handles request.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
validateRealm(realm);
String[] params = { realm };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_DATASTORES", params);
try {
ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
Set names = (cfg != null) ? cfg.getSubConfigNames() : Collections.EMPTY_SET;
if ((names != null) && !names.isEmpty()) {
getOutputWriter().printlnMessage(getResourceString("datastore-list-datastores-succeeded"));
for (Iterator i = names.iterator(); i.hasNext(); ) {
String name = (String) i.next();
getOutputWriter().printlnMessage(name);
}
} else {
getOutputWriter().printlnMessage(getResourceString("datastore-list-datastores-no-entries"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_LIST_DATASTORES", params);
} catch (SMSException e) {
debugError("ListDataStores.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_DATASTORES", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
debugError("ListDataStores.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_DATASTORES", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations