use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class GetAuthInstance 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);
String instanceName = getStringOptionValue(AuthOptions.AUTH_INSTANCE_NAME);
String[] params = { realm, instanceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_AUTH_INSTANCE", params);
try {
AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
AMAuthenticationInstance ai = mgr.getAuthenticationInstance(instanceName);
if (ai != null) {
IOutput outputWriter = getOutputWriter();
Map attributeValues = ai.getAttributeValues();
if ((attributeValues != null) && !attributeValues.isEmpty()) {
AMAuthenticationSchema schema = mgr.getAuthenticationSchema(ai.getType());
String serviceName = schema.getServiceName();
outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-succeeded"));
outputWriter.printlnMessage(FormatUtils.printAttributeValues(getResourceString("authentication-get-auth-instance-result"), attributeValues, CLIUtil.getPasswordFields(serviceName)));
} else {
outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-no-values"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_GET_AUTH_INSTANCE", params);
} else {
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(getResourceString("authentication-get-auth-instance-not-found"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} catch (SSOException e) {
debugError("GetAuthInstance.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
debugError("GetAuthInstance.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (AMConfigurationException e) {
debugError("GetAuthInstance.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class RegisterAuthModule 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();
String authModule = getStringOptionValue(AUTH_MODULE);
ServiceSchema ss = getServiceSchema(ISAuthConstants.AUTH_SERVICE_NAME, null, "Global");
IOutput outputWriter = getOutputWriter();
try {
String[] params = { ISAuthConstants.AUTH_SERVICE_NAME };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REGISTER_AUTH_MODULE", params);
Map attrValues = ss.getAttributeDefaults();
Set values = (Set) attrValues.get(AUTH_AUTHENTICATOR_ATTR);
if ((values == null) || values.isEmpty()) {
values = new HashSet(2);
}
values.add(authModule);
ss.setAttributeDefaults(AUTH_AUTHENTICATOR_ATTR, values);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REGISTER_AUTH_MODULE", params);
outputWriter.printlnMessage(getResourceString("register-auth-module-succeeded"));
} catch (SSOException e) {
String[] args = { ISAuthConstants.AUTH_SERVICE_NAME, e.getMessage() };
debugError("RegisterAuthModule.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REGISTER_AUTH_MODULE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { ISAuthConstants.AUTH_SERVICE_NAME, e.getMessage() };
debugError("RegisterAuthModule.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REGISTER_AUTH_MODULE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput 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.IOutput in project OpenAM by OpenRock.
the class RealmSetServiceAttributeValues method handleDynamicAttributes.
private void handleDynamicAttributes(AMIdentity idRealm, String realm, String serviceName, Map attributeValues, boolean bAppend) throws CLIException, IdRepoException, SSOException {
String[] params = { realm, serviceName };
IOutput outputWriter = getOutputWriter();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_SVC_ATTR_VALUES_REALM", params);
if (bAppend) {
Map newValues = new HashMap();
Map currentVal = idRealm.getAttributes(attributeValues.keySet());
for (Iterator i = attributeValues.keySet().iterator(); i.hasNext(); ) {
String attrName = (String) i.next();
Set origVal = (Set) currentVal.get(attrName);
Set newVal = (Set) attributeValues.get(attrName);
if ((origVal == null) || origVal.isEmpty()) {
newValues.put(attrName, newVal);
} else {
origVal.addAll(newVal);
newValues.put(attrName, origVal);
}
}
idRealm.modifyService(serviceName, newValues);
} else {
idRealm.modifyService(serviceName, attributeValues);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SVC_ATTR_VALUES_REALM", params);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-svc-attribute-values-realm-succeed"), (Object[]) params));
}
use of com.sun.identity.cli.IOutput 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);
}
}
Aggregations