use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class AgentConfiguration method getAgentAttributes.
/**
* Returns agent's attribute values.
*
* @param ssoToken Single Sign On token that is to be used for query.
* @param realm Realm where agent resides.
* @param agentName Name of agent.
* @param bInherit <code>true</code> to inherit from group.
* @return agent's attribute values.
* @throws IdRepoException if there are Id Repository related errors.
* @throws SSOException if the Single Sign On token is invalid or has
* expired.
* @throws SMSException if there are errors in service management layers.
*/
public static Map getAgentAttributes(SSOToken ssoToken, String realm, String agentName, boolean bInherit) throws IdRepoException, SMSException, SSOException {
IdType type = (bInherit) ? IdType.AGENT : IdType.AGENTONLY;
AMIdentity amid = new AMIdentity(ssoToken, agentName, type, realm, null);
return getAgentAttributes(amid, true);
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class ShowAgentGroup 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 agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
String outfile = getStringOptionValue(IArgument.OUTPUT_FILE);
String[] params = { realm, agentGroupName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_AGENT_GROUP", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
if (!amid.isExists()) {
String[] args = { realm, agentGroupName, "agent group did not exist" };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
Object[] p = { agentGroupName };
String msg = MessageFormat.format(getResourceString("show-agent-group-does-not-exist"), p);
throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
Map values = AgentConfiguration.getAgentGroupAttributes(adminSSOToken, realm, agentGroupName);
Set passwords = AgentConfiguration.getAttributesSchemaNames(amid, AttributeSchema.Syntax.PASSWORD);
if ((values != null) && !values.isEmpty()) {
StringBuilder buff = new StringBuilder();
// Used to generated a sorted list of property names for easier viewing
List<String> sortedKeys = new ArrayList<String>(values.keySet());
Collections.sort(sortedKeys);
for (String attrName : sortedKeys) {
if (passwords.contains(attrName)) {
buff.append(attrName).append("=********\n");
} else {
Set vals = (Set) values.get(attrName);
if (vals.isEmpty()) {
buff.append(attrName).append("=").append("\n");
} else {
for (Iterator j = vals.iterator(); j.hasNext(); ) {
String val = (String) j.next();
buff.append(attrName).append("=").append(val).append("\n");
}
}
}
}
if (outfile == null) {
outputWriter.printlnMessage(buff.toString());
} else {
writeToFile(outfile, buff.toString());
outputWriter.printlnMessage(getResourceString("show-agent-group-to-file"));
}
} else {
outputWriter.printlnMessage(getResourceString("show-agent-group-no-attributes"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_AGENT_GROUP", params);
} catch (SMSException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("ShowAgentGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IdRepoException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("ShowAgentGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("ShowAgentGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class UpdateAgent 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 agentName = getStringOptionValue(IArgument.AGENT_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
boolean bSet = isOptionSet(IArgument.AGENT_SET_ATTR_VALUE);
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, agentName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_AGENT", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
if (!amid.isExists()) {
String[] args = { realm, agentName, "agent did not exist" };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
Object[] p = { agentName };
String msg = MessageFormat.format(getResourceString("update-agent-does-not-exist"), p);
throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
AgentConfiguration.updateAgent(adminSSOToken, realm, agentName, attributeValues, bSet);
outputWriter.printlnMessage(getResourceString("update-agent-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_AGENT", params);
} catch (IdRepoException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class UpdateAgentGroup 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 agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
boolean bSet = isOptionSet(IArgument.AGENT_SET_ATTR_VALUE);
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, agentGroupName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_AGENT_GROUP", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
if (!amid.isExists()) {
String[] args = { realm, agentGroupName, "agent group did not exist" };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
Object[] p = { agentGroupName };
String msg = MessageFormat.format(getResourceString("update-agent-group-does-not-exist"), p);
throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
AgentConfiguration.updateAgentGroup(adminSSOToken, realm, agentGroupName, attributeValues, bSet);
outputWriter.printlnMessage(getResourceString("update-agent-group-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_AGENT_GROUP", params);
} catch (IdRepoException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentity 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