Search in sources :

Example 51 with CLIException

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

the class ModifyAttributeSchemaUIType 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 uitype = getStringOptionValue(ARGUMENT_UI_TYPE);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, schemaType, subSchemaName, attributeSchemaName, uitype };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_ATTRIBUTE_SCHEMA_UI_TYPE", params);
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeSchemaName);
        if (attrSchema == null) {
            String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, uitype, "attribute schema does not exist" };
            attributeSchemaNoExist(attributeSchemaName, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_UI_TYPE", args);
        }
        attrSchema.setUIType(uitype);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_ATTRIBUTE_SCHEMA_UI_TYPE", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-modify-type-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, uitype, e.getMessage() };
        debugError("ModifyAttributeSchemaUIType.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_UI_TYPE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, uitype, e.getMessage() };
        debugError("ModifyAttributeSchemaUIType.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_UI_TYPE", 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 52 with CLIException

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

the class ModifyInheritance 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
    String subSchemaName = getStringOptionValue(IArgument.SUBSCHEMA_NAME);
    String inheritance = getStringOptionValue(ARGUMENT_INHERITANCE);
    IOutput outputWriter = getOutputWriter();
    String[] params = { serviceName, schemaType, subSchemaName };
    ServiceSchema ss = getServiceSchema();
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_INHERITANCE_SUB_SCHEMA", params);
        ss.setInheritance(inheritance);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_INHERITANCE_SUB_SCHEMA", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-inheritance-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
        debugError("ModifyInheritance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_INHERITANCE_SUB_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
        debugError("ModifyInheritance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_INHERITANCE_SUB_SCHEMA", 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) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 53 with CLIException

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

the class ModifySubConfiguration method modifySubConfigToRealm.

private void modifySubConfigToRealm(String realmName, String serviceName, String subConfigName, Map attrValues, String operation) throws CLIException {
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String[] params = { realmName, subConfigName, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SUB_CONFIGURATION_IN_REALM", params);
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminSSOToken);
        ServiceConfig sc = scm.getOrganizationConfig(realmName, null);
        if (sc == null) {
            sc = scm.createOrganizationConfig(realmName, null);
        }
        modifySubConfig(sc, subConfigName, attrValues, operation);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SUB_CONFIGURATION_IN_REALM", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-sub-configuration-to-realm-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { realmName, subConfigName, serviceName, e.getMessage() };
        debugError("ModifySubConfiguration.modifySubConfigToRealm", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SUB_CONFIGURATIONT_IN_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realmName, subConfigName, serviceName, e.getMessage() };
        debugError("ModifySubConfiguration.modifySubConfigToRealm", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SUB_CONFIGURATIONT_IN_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 54 with CLIException

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

the class ModifySubConfiguration method modifySubConfig.

private void modifySubConfig(ServiceConfig sc, String subConfigName, Map attrValues, String operation) throws SSOException, SMSException, CLIException {
    StringTokenizer st = new StringTokenizer(subConfigName, "/");
    int tokenCount = st.countTokens();
    for (int i = 1; i <= tokenCount; i++) {
        String scn = SMSSchema.unescapeName(st.nextToken());
        sc = sc.getSubConfig(scn);
        if (sc == null) {
            Object[] params = { subConfigName };
            String msg = MessageFormat.format(getResourceString("modify-sub-configuration-does-not-exist"), params);
            throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
    if (operation.equals("set")) {
        sc.setAttributes(attrValues);
    } else if (operation.equals("add")) {
        for (Iterator i = attrValues.keySet().iterator(); i.hasNext(); ) {
            String attrName = (String) i.next();
            sc.addAttribute(attrName, (Set) attrValues.get(attrName));
        }
    } else if (operation.equals("delete")) {
        for (Iterator i = attrValues.keySet().iterator(); i.hasNext(); ) {
            sc.removeAttribute((String) i.next());
        }
    } else {
        throw new CLIException(getResourceString("modify-sub-configuration-invalid-operation"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Set(java.util.Set) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

Example 55 with CLIException

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

the class ModifySubConfiguration method modifySubConfigRoot.

private void modifySubConfigRoot(String serviceName, String subConfigName, Map attrValues, String operation) throws CLIException {
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String[] params = { subConfigName, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SUB_CONFIGURATION", params);
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminSSOToken);
        ServiceConfig sc = scm.getGlobalConfig(null);
        modifySubConfig(sc, subConfigName, attrValues, operation);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SUB_CONFIGURATION", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-sub-configuration-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { subConfigName, serviceName, e.getMessage() };
        debugError("ModifySubConfiguration.addSubConfigToRoot", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SUB_CONFIGURATION", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { subConfigName, serviceName, e.getMessage() };
        debugError("ModifySubConfiguration.addSubConfigToRoot", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SUB_CONFIGURATION", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

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