Search in sources :

Example 46 with IOutput

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);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 47 with IOutput

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);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 48 with IOutput

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());
    }
}
Also used : NameIDInfo(com.sun.identity.saml2.common.NameIDInfo) SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) NameID(com.sun.identity.saml2.assertion.NameID) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) CLIException(com.sun.identity.cli.CLIException) HashMap(java.util.HashMap) Map(java.util.Map) NameIDInfoKey(com.sun.identity.saml2.common.NameIDInfoKey) HashSet(java.util.HashSet)

Example 49 with IOutput

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);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 50 with IOutput

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);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Aggregations

IOutput (com.sun.identity.cli.IOutput)152 CLIException (com.sun.identity.cli.CLIException)137 SSOException (com.iplanet.sso.SSOException)123 SSOToken (com.iplanet.sso.SSOToken)99 SMSException (com.sun.identity.sm.SMSException)98 Set (java.util.Set)61 Iterator (java.util.Iterator)53 IdRepoException (com.sun.identity.idm.IdRepoException)45 List (java.util.List)45 AMIdentity (com.sun.identity.idm.AMIdentity)42 Map (java.util.Map)35 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)26 ServiceSchema (com.sun.identity.sm.ServiceSchema)26 IdType (com.sun.identity.idm.IdType)19 IOException (java.io.IOException)18 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)17 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 AttributeSchema (com.sun.identity.sm.AttributeSchema)14