use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class DeleteAuthInstances 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(AuthOptions.AUTH_INSTANCE_NAMES);
String[] params = { realm, names.toString() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_AUTH_INSTANCES", params);
try {
AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
for (Iterator i = names.iterator(); i.hasNext(); ) {
String name = (String) i.next();
mgr.deleteAuthenticationInstance(name);
}
if (names.size() == 1) {
getOutputWriter().printlnMessage(getResourceString("authentication-delete-auth-instance-succeeded"));
} else {
getOutputWriter().printlnMessage(getResourceString("authentication-delete-auth-instances-succeeded"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_AUTH_INSTANCES", params);
} catch (AMConfigurationException e) {
debugError("DeleteAuthInstances,handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AUTH_INSTANCES", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class UpdateAuthConfigurationEntries method validateEntries.
private void validateEntries(String realm, SSOToken adminSSOToken, List entries, String[] params) throws CLIException {
if ((entries != null) && !entries.isEmpty()) {
Set instanceNames = getInstanceNames(realm, adminSSOToken, params);
for (Iterator i = entries.iterator(); i.hasNext(); ) {
AuthConfigurationEntry token = (AuthConfigurationEntry) i.next();
String instanceName = token.getLoginModuleName();
if (!instanceNames.contains(instanceName)) {
Object[] p = { instanceName };
throw new CLIException(MessageFormat.format(getResourceString("authentication-set-auth-config-entries-instance-not-found"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class RealmSetAttributeValues 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();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
boolean bAppend = isOptionSet(OPT_APPEND);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
if (bAppend) {
for (Iterator i = attributeValues.keySet().iterator(); i.hasNext(); ) {
String attributeName = (String) i.next();
String[] params = { realm, serviceName, attributeName };
Set values = (Set) attributeValues.get(attributeName);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTR_VALUES_REALM", params);
ocm.addAttributeValues(serviceName, attributeName, values);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTR_VALUES_REALM", params);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-attribute-values-realm-succeed"), (Object[]) params));
}
} else {
String[] params = { realm, serviceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_ATTR_VALUES_REALM", params);
ocm.setAttributes(serviceName, attributeValues);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_ATTR_VALUES_REALM", params);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-attribute-values-realm-succeed"), (Object[]) params));
}
} catch (SMSException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmSetAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_ATTR_VALUES_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class RealmSetServiceAttributeValues 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();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
boolean bAppend = isOptionSet(OPT_APPEND);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
attributeValues = processFileAttributes(attributeValues);
try {
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = repo.getRealmIdentity();
Set servicesFromIdRepo = ai.getAssignedServices();
if (servicesFromIdRepo.contains(serviceName)) {
handleDynamicAttributes(ai, realm, serviceName, attributeValues, bAppend);
} else {
handleOrganizatioAttribute(realm, serviceName, attributeValues, bAppend);
}
} catch (IdRepoException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmSetServiceAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmSetServiceAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class SearchRealms 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);
String pattern = getStringOptionValue(IArgument.FILTER);
boolean recursive = isOptionSet(IArgument.RECURSIVE);
String strRecursive = (recursive) ? "recursive" : "non recursive";
if ((pattern == null) || (pattern.trim().length() == 0)) {
pattern = "*";
}
String[] params = { realm, pattern, strRecursive };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SEARCH_REALM", params);
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set results = ocm.getSubOrganizationNames(pattern, recursive);
IOutput outputWriter = getOutputWriter();
if ((results != null) && !results.isEmpty()) {
String template = getResourceString("search-realm-results");
String[] arg = new String[1];
for (Iterator i = results.iterator(); i.hasNext(); ) {
arg[0] = (String) i.next();
outputWriter.printlnMessage(MessageFormat.format(template, (Object[]) arg));
}
outputWriter.printlnMessage(getResourceString("search-realm-succeed"));
} else {
outputWriter.printlnMessage(getResourceString("search-realm-no-results"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SEARCH_REALM", params);
} catch (SMSException e) {
String[] args = { realm, strRecursive, e.getMessage() };
debugError("SearchRealms.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations