Search in sources :

Example 6 with IOutput

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

the class GetAuthInstance 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 instanceName = getStringOptionValue(AuthOptions.AUTH_INSTANCE_NAME);
    String[] params = { realm, instanceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_AUTH_INSTANCE", params);
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        AMAuthenticationInstance ai = mgr.getAuthenticationInstance(instanceName);
        if (ai != null) {
            IOutput outputWriter = getOutputWriter();
            Map attributeValues = ai.getAttributeValues();
            if ((attributeValues != null) && !attributeValues.isEmpty()) {
                AMAuthenticationSchema schema = mgr.getAuthenticationSchema(ai.getType());
                String serviceName = schema.getServiceName();
                outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-succeeded"));
                outputWriter.printlnMessage(FormatUtils.printAttributeValues(getResourceString("authentication-get-auth-instance-result"), attributeValues, CLIUtil.getPasswordFields(serviceName)));
            } else {
                outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-no-values"));
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_GET_AUTH_INSTANCE", params);
        } else {
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
            throw new CLIException(getResourceString("authentication-get-auth-instance-not-found"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    } catch (SSOException e) {
        debugError("GetAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("GetAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (AMConfigurationException e) {
        debugError("GetAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) AMAuthenticationSchema(com.sun.identity.authentication.config.AMAuthenticationSchema) CLIException(com.sun.identity.cli.CLIException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 7 with IOutput

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

the class RegisterAuthModule 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 authModule = getStringOptionValue(AUTH_MODULE);
    ServiceSchema ss = getServiceSchema(ISAuthConstants.AUTH_SERVICE_NAME, null, "Global");
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { ISAuthConstants.AUTH_SERVICE_NAME };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REGISTER_AUTH_MODULE", params);
        Map attrValues = ss.getAttributeDefaults();
        Set values = (Set) attrValues.get(AUTH_AUTHENTICATOR_ATTR);
        if ((values == null) || values.isEmpty()) {
            values = new HashSet(2);
        }
        values.add(authModule);
        ss.setAttributeDefaults(AUTH_AUTHENTICATOR_ATTR, values);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REGISTER_AUTH_MODULE", params);
        outputWriter.printlnMessage(getResourceString("register-auth-module-succeeded"));
    } catch (SSOException e) {
        String[] args = { ISAuthConstants.AUTH_SERVICE_NAME, e.getMessage() };
        debugError("RegisterAuthModule.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REGISTER_AUTH_MODULE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { ISAuthConstants.AUTH_SERVICE_NAME, e.getMessage() };
        debugError("RegisterAuthModule.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REGISTER_AUTH_MODULE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 8 with IOutput

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

the class RealmSetAttributeValues 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    boolean bAppend = isOptionSet(OPT_APPEND);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        if (bAppend) {
            for (Iterator i = attributeValues.keySet().iterator(); i.hasNext(); ) {
                String attributeName = (String) i.next();
                String[] params = { realm, serviceName, attributeName };
                Set values = (Set) attributeValues.get(attributeName);
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTR_VALUES_REALM", params);
                ocm.addAttributeValues(serviceName, attributeName, values);
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTR_VALUES_REALM", params);
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-attribute-values-realm-succeed"), (Object[]) params));
            }
        } else {
            String[] params = { realm, serviceName };
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_ATTR_VALUES_REALM", params);
            ocm.setAttributes(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_ATTR_VALUES_REALM", params);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-attribute-values-realm-succeed"), (Object[]) params));
        }
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmSetAttributeValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_ATTR_VALUES_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) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Map(java.util.Map)

Example 9 with IOutput

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

the class RealmSetServiceAttributeValues method handleDynamicAttributes.

private void handleDynamicAttributes(AMIdentity idRealm, String realm, String serviceName, Map attributeValues, boolean bAppend) throws CLIException, IdRepoException, SSOException {
    String[] params = { realm, serviceName };
    IOutput outputWriter = getOutputWriter();
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_SVC_ATTR_VALUES_REALM", params);
    if (bAppend) {
        Map newValues = new HashMap();
        Map currentVal = idRealm.getAttributes(attributeValues.keySet());
        for (Iterator i = attributeValues.keySet().iterator(); i.hasNext(); ) {
            String attrName = (String) i.next();
            Set origVal = (Set) currentVal.get(attrName);
            Set newVal = (Set) attributeValues.get(attrName);
            if ((origVal == null) || origVal.isEmpty()) {
                newValues.put(attrName, newVal);
            } else {
                origVal.addAll(newVal);
                newValues.put(attrName, origVal);
            }
        }
        idRealm.modifyService(serviceName, newValues);
    } else {
        idRealm.modifyService(serviceName, attributeValues);
    }
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SVC_ATTR_VALUES_REALM", params);
    outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-svc-attribute-values-realm-succeed"), (Object[]) params));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with IOutput

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

the class RealmSetServiceAttributeValues 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    boolean bAppend = isOptionSet(OPT_APPEND);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    attributeValues = processFileAttributes(attributeValues);
    try {
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        if (servicesFromIdRepo.contains(serviceName)) {
            handleDynamicAttributes(ai, realm, serviceName, attributeValues, bAppend);
        } else {
            handleOrganizatioAttribute(realm, serviceName, attributeValues, bAppend);
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmSetServiceAttributeValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmSetServiceAttributeValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

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