Search in sources :

Example 16 with IOutput

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

the class RealmAssignService 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);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    Map<String, Set<String>> attributeValues = null;
    if ((datafile != null) || (attrValues != null)) {
        attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
        attributeValues = processFileAttributes(attributeValues);
    }
    IOutput outputWriter = getOutputWriter();
    String[] params = { realm, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ASSIGN_SERVICE_TO_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignableServices = ocm.getAssignableServices();
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = amir.getRealmIdentity();
        Set dynAssignableServices = ai.getAssignableServices();
        if (assignableServices.contains(serviceName)) {
            ocm.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        if (dynAssignableServices.contains(serviceName)) {
            ai.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ASSIGN_SERVICE_TO_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", 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) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 17 with IOutput

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

the class RealmGetAssignableServices 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);
    String[] params = { realm };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set serviceNames = ocm.getAssignableServices();
        Set dynamicServiceNames = getAssignableDynamicServiceNames(adminSSOToken, realm);
        if ((dynamicServiceNames != null) && !dynamicServiceNames.isEmpty()) {
            if ((serviceNames != null) && !serviceNames.isEmpty()) {
                serviceNames.addAll(dynamicServiceNames);
            } else {
                serviceNames = dynamicServiceNames;
            }
        }
        IOutput outputWriter = getOutputWriter();
        if ((serviceNames != null) && !serviceNames.isEmpty()) {
            String msg = getResourceString("realm-getassignable-services-result");
            outputWriter.printlnMessage(FormatUtils.printServiceNames(serviceNames, msg, adminSSOToken));
            outputWriter.printlnMessage(getResourceString("realm-getassignable-services-succeed"));
        } else {
            outputWriter.printlnMessage(getResourceString("realm-getassignable-services-no-services"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", 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) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 18 with IOutput

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

the class GetAttributeDefaults 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);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    String[] params = { serviceName, schemaType, subSchemaName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_SCHEMA_ATTR_DEFAULTS", params);
    Map attrValues = ss.getAttributeDefaults();
    retainValues(rc, attrValues);
    maskPasswordValues(ss, attrValues);
    if (!attrValues.isEmpty()) {
        outputWriter.printlnMessage(FormatUtils.printAttributeValues(getResourceString("schema-get-attribute-defaults-result"), attrValues));
        outputWriter.printlnMessage(getResourceString("schema-get-attribute-defaults-succeed"));
    } else {
        outputWriter.printlnMessage(getResourceString("schema-get-attribute-defaults-no-matching-attr"));
    }
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_SCHEMA_ATTR_DEFAULTS", params);
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) IOutput(com.sun.identity.cli.IOutput) Map(java.util.Map)

Example 19 with IOutput

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

the class AddPluginInterface 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 i18nKey = getStringOptionValue(ARGUMENT_I18N_KEY);
    String interfaceName = getStringOptionValue(ARGUMENT_INTERFACE_NAME);
    String pluginName = getStringOptionValue(ARGUMENT_PLUGIN_NAME);
    ServiceSchemaManager ssm = getServiceSchemaManager();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, pluginName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_PLUGIN_INTERFACE", params);
        ssm.addPluginInterface(pluginName, interfaceName, i18nKey);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_PLUGIN_INTERFACE", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-plugin-interface-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, pluginName, e.getMessage() };
        debugError("AddPluginInterface.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_INTERFACE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, pluginName, e.getMessage() };
        debugError("AddPluginInterface.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_INTERFACE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 20 with IOutput

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

the class StopRecord method handleRequest.

/**
     * Stop recording
     * @param rc Request Context.
     * @throws CLIException
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    IOutput outputWriter = getOutputWriter();
    String serverName = getStringOptionValue(IArgument.SERVER_NAME);
    debug.message("Stop recording: serverURL : '{}'", serverName);
    String[] argsAttempt = { serverName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_STOP_RECORD", argsAttempt);
    SSOToken adminSSOToken = getAdminSSOToken();
    try {
        if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
            String message = "ServerName '" + serverName + "' doesn't exist";
            debug.error(message);
            outputWriter.printlnMessage(message);
            String[] args = { serverName, message };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STOP_RECORD", args);
            return;
        }
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "application/json");
        RestCommand restCommand = new RestCommand();
        String result = restCommand.sendRestCommand(adminSSOToken.getTokenID(), new URL(serverName + "/json/" + RecordConstants.RECORD_REST_ENDPOINT + "?_action=" + RecordConstants.STOP_ACTION), "POST", headers, "");
        debug.message("Stop recording with success. Result : '{}'", result);
        if (result.isEmpty()) {
            outputWriter.printlnMessage("Result from server is empty. An error occurred. See debug logs for more " + "information");
            String[] args = { serverName, "Result from server is empty. An error occurred." };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STATUS_RECORD", args);
        }
        String[] args = { serverName, result };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_STOP_RECORD", args);
        outputWriter.printlnMessage(result);
    } catch (IOException | SMSException | SSOException e) {
        debug.error("An error occurred", e);
        outputWriter.printlnMessage(e.getMessage());
        String[] args = { serverName, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STOP_RECORD", args);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) RestCommand(com.sun.identity.cli.rest.RestCommand) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) URL(java.net.URL)

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