Search in sources :

Example 1 with AMConfigurationException

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

the class PolicyModelImpl method getAuthenticationInstances.

/**
     * Returns set of authentication instances.
     *
     * @param realmName Name of Realm.
     * @return set of authentication instances.
     * @throws AMConsoleException if authentication instances cannot be
     *         obtained.
     */
public Set getAuthenticationInstances(String realmName) throws AMConsoleException {
    Set names = Collections.EMPTY_SET;
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(getUserSSOToken(), realmName);
        Set instances = mgr.getAuthenticationInstances();
        if ((instances != null) && !instances.isEmpty()) {
            names = new HashSet(instances.size());
            for (Iterator i = instances.iterator(); i.hasNext(); ) {
                names.add(((AMAuthenticationInstance) i.next()).getName());
            }
        }
    } catch (AMConfigurationException e) {
        throw new AMConsoleException(getErrorString(e));
    }
    return names;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager) HashSet(java.util.HashSet)

Example 2 with AMConfigurationException

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

the class AuthPropertiesModelImpl method hasAuthAttributes.

/**
     * Returns true if there are attributes for a authentication type.
     *
     * @param type Authtentication type.
     * @return true if there are attributes for a authentication type.
     */
public boolean hasAuthAttributes(String type) {
    boolean has = false;
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(getUserSSOToken(), currentRealm);
        AMAuthenticationSchema schema = mgr.getAuthenticationSchema(type);
        has = !schema.getAttributeSchemas().isEmpty();
    } catch (AMConfigurationException e) {
        debug.warning("AuthPropertiesModelImpl.hasAuthAttributes", e);
    }
    return has;
}
Also used : AMAuthenticationSchema(com.sun.identity.authentication.config.AMAuthenticationSchema) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 3 with AMConfigurationException

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

the class AuthPropertiesModelImpl method getServiceName.

/**
     * To get the service name from the instance name:
     *   1) get a handle to the AMAuthenicationInstance object
     *   2) from the AuthInstance object get the type of instance
     *   3) Use the instance type to get the schema for that type
     *   4) from the schema get the service name
     */
public String getServiceName(String instance) {
    String name = null;
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(getUserSSOToken(), currentRealm);
        AMAuthenticationInstance inst = mgr.getAuthenticationInstance(instance);
        if (inst != null) {
            AMAuthenticationSchema schema = mgr.getAuthenticationSchema(inst.getType());
            name = schema.getServiceName();
        } else {
            if (debug.warningEnabled()) {
                debug.warning("AuthPropertiesModel.getServiceName, " + " the requested instance " + instance + " does not exist.");
            }
        }
    } catch (AMConfigurationException ace) {
        if (debug.warningEnabled()) {
            debug.warning("problem getting service name for " + instance, ace);
        }
    }
    return name;
}
Also used : AMAuthenticationSchema(com.sun.identity.authentication.config.AMAuthenticationSchema) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 4 with AMConfigurationException

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

the class AddAuthConfigurationEntry 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 moduleName = getStringOptionValue(AuthOptions.AUTH_CONFIG_MODULE_NAME);
    String criteria = getStringOptionValue(AuthOptions.AUTH_CONFIG_CRITERIA);
    String options = getStringOptionValue(AuthOptions.AUTH_CONFIG_OPTIONS);
    String[] params = { realm, configName, moduleName };
    if (!POSSIBLE_CRITERIA.contains(criteria)) {
        throw new CLIException(getResourceString("authentication-add-auth-config-entry-criteria.invalid"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    int pos = getPosition();
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_AUTH_CONFIG_ENTRY", params);
    try {
        AuthConfigurationEntry ae = new AuthConfigurationEntry(moduleName, criteria, options);
        Set instanceNames = getInstanceNames(realm, adminSSOToken);
        String instanceName = ae.getLoginModuleName();
        if (!instanceNames.contains(instanceName)) {
            Object[] p = { instanceName };
            throw new CLIException(MessageFormat.format(getResourceString("authentication-add-auth-config-entry-not-found"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        List entries = getConfigEntries(realm, configName, adminSSOToken);
        if (entries == null) {
            entries = new ArrayList();
        }
        if ((pos == -1) || (pos >= entries.size())) {
            entries.add(ae);
        } else {
            entries.add(pos, ae);
        }
        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-add-auth-config-entry-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_ADD_AUTH_CONFIG_ENTRY", params);
    } catch (AMConfigurationException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        String[] p = { realm, configName, moduleName, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        String[] p = { realm, configName, moduleName, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        String[] p = { realm, configName, moduleName, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) 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) 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 5 with AMConfigurationException

use of com.sun.identity.authentication.config.AMConfigurationException 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)

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