Search in sources :

Example 21 with AMConfigurationException

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

the class AuthPropertiesModelImpl method getAuthInstances.

public Set getAuthInstances() {
    Set instances = null;
    if (currentRealm != null) {
        String[] param = { currentRealm };
        logEvent("ATTEMPT_GET_AUTH_INSTANCE", param);
        try {
            AMAuthenticationManager mgr = new AMAuthenticationManager(getUserSSOToken(), currentRealm);
            instances = mgr.getAuthenticationInstances();
            logEvent("SUCCEED_GET_AUTH_INSTANCE", param);
        } catch (AMConfigurationException e) {
            String strError = getErrorString(e);
            String[] paramsEx = { currentRealm, strError };
            logEvent("AUTH_CONFIG_EXCEPTION_GET_AUTH_INSTANCE", paramsEx);
            debug.warning("AuthPropertiesModelImpl.getAuthInstances", e);
        }
    }
    return (instances == null) ? Collections.EMPTY_SET : instances;
}
Also used : Set(java.util.Set) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 22 with AMConfigurationException

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

the class AuthConfigurationModelImpl method initialize.

/**
     * Initialize configuration entry information for the given realm
     * and named configuration.
     *
     * @param realm name where configuration is locate.
     * @param config name of entry.
     */
public void initialize(String realm, String config) {
    verifyConfigurationService(realm);
    try {
        if (configData == null) {
            String[] params = { realm, config };
            logEvent("ATTEMPT_GET_AUTH_CONFIG_PROFILE", params);
            configData = AMAuthConfigUtils.getNamedConfig(config, realm, getUserSSOToken());
            logEvent("SUCCEED_GET_AUTH_CONFIG_PROFILE", params);
        }
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, config, strError };
        logEvent("SSO_EXCEPTION_GET_AUTH_CONFIG_PROFILE", paramsEx);
        debug.warning("AuthConfigurationModelImpl.initialize", e);
        configData = Collections.EMPTY_MAP;
    } catch (AMConfigurationException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, config, strError };
        logEvent("AUTH_CONFIGURATION_EXCEPTION_GET_AUTH_CONFIG_PROFILE", paramsEx);
        debug.error("AuthConfigurationModelImpl.initialize", e);
        configData = Collections.EMPTY_MAP;
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, config, strError };
        logEvent("SMS_EXCEPTION_GET_AUTH_CONFIG_PROFILE", paramsEx);
        debug.error("AuthConfigurationModelImpl.initialize", e);
        configData = Collections.EMPTY_MAP;
    }
    if ((configData != null) && !configData.isEmpty() && (xmlValue == null)) {
        Set tmp = (Set) configData.get(AUTH_CONFIG_ATTR);
        if ((tmp != null) && (!tmp.isEmpty())) {
            xmlValue = (String) tmp.iterator().next();
            entryList = new ArrayList(AMAuthConfigUtils.xmlToAuthConfigurationEntry(xmlValue));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) SSOException(com.iplanet.sso.SSOException)

Example 23 with AMConfigurationException

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

the class AuthConfigurationModelImpl method deleteAuthConfiguration.

/**
     * Deletes the named authentication configuration object.
     *  
     * @param realm name where configuration is locate.
     * @param names names of entries.
     */
public void deleteAuthConfiguration(String realm, Set names) throws AMConsoleException {
    StringBuilder errorList = new StringBuilder();
    String message = null;
    for (Iterator i = names.iterator(); i.hasNext(); ) {
        String config = (String) i.next();
        message = null;
        try {
            AMAuthConfigUtils.removeNamedConfig(config, realm, getUserSSOToken());
        } catch (AMConfigurationException e) {
            debug.warning("failed to delete", e);
            message = e.getMessage();
            errorList.append(config);
        } catch (SMSException e) {
            debug.warning("failed to delete", e);
            message = e.getMessage();
            errorList.append(config);
        } catch (SSOException e) {
            debug.warning("failed to delete", e);
            message = e.getMessage();
            errorList.append(config);
        }
        if (message != null) {
            if (errorList.length() > 0) {
                errorList.append(", ");
            }
        }
    }
    if (errorList.length() > 0) {
        String[] tmp = { errorList.toString(), message };
        throw new AMConsoleException(MessageFormat.format(getLocalizedString("authentication.config.delete.failed"), (Object[]) tmp));
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 24 with AMConfigurationException

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

the class UpdateAuthConfigurationEntries 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 datafile = getStringOptionValue(IArgument.DATA_FILE);
    List listEntries = rc.getOption(AuthOptions.AUTH_CONFIG_ENTRIES);
    if ((datafile == null) && (listEntries == null)) {
        throw new CLIException(getResourceString("authentication-set-auth-config-entries-missing-data"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    String[] params = { realm, configName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_AUTH_CONFIG_ENTRIES", params);
    try {
        List entries = parse(datafile, listEntries);
        validateEntries(realm, adminSSOToken, entries, params);
        Map configData = new HashMap(2);
        Set tmp = new HashSet(2);
        String xml = AMAuthConfigUtils.authConfigurationEntryToXMLString(entries);
        tmp.add(xml);
        configData.put(AuthOptions.AUTH_CONFIG_ATTR, tmp);
        IOutput outputWriter = getOutputWriter();
        AMAuthConfigUtils.replaceNamedConfig(configName, 0, configData, realm, adminSSOToken);
        outputWriter.printlnMessage(getResourceString("authentication-set-auth-config-entries-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SET_AUTH_CONFIG_ENTRIES", params);
    } catch (AMConfigurationException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_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_SET_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_SET_AUTH_CONFIG_ENTRIES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 25 with AMConfigurationException

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

the class UpdateAuthConfigurationEntries method getInstanceNames.

private Set getInstanceNames(String realm, SSOToken adminSSOToken, String[] params) throws CLIException {
    Set names = new HashSet();
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        Set instances = mgr.getAuthenticationInstances();
        for (Iterator i = instances.iterator(); i.hasNext(); ) {
            AMAuthenticationInstance instance = (AMAuthenticationInstance) i.next();
            names.add(instance.getName());
        }
    } catch (AMConfigurationException e) {
        debugError("ListAuthInstances.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_AUTH_CONFIG_ENTRIES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    return names;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) CLIException(com.sun.identity.cli.CLIException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) HashSet(java.util.HashSet) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

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