Search in sources :

Example 41 with IOutput

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

the class SetAttributeSchemaStartRange 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();
    String schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String subSchemaName = getStringOptionValue(IArgument.SUBSCHEMA_NAME);
    String attributeSchemaName = getStringOptionValue(IArgument.ATTRIBUTE_SCHEMA);
    String range = getStringOptionValue(ARGUMENT_RANGE);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, schemaType, subSchemaName, attributeSchemaName, range };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_ATTRIBUTE_SCHEMA_START_RANGE", params);
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeSchemaName);
        if (attrSchema == null) {
            String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, range, "attribute schema does not exist" };
            attributeSchemaNoExist(attributeSchemaName, "FAILED_SET_ATTRIBUTE_SCHEMA_START_RANGE", args);
        }
        attrSchema.setStartRange(range);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_ATTRIBUTE_SCHEMA_START_RANGE", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-set-start-range-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, range, e.getMessage() };
        debugError("SetAttributeSchemaStartRange.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_ATTRIBUTE_SCHEMA_START_RANGE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, range, e.getMessage() };
        debugError("SetAttributeSchemaStartRange.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_ATTRIBUTE_SCHEMA_START_RANGE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) AttributeSchema(com.sun.identity.sm.AttributeSchema) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 42 with IOutput

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

the class RemoveAgentsFromGroup 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 agentGroup = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
        if (!agentGroup.isExists()) {
            Object[] p = { agentGroupName };
            throw new CLIException(MessageFormat.format(getResourceString("remove-agent-to-group-agent-invalid-group"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        validateAgents(realm, adminSSOToken, agentGroup, agentNames);
        for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
            agentName = (String) i.next();
            params[2] = agentName;
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_AGENT_FROM_GROUP", params);
            AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
            AgentConfiguration.removeAgentGroup(amid, agentGroup);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_AGENT_FROM_GROUP", params);
        }
        if (agentNames.size() > 1) {
            outputWriter.printlnMessage(getResourceString("remove-agent-to-group-succeeded-pural"));
        } else {
            outputWriter.printlnMessage(getResourceString("remove-agent-to-group-succeeded"));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, agentGroupName, agentName, e.getMessage() };
        debugError("RemoveAgentsFromGroup.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_AGENT_FROM_GROUP", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentGroupName, agentName, e.getMessage() };
        debugError("RemoveAgentsFromGroup.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_AGENT_FROM_GROUP", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, agentGroupName, agentName, e.getMessage() };
        debugError("RemoveAgentsFromGroup.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_AGENT_FROM_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) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 43 with IOutput

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

the class ShowAgent 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 outfile = getStringOptionValue(IArgument.OUTPUT_FILE);
    boolean includeHashedPassword = isOptionSet(IArgument.AGENT_HASHED_PASSWORD);
    boolean inherit = isOptionSet(OPT_INHERIT);
    String[] params = { realm, agentName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_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_SHOW_AGENT", args);
            Object[] p = { agentName };
            String msg = MessageFormat.format(getResourceString("show-agent-agent-does-not-exist"), p);
            throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        Map values = AgentConfiguration.getAgentAttributes(adminSSOToken, realm, agentName, inherit);
        Set passwords = AgentConfiguration.getAttributesSchemaNames(amid, AttributeSchema.Syntax.PASSWORD);
        String agentType = AgentConfiguration.getAgentType(amid);
        // OAUTH2 agent passwords are stored in plaintext so should not be included since they are not hashed.
        if (AgentConfiguration.AGENT_TYPE_OAUTH2.equals(agentType)) {
            includeHashedPassword = false;
        }
        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) {
                // Always true if user has asked to include the hashed password in the export.
                if (includeHashedPassword || !passwords.contains(attrName)) {
                    Set vals = (Set) values.get(attrName);
                    if (vals != null) {
                        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-to-file"));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("show-agent-no-attributes"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_AGENT", params);
    } catch (SMSException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("ShowAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("ShowAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("ShowAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT", 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 44 with IOutput

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

the class DeleteAgents 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 agentNames = (List) rc.getOption(IArgument.AGENT_NAMES);
    String file = getStringOptionValue(IArgument.FILE);
    if (agentNames == null) {
        agentNames = new ArrayList();
    }
    if (file != null) {
        agentNames.addAll(AttributeValues.parseValues(file));
    }
    if (agentNames.isEmpty()) {
        throw new CLIException(getResourceString("missing-agent-names"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    String displayableNames = tokenize(agentNames);
    String[] params = { realm, displayableNames };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_AGENTS", params);
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        Set setDelete = new HashSet();
        for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
            String name = (String) i.next();
            AMIdentity amid = new AMIdentity(adminSSOToken, name, IdType.AGENTONLY, realm, null);
            setDelete.add(amid);
        }
        amir.deleteIdentities(setDelete);
        IOutput outputWriter = getOutputWriter();
        outputWriter.printlnMessage(getResourceString("delete-agent-succeeded"));
        for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
            outputWriter.printlnMessage("    " + (String) i.next());
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_AGENTS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, displayableNames, e.getMessage() };
        debugError("DeleteAgents.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, displayableNames, e.getMessage() };
        debugError("DeleteAgents.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENTS", 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) 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) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 45 with IOutput

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

the class ListAgents 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 patternType = getStringOptionValue(IArgument.AGENT_TYPE);
    String filter = getStringOptionValue(IArgument.FILTER);
    if (patternType == null) {
        patternType = "";
    }
    if ((filter == null) || (filter.length() == 0)) {
        filter = "*";
    }
    String[] params = { realm, patternType, filter };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_AGENTS", params);
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        IdSearchResults isr = amir.searchIdentities(IdType.AGENTONLY, filter, new IdSearchControl());
        Set results = isr.getSearchResults();
        if ((results != null) && !results.isEmpty()) {
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                if (!matchType(amid, patternType)) {
                    i.remove();
                }
            }
        }
        if ((results != null) && !results.isEmpty()) {
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                Object[] args = { amid.getName(), amid.getUniversalId() };
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("format-search-agent-results"), args));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("search-agent-no-entries"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_AGENTS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, patternType, filter, e.getMessage() };
        debugError("ListAgents.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, patternType, filter, e.getMessage() };
        debugError("ListAgents.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

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