use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class RealmModifyService 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);
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 {
String[] params = { realm, serviceName };
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set assignedServices = ocm.getAssignedServices(true);
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = repo.getRealmIdentity();
Set servicesFromIdRepo = ai.getAssignedServices();
boolean modified = false;
if (assignedServices.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SERVICE_REALM", params);
ocm.modifyService(serviceName, attributeValues);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
modified = true;
}
if (servicesFromIdRepo.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SERVICE_REALM", params);
ai.modifyService(serviceName, attributeValues);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
modified = true;
}
if (modified) {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-succeed"), (Object[]) params));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-not-assigned"), (Object[]) params));
}
} catch (IdRepoException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmModifyService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmModifyService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmModifyService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class RealmRemoveServiceAttributes 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);
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 {
String[] params = { realm, serviceName };
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set assignedServices = ocm.getAssignedServices(true);
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = repo.getRealmIdentity();
Set servicesFromIdRepo = ai.getAssignedServices();
boolean modified = false;
if (assignedServices.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
Map origValues = ocm.getServiceAttributes(serviceName);
if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
ocm.modifyService(serviceName, origValues);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
modified = true;
}
if (servicesFromIdRepo.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
Map origValues = ai.getServiceAttributes(serviceName);
if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
ai.modifyService(serviceName, origValues);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
modified = true;
}
if (modified) {
outputWriter.printlnMessage(getResourceString("realm-remove-service-attributes-succeed"));
outputWriter.printlnMessage("");
outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-remove-service-attributes-not-assigned"), (Object[]) params));
}
} catch (IdRepoException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmRemoveServiceAttributes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmRemoveServiceAttributes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmRemoveServiceAttributes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class RealmAddServiceAttributes method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
@Override
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);
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 {
String[] params = { realm, serviceName };
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Map<String, Boolean> mapAttrType = getMultipleValueAttrs(serviceName);
Set assignedServices = ocm.getAssignedServices(true);
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = repo.getRealmIdentity();
Set servicesFromIdRepo = ai.getAssignedServices();
boolean modified = false;
if (assignedServices.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
Map origValues = ocm.getServiceAttributes(serviceName);
if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
ocm.modifyService(serviceName, origValues);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
modified = true;
}
if (servicesFromIdRepo.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
Map origValues = ai.getServiceAttributes(serviceName);
if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
ai.modifyService(serviceName, origValues);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
modified = true;
}
if (modified) {
outputWriter.printlnMessage(getResourceString("realm-add-service-attributes-succeed"));
outputWriter.printlnMessage("");
outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-add-service-attributes-not-assigned"), (Object[]) params));
}
} catch (IdRepoException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmAddServiceAttributes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmAddServiceAttributes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmAddServiceAttributes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class RealmAssignService 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
Map<String, Set<String>> attributeValues = null;
if ((datafile != null) || (attrValues != null)) {
attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
attributeValues = processFileAttributes(attributeValues);
}
IOutput outputWriter = getOutputWriter();
String[] params = { realm, serviceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ASSIGN_SERVICE_TO_REALM", params);
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set assignableServices = ocm.getAssignableServices();
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = amir.getRealmIdentity();
Set dynAssignableServices = ai.getAssignableServices();
if (assignableServices.contains(serviceName)) {
ocm.assignService(serviceName, attributeValues);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
}
if (dynAssignableServices.contains(serviceName)) {
ai.assignService(serviceName, attributeValues);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ASSIGN_SERVICE_TO_REALM", params);
} catch (SSOException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmAssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IdRepoException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmAssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmAssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class RealmGetAssignedServices method getAssignedDynamicServiceNames.
private Set getAssignedDynamicServiceNames(SSOToken adminSSOToken, String realm) throws SMSException, IdRepoException, SSOException {
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = repo.getRealmIdentity();
return ai.getAssignedServices();
}
Aggregations