use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class AssignService 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);
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String idName = getStringOptionValue(ARGUMENT_ID_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
IdType idType = convert2IdType(type);
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);
String[] params = { realm, type, idName, serviceName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_ASSIGN_SERVICE", params);
AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
amid.assignService(serviceName, attributeValues);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-assign-service-succeed"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_ASSIGN_SERVICE", params);
} catch (IdRepoException e) {
String[] args = { realm, type, idName, serviceName, e.getMessage() };
debugError("AssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ASSIGN_SERVICE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, idName, serviceName, e.getMessage() };
debugError("AssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ASSIGN_SERVICE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class CreateIdentity 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);
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String idName = getStringOptionValue(ARGUMENT_ID_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
Map attributeValues = Collections.EMPTY_MAP;
if ((datafile != null) || (attrValues != null)) {
attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
}
String[] params = { realm, type, idName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_IDENTITY", params);
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
IdType idType = convert2IdType(type);
Set set = amir.getAllowedIdOperations(idType);
if (!set.contains(IdOperation.CREATE)) {
String[] args = { realm, type };
throw new CLIException(MessageFormat.format(getResourceString("does-not-support-creation"), (Object[]) args), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
amir.createIdentity(idType, idName, attributeValues);
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-identity-succeed"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_CREATE_IDENTITY", params);
} catch (IdRepoException e) {
String[] args = { realm, type, idName, e.getMessage() };
debugError("CreateIdentity.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_IDENTITY", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, idName, e.getMessage() };
debugError("CreateIdentity.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_IDENTITY", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class GetAllowedIdOperations 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);
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
String[] params = { realm, type };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ALLOWED_OPS", params);
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
IdType idType = convert2IdType(type);
Set ops = amir.getAllowedIdOperations(idType);
String msg = getResourceString("allowed-ops-result");
String[] arg = { "" };
if ((ops != null) && !ops.isEmpty()) {
for (Iterator i = ops.iterator(); i.hasNext(); ) {
arg[0] = ((IdOperation) i.next()).getName();
outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
}
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-allowed-ops-no-ops"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ALLOWED_OPS", params);
} catch (IdRepoException e) {
String[] args = { realm, type, e.getMessage() };
debugError("GetAllowedIdOperations.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ALLOWED_OPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, e.getMessage() };
debugError("GetAllowedIdOperations.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ALLOWED_OPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class GetMembers 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);
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String idName = getStringOptionValue(ARGUMENT_ID_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
IdType idType = convert2IdType(type);
String membershipType = getStringOptionValue(ARGUMENT_MEMBERSHIP_IDTYPE);
IdType membershipIdType = convert2IdType(membershipType);
String[] params = { realm, type, idName, membershipType };
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
Set memberOfs = membershipIdType.canBeMemberOf();
if (!memberOfs.contains(idType)) {
String[] args = { type, membershipType };
throw new CLIException(MessageFormat.format(getResourceString("idrepo-cannot-be-member"), (Object[]) args), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_GET_MEMBERS", params);
AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
Set members = amid.getMembers(membershipIdType);
if ((members != null) && !members.isEmpty()) {
String msg = getResourceString("idrepo-members-result");
String[] arg = { "", "" };
for (Iterator i = members.iterator(); i.hasNext(); ) {
AMIdentity a = (AMIdentity) i.next();
arg[0] = a.getName();
arg[1] = a.getUniversalId();
outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
}
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-no-members"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_GET_MEMBERS", params);
} catch (IdRepoException e) {
String[] args = { realm, type, idName, membershipType, e.getMessage() };
debugError("GetMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, idName, membershipType, e.getMessage() };
debugError("GetMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class GetMemberships 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);
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String idName = getStringOptionValue(ARGUMENT_ID_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
IdType idType = convert2IdType(type);
String membershipType = getStringOptionValue(ARGUMENT_MEMBERSHIP_IDTYPE);
IdType membershipIdType = convert2IdType(membershipType);
String[] params = { realm, type, idName, membershipType };
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
Set memberOfs = idType.canBeMemberOf();
if (!memberOfs.contains(membershipIdType)) {
String[] args = { type, membershipType };
throw new CLIException(MessageFormat.format(getResourceString("idrepo-cannot-be-member"), (Object[]) args), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_GET_MEMBERSHIPS", params);
AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
Set memberships = amid.getMemberships(membershipIdType);
if ((memberships != null) && !memberships.isEmpty()) {
String msg = getResourceString("idrepo-memberships-result");
String[] arg = { "", "" };
for (Iterator i = memberships.iterator(); i.hasNext(); ) {
AMIdentity a = (AMIdentity) i.next();
arg[0] = a.getName();
arg[1] = a.getUniversalId();
outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
}
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-no-memberships"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_GET_MEMBERSHIPS", params);
} catch (IdRepoException e) {
String[] args = { realm, type, idName, membershipType, e.getMessage() };
debugError("GetMemberships.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERSHIPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, idName, membershipType, e.getMessage() };
debugError("GetMemberships.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERSHIPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations