Search in sources :

Example 1 with IOutput

use of com.sun.identity.cli.IOutput 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);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) 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) Map(java.util.Map)

Example 2 with IOutput

use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.

the class ShowAgentTypes 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();
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_AGENT_TYPES", null);
        Set agentTypes = AgentConfiguration.getAgentTypes();
        if (!agentTypes.isEmpty()) {
            for (Iterator i = agentTypes.iterator(); i.hasNext(); ) {
                outputWriter.printlnMessage((String) i.next());
            }
        } else {
            outputWriter.printlnMessage(getResourceString("show-agent-type-no-results"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_AGENT_TYPES", null);
    } catch (SMSException e) {
        String[] args = { e.getMessage() };
        debugError("ShowAgentTypes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_TYPES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { e.getMessage() };
        debugError("ShowAgentTypes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_TYPES", 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 3 with IOutput

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

Example 4 with IOutput

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

Example 5 with IOutput

use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.

the class AddAuthConfigurationEntry method handleRequest.

/**
     * Handles request.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String configName = getStringOptionValue(AuthOptions.AUTH_CONFIG_NAME);
    String moduleName = getStringOptionValue(AuthOptions.AUTH_CONFIG_MODULE_NAME);
    String criteria = getStringOptionValue(AuthOptions.AUTH_CONFIG_CRITERIA);
    String options = getStringOptionValue(AuthOptions.AUTH_CONFIG_OPTIONS);
    String[] params = { realm, configName, moduleName };
    if (!POSSIBLE_CRITERIA.contains(criteria)) {
        throw new CLIException(getResourceString("authentication-add-auth-config-entry-criteria.invalid"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    int pos = getPosition();
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_AUTH_CONFIG_ENTRY", params);
    try {
        AuthConfigurationEntry ae = new AuthConfigurationEntry(moduleName, criteria, options);
        Set instanceNames = getInstanceNames(realm, adminSSOToken);
        String instanceName = ae.getLoginModuleName();
        if (!instanceNames.contains(instanceName)) {
            Object[] p = { instanceName };
            throw new CLIException(MessageFormat.format(getResourceString("authentication-add-auth-config-entry-not-found"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        List entries = getConfigEntries(realm, configName, adminSSOToken);
        if (entries == null) {
            entries = new ArrayList();
        }
        if ((pos == -1) || (pos >= entries.size())) {
            entries.add(ae);
        } else {
            entries.add(pos, ae);
        }
        Map configData = new HashMap(2);
        Set tmp = new HashSet(2);
        String xml = AMAuthConfigUtils.authConfigurationEntryToXMLString(entries);
        tmp.add(xml);
        configData.put(AuthOptions.AUTH_CONFIG_ATTR, tmp);
        IOutput outputWriter = getOutputWriter();
        AMAuthConfigUtils.replaceNamedConfig(configName, 0, configData, realm, adminSSOToken);
        outputWriter.printlnMessage(getResourceString("authentication-add-auth-config-entry-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_ADD_AUTH_CONFIG_ENTRY", params);
    } catch (AMConfigurationException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        String[] p = { realm, configName, moduleName, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        String[] p = { realm, configName, moduleName, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        String[] p = { realm, configName, moduleName, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) SSOException(com.iplanet.sso.SSOException) AuthConfigurationEntry(com.sun.identity.authentication.config.AuthConfigurationEntry) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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