Search in sources :

Example 1 with AMAuthenticationInstance

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

the class ScriptedAuthModulesStep method captureScriptedModuleData.

private void captureScriptedModuleData(String realm) throws AMConfigurationException, ScriptException {
    Set<ScriptData> scriptDataSet = new HashSet<>();
    AMAuthenticationManager authManager = new AMAuthenticationManager(getAdminToken(), realm);
    Set<AMAuthenticationInstance> instances = authManager.getAuthenticationInstances();
    for (AMAuthenticationInstance instance : instances) {
        String moduleType = instance.getType();
        if ("Scripted".equalsIgnoreCase(moduleType) || "DeviceIdMatch".equalsIgnoreCase(moduleType)) {
            DEBUG.message("Found Scripted Module called {}, in realm {}", instance.getName(), realm);
            @SuppressWarnings("unchecked") Map<String, Set<String>> attributes = instance.getAttributeValues();
            if (attributes.containsKey(SCRIPT_TYPE)) {
                scriptDataSet.add(getScriptData(instance.getName(), attributes));
                moduleCount++;
            }
        }
    }
    if (!scriptDataSet.isEmpty()) {
        scriptsToMove.put(realm, scriptDataSet);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) HashSet(java.util.HashSet) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 2 with AMAuthenticationInstance

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

the class ScriptedAuthModulesStep method upgradeScriptedAuthModules.

private void upgradeScriptedAuthModules(String realm, Set<ScriptData> scriptDataSet) throws AMConfigurationException, ScriptException, SSOException, SMSException {
    ScriptingService service = serviceFactory.create(getAdminSubject(), realm);
    AMAuthenticationManager authManager = new AMAuthenticationManager(getAdminToken(), realm);
    for (ScriptData scriptData : scriptDataSet) {
        Map<String, Set<String>> attributes = new HashMap<>();
        UpgradeProgress.reportStart("upgrade.scripted.auth.server.script.start", scriptData.serverSideScript.getName(), realm);
        service.create(scriptData.serverSideScript);
        attributes.put(SERVER_SCRIPT, Collections.singleton(scriptData.serverSideScript.getId()));
        UpgradeProgress.reportEnd("upgrade.success");
        if (scriptData.clientSideScript != null) {
            UpgradeProgress.reportStart("upgrade.scripted.auth.client.script.start", scriptData.clientSideScript.getName(), realm);
            service.create(scriptData.clientSideScript);
            attributes.put(CLIENT_SCRIPT, Collections.singleton(scriptData.clientSideScript.getId()));
            UpgradeProgress.reportEnd("upgrade.success");
        } else {
            attributes.put(CLIENT_SCRIPT, Collections.singleton(EMPTY_SCRIPT_SELECTION));
        }
        UpgradeProgress.reportStart("upgrade.scripted.auth.module.script.start", scriptData.moduleName, realm);
        AMAuthenticationInstance instance = authManager.getAuthenticationInstance(scriptData.moduleName);
        if (instance != null) {
            instance.setAttributeValues(attributes);
            UpgradeProgress.reportEnd("upgrade.success");
        } else {
            DEBUG.error("Scripted module {} in realm {} could not be found", scriptData.moduleName, realm);
            UpgradeProgress.reportEnd("upgrade.failed");
        }
    }
}
Also used : ScriptingService(org.forgerock.openam.scripting.service.ScriptingService) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 3 with AMAuthenticationInstance

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

the class UpgradeLDAPAuthModulesStep method initialize.

@Override
public void initialize() throws UpgradeException {
    String realmName = null;
    String authInstanceName = null;
    try {
        for (final String realm : getRealmNames()) {
            realmName = realm;
            final AMAuthenticationManager mgr = new AMAuthenticationManager(getAdminToken(), realm);
            final Set<AMAuthenticationInstance> moduleInstances = mgr.getAuthenticationInstances();
            if (moduleInstances != null) {
                for (final AMAuthenticationInstance moduleInstance : moduleInstances) {
                    if (moduleInstance.getType().equalsIgnoreCase("LDAP") || moduleInstance.getType().equalsIgnoreCase("AD")) {
                        authInstanceName = moduleInstance.getName();
                        if (DEBUG.messageEnabled()) {
                            DEBUG.message("ldap/ad auth module configuration found under realm: " + realm + " : " + authInstanceName);
                        }
                        final Map<String, Set<String>> configProperties = moduleInstance.getAttributeValues(asSet(SSL_ENABLED_PROPERTY));
                        if (configProperties != null && !configProperties.isEmpty()) {
                            final String sslEnabledProp = CollectionHelper.getMapAttr(configProperties, SSL_ENABLED_PROPERTY);
                            if (sslEnabledProp != null) {
                                if (DEBUG.messageEnabled()) {
                                    DEBUG.message("ldap/ad auth module config " + authInstanceName + " in realm: " + realm + " " + SSL_ENABLED_PROPERTY + ":" + sslEnabledProp);
                                }
                                Map<String, Boolean> instanceMap = instances.get(realm);
                                if (instanceMap == null) {
                                    instanceMap = new HashMap<String, Boolean>();
                                    instances.put(realm, instanceMap);
                                }
                                instanceMap.put(authInstanceName, Boolean.parseBoolean(sslEnabledProp));
                            }
                        }
                    }
                }
            }
        }
    } catch (final Exception ex) {
        DEBUG.error("Unable to identify the configuration for the old ldap/ad auth module instance " + authInstanceName + " in realm " + realmName, ex);
        throw new UpgradeException("An error occurred while trying to identify the configuration for the old " + "ldap/ad auth module instance " + authInstanceName + " in realm " + realmName, ex);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) SMSException(com.sun.identity.sm.SMSException) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SSOException(com.iplanet.sso.SSOException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 4 with AMAuthenticationInstance

use of com.sun.identity.authentication.config.AMAuthenticationInstance 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 5 with AMAuthenticationInstance

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

AMAuthenticationInstance (com.sun.identity.authentication.config.AMAuthenticationInstance)25 AMAuthenticationManager (com.sun.identity.authentication.config.AMAuthenticationManager)22 Set (java.util.Set)18 AMConfigurationException (com.sun.identity.authentication.config.AMConfigurationException)17 HashSet (java.util.HashSet)14 Iterator (java.util.Iterator)12 SSOException (com.iplanet.sso.SSOException)9 SSOToken (com.iplanet.sso.SSOToken)8 HashMap (java.util.HashMap)8 SMSException (com.sun.identity.sm.SMSException)6 Map (java.util.Map)6 CLIException (com.sun.identity.cli.CLIException)4 AMIdentity (com.sun.identity.idm.AMIdentity)3 IdRepoException (com.sun.identity.idm.IdRepoException)3 AMAuthenticationSchema (com.sun.identity.authentication.config.AMAuthenticationSchema)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)2 InvalidPasswordException (com.sun.identity.authentication.spi.InvalidPasswordException)2 AuthPropertiesModel (com.sun.identity.console.authentication.model.AuthPropertiesModel)2 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)2 LoginException (javax.security.auth.login.LoginException)2