Search in sources :

Example 26 with AMConfigurationException

use of com.sun.identity.authentication.config.AMConfigurationException in project OpenAM by OpenRock.

the class UpdateAuthInstance 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 datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    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);
    String[] params = { realm, instanceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_AUTH_INSTANCE", params);
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        AMAuthenticationInstance ai = mgr.getAuthenticationInstance(instanceName);
        if (ai != null) {
            ai.setAttributeValues(attributeValues);
            getOutputWriter().printlnMessage(getResourceString("authentication-update-auth-instance-succeeded"));
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_AUTH_INSTANCE", params);
        } else {
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AUTH_INSTANCE", params);
            throw new CLIException(getResourceString("authentication-update-auth-instance-not-found"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    } catch (AMConfigurationException e) {
        debugError("UpdateAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("UpdateAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("UpdateAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AUTH_INSTANCE", params);
        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) CLIException(com.sun.identity.cli.CLIException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) List(java.util.List) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) SSOException(com.iplanet.sso.SSOException) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 27 with AMConfigurationException

use of com.sun.identity.authentication.config.AMConfigurationException in project OpenAM by OpenRock.

the class AuthConfigViewBean method getTableData.

private List getTableData() throws ModelControlException {
    List entryList = new ArrayList();
    CCActionTable table = (CCActionTable) getChild(AUTH_ENTRY_TABLE);
    table.restoreStateData();
    int size = entryTableModel.getNumRows();
    for (int i = 0; i < size; i++) {
        entryTableModel.setRowIndex(i);
        String module = (String) entryTableModel.getValue(MODULE_NAME);
        String flag = (String) entryTableModel.getValue(CRITERIA);
        String option = (String) entryTableModel.getValue(OPTION_FIELD);
        try {
            AuthConfigurationEntry ae = new AuthConfigurationEntry(module, flag, option);
            entryList.add(ae);
        } catch (AMConfigurationException e) {
            debug.warning("AuthConfigViewBean.getTableData() " + "Couldn't create the auth configuration entry", e);
        }
    }
    return entryList;
}
Also used : ArrayList(java.util.ArrayList) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) ArrayList(java.util.ArrayList) OptionList(com.iplanet.jato.view.html.OptionList) List(java.util.List) CCActionTable(com.sun.web.ui.view.table.CCActionTable) AuthConfigurationEntry(com.sun.identity.authentication.config.AuthConfigurationEntry)

Example 28 with AMConfigurationException

use of com.sun.identity.authentication.config.AMConfigurationException in project OpenAM by OpenRock.

the class AuthConfigViewBean method handleAddEntryButtonRequest.

/**
     * Handles add auth instances request.
     *
     * @param event Request invocation event
     */
public void handleAddEntryButtonRequest(RequestInvocationEvent event) throws ModelControlException {
    // get the current values from the table so we don't 
    // overwrite any changes already made by the user.
    List currentEntries = getTableData();
    // create a new entry, add it to the list, and generat the xml
    // use the first entry from the available instances list as default
    Iterator i = getInstanceNames().iterator();
    String moduleName = (String) i.next();
    try {
        AuthConfigurationEntry ace = new AuthConfigurationEntry(moduleName, REQUIRED_FLAG, "");
        currentEntries.add(ace);
        acModel.setEntries(currentEntries);
        setPageSessionAttribute(ENTRY_LIST, acModel.getXMLValue(getRealmName(), getConfigName()));
    } catch (AMConfigurationException a) {
        debug.warning("AuthConfigViewBean.handleAddEntryButtonRequest() " + "Adding new config entry failed", a);
    }
    cacheValues();
    populateEntryTable();
    forwardTo();
}
Also used : Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) ArrayList(java.util.ArrayList) OptionList(com.iplanet.jato.view.html.OptionList) List(java.util.List) AuthConfigurationEntry(com.sun.identity.authentication.config.AuthConfigurationEntry)

Example 29 with AMConfigurationException

use of com.sun.identity.authentication.config.AMConfigurationException in project OpenAM by OpenRock.

the class GetAuthConfigurationEntries 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 configName = getStringOptionValue(AuthOptions.AUTH_CONFIG_NAME);
    String[] params = { realm, configName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_AUTH_CONFIG_ENTRIES", params);
    try {
        Map configData = AMAuthConfigUtils.getNamedConfig(configName, realm, adminSSOToken);
        IOutput outputWriter = getOutputWriter();
        boolean hasData = false;
        if ((configData != null) && !configData.isEmpty()) {
            Set tmp = (Set) configData.get(AuthOptions.AUTH_CONFIG_ATTR);
            if ((tmp != null) && !tmp.isEmpty()) {
                hasData = true;
                String xml = (String) tmp.iterator().next();
                List entryList = new ArrayList(AMAuthConfigUtils.xmlToAuthConfigurationEntry(xml));
                outputWriter.printlnMessage(getResourceString("authentication-get-auth-config-entries-succeeded"));
                for (Iterator i = entryList.iterator(); i.hasNext(); ) {
                    AuthConfigurationEntry e = (AuthConfigurationEntry) i.next();
                    String options = e.getOptions();
                    if (options == null) {
                        options = "";
                    }
                    Object[] args = { e.getLoginModuleName(), e.getControlFlag(), options };
                    outputWriter.printlnMessage(MessageFormat.format(getResourceString("authentication-get-auth-config-entries-entry"), args));
                }
            }
        } else {
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
            throw new CLIException(getResourceString("authentication-get-auth-config-entries-not-found"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (!hasData) {
            outputWriter.printlnMessage(getResourceString("authentication-get-auth-config-entries-no-values"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_GET_AUTH_CONFIG_ENTRIES", params);
    } catch (AMConfigurationException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
        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) SSOException(com.iplanet.sso.SSOException) AuthConfigurationEntry(com.sun.identity.authentication.config.AuthConfigurationEntry) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 30 with AMConfigurationException

use of com.sun.identity.authentication.config.AMConfigurationException in project OpenAM by OpenRock.

the class CreateAuthConfiguration 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 name = getStringOptionValue(AuthOptions.AUTH_CONFIG_NAME);
    String[] params = { realm, name };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_AUTH_CONFIGURATION", params);
    try {
        AMAuthConfigUtils.createNamedConfig(name, 0, new HashMap(), realm, adminSSOToken);
        getOutputWriter().printlnMessage(getResourceString("authentication-created-auth-configuration-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_AUTH_CONFIGURATION", params);
    } catch (AMConfigurationException e) {
        debugError("CreateAuthConfiguration.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AUTH_CONFIGURATION", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("CreateAuthConfiguration.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AUTH_CONFIGURATION", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("CreateAuthConfiguration.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AUTH_CONFIGURATION", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Aggregations

AMConfigurationException (com.sun.identity.authentication.config.AMConfigurationException)45 AMAuthenticationManager (com.sun.identity.authentication.config.AMAuthenticationManager)33 Set (java.util.Set)26 Iterator (java.util.Iterator)18 SSOException (com.iplanet.sso.SSOException)17 SSOToken (com.iplanet.sso.SSOToken)17 SMSException (com.sun.identity.sm.SMSException)17 HashSet (java.util.HashSet)17 AMAuthenticationInstance (com.sun.identity.authentication.config.AMAuthenticationInstance)16 CLIException (com.sun.identity.cli.CLIException)13 HashMap (java.util.HashMap)12 Map (java.util.Map)11 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AMAuthenticationSchema (com.sun.identity.authentication.config.AMAuthenticationSchema)6 AuthConfigurationEntry (com.sun.identity.authentication.config.AuthConfigurationEntry)5 IOutput (com.sun.identity.cli.IOutput)5 JsonValue (org.forgerock.json.JsonValue)3 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)3