use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class AddAgentsToGroup 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);
List agentNames = rc.getOption(IArgument.AGENT_NAMES);
String[] params = { realm, agentGroupName, "" };
String agentName = "";
try {
AMIdentity amidGroup = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
agentName = (String) i.next();
params[2] = agentName;
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_AGENT_TO_GROUP", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
AgentConfiguration.AddAgentToGroup(amidGroup, amid);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_AGENT_TO_GROUP", params);
}
if (agentNames.size() > 1) {
outputWriter.printlnMessage(getResourceString("add-agent-to-group-succeeded-pural"));
} else {
outputWriter.printlnMessage(getResourceString("add-agent-to-group-succeeded"));
}
} catch (IdRepoException e) {
String[] args = { realm, agentGroupName, agentName, e.getMessage() };
debugError("AddAgentsToGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { realm, agentGroupName, agentName, e.getMessage() };
debugError("AddAgentsToGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentGroupName, agentName, e.getMessage() };
debugError("AddAgentsToGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class DeleteAgentGroups 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);
List names = (List) rc.getOption(IArgument.AGENT_GROUP_NAMES);
String file = getStringOptionValue(IArgument.FILE);
if (names == null) {
names = new ArrayList();
}
if (file != null) {
names.addAll(AttributeValues.parseValues(file));
}
if (names.isEmpty()) {
throw new CLIException(getResourceString("missing-agent-group-names"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
String displayableNames = tokenize(names);
String[] params = { realm, displayableNames };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_AGENT_GROUPS", params);
try {
Set setDelete = new HashSet();
for (Iterator i = names.iterator(); i.hasNext(); ) {
String name = (String) i.next();
AMIdentity amid = new AMIdentity(adminSSOToken, name, IdType.AGENTGROUP, realm, null);
setDelete.add(amid);
}
AgentConfiguration.deleteAgentGroups(adminSSOToken, realm, setDelete);
IOutput outputWriter = getOutputWriter();
outputWriter.printlnMessage(getResourceString("delete-agent-group-succeeded"));
for (Iterator i = names.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage(" " + (String) i.next());
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_AGENT_GROUPS", params);
} catch (IdRepoException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgentGroups.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENT_GROUPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgentGroups.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENT_GROUPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgentGroups.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENT_GROUPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class BulkFederation method saml2FederateUser.
private void saml2FederateUser(String localUserId, String remoteUserId, BufferedWriter out) throws CLIException {
SSOToken adminSSOToken = getAdminSSOToken();
try {
AMIdentity amid = IdUtils.getIdentity(adminSSOToken, localUserId);
String nameIdValue = createNameIdentifier();
NameID nameId = AssertionFactory.getInstance().createNameID();
nameId.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent");
if (isIDP) {
nameId.setNameQualifier(localEntityId);
nameId.setSPNameQualifier(remoteEntityId);
} else {
nameId.setNameQualifier(remoteEntityId);
nameId.setSPNameQualifier(localEntityId);
}
nameId.setValue(nameIdValue);
String role = (isIDP) ? SAML2Constants.IDP_ROLE : SAML2Constants.SP_ROLE;
NameIDInfoKey key = new NameIDInfoKey(nameIdValue, localEntityId, remoteEntityId);
NameIDInfo info = new NameIDInfo(localEntityId, remoteEntityId, nameId, role, true);
Map attributes = amid.getAttributes(saml2UserAttributesFed);
Set setInfoKey = (Set) attributes.get(SAML2Constants.NAMEID_INFO_KEY);
if ((setInfoKey == null) || setInfoKey.isEmpty()) {
setInfoKey = new HashSet(2);
attributes.put(SAML2Constants.NAMEID_INFO_KEY, setInfoKey);
}
setInfoKey.add(key.toValueString());
Set setInfo = (Set) attributes.get(SAML2Constants.NAMEID_INFO);
if ((setInfo == null) || setInfo.isEmpty()) {
setInfo = new HashSet(2);
attributes.put(SAML2Constants.NAMEID_INFO, setInfo);
}
setInfo.add(info.toValueString());
amid.setAttributes(attributes);
amid.store();
out.write(remoteUserId + "|" + nameIdValue);
out.newLine();
} catch (SAML2Exception e) {
debugError("BulkFederation.saml2FederateUser", e);
Object[] param = { localUserId };
throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-cannot-federate"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
debugError("BulkFederation.saml2FederateUser", e);
Object[] param = { localUserId };
throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-cannot-federate"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IdRepoException e) {
debugError("BulkFederation.saml2FederateUser", e);
IOutput outputWriter = getOutputWriter();
outputWriter.printlnError(e.getMessage());
} catch (SSOException e) {
debugError("BulkFederation.saml2FederateUser", e);
IOutput outputWriter = getOutputWriter();
outputWriter.printlnError(e.getMessage());
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class ShowSite 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 siteName = getStringOptionValue(IArgument.SITE_NAME);
String[] params = { siteName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_SITE", params);
if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
String primaryURL = SiteConfiguration.getSitePrimaryURL(adminSSOToken, siteName);
Set failoverURLs = SiteConfiguration.getSiteSecondaryURLs(adminSSOToken, siteName);
String siteId = SiteConfiguration.getSiteID(adminSSOToken, siteName);
Object[] args = { primaryURL };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-primaryURL"), args));
if ((failoverURLs != null) && !failoverURLs.isEmpty()) {
outputWriter.printlnMessage(getResourceString("show-site-secondaryURL"));
for (Iterator i = failoverURLs.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage((String) i.next());
}
} else {
outputWriter.printlnMessage(getResourceString("show-site-no-secondaryURL"));
}
outputWriter.printlnMessage("");
args[0] = siteId;
outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-ID"), args));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-no-exists"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_SITE", params);
} catch (SSOException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSite.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSite.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class ShowSiteMembers method handleRequest.
/**
* Display members of a site.
*
* @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 siteName = getStringOptionValue(IArgument.SITE_NAME);
String[] params = { siteName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_SITE_MEMBERS", params);
IOutput outputWriter = getOutputWriter();
try {
Set members = SiteConfiguration.listServers(adminSSOToken, siteName);
if ((members != null) && !members.isEmpty()) {
for (Iterator i = members.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage((String) i.next());
}
} else {
outputWriter.printlnMessage(getResourceString("show-site-members-no-members"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_SITE_MEMBERS", params);
} catch (ConfigurationException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSiteMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSiteMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSiteMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations