Search in sources :

Example 66 with CLIException

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

the class SchemaCommand method getServiceSchemaManager.

protected ServiceSchemaManager getServiceSchemaManager(String serviceName) throws CLIException {
    ServiceSchemaManager mgr = null;
    SSOToken adminSSOToken = getAdminSSOToken();
    if (serviceName != null) {
        try {
            mgr = new ServiceSchemaManager(serviceName, adminSSOToken);
        } catch (SSOException e) {
            debugError("SchemaCommand.getServiceSchemaManager", e);
            throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        } catch (SMSException e) {
            debugError("SchemaCommand.getServiceSchemaManager", e);
            throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
    return mgr;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 67 with CLIException

use of com.sun.identity.cli.CLIException 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 68 with CLIException

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

the class RemoveAgentsFromGroup method validateAgents.

private void validateAgents(String realm, SSOToken adminSSOToken, AMIdentity agentGroup, List agentNames) throws CLIException, IdRepoException, SSOException {
    for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
        String agentName = (String) i.next();
        AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
        if (!amid.isMember(agentGroup)) {
            Object[] p = { agentName, agentGroup.getName() };
            throw new CLIException(MessageFormat.format(getResourceString("remove-agent-to-group-agent-not-member"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

Example 69 with CLIException

use of com.sun.identity.cli.CLIException 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 70 with CLIException

use of com.sun.identity.cli.CLIException 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)

Aggregations

CLIException (com.sun.identity.cli.CLIException)282 SSOException (com.iplanet.sso.SSOException)171 SMSException (com.sun.identity.sm.SMSException)150 IOutput (com.sun.identity.cli.IOutput)136 SSOToken (com.iplanet.sso.SSOToken)116 Set (java.util.Set)88 Iterator (java.util.Iterator)62 List (java.util.List)61 IOException (java.io.IOException)53 IdRepoException (com.sun.identity.idm.IdRepoException)48 ServiceSchema (com.sun.identity.sm.ServiceSchema)46 AMIdentity (com.sun.identity.idm.AMIdentity)43 Map (java.util.Map)42 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)33 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)29 AttributeSchema (com.sun.identity.sm.AttributeSchema)28 CLIRequest (com.sun.identity.cli.CLIRequest)27 AfterTest (org.testng.annotations.AfterTest)27 BeforeTest (org.testng.annotations.BeforeTest)27 Test (org.testng.annotations.Test)27