Search in sources :

Example 21 with AMAuthenticationManager

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

the class AuthenticationModuleTypeHandler method handleQuery.

/**
     * Returns the list of configured authentication module instances for the current realm.
     *
     * {@inheritDoc}
     */
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
    if (!"true".equals(request.getQueryFilter().toString())) {
        return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
    }
    if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
        return new NotSupportedException("Query paging not currently supported").asPromise();
    }
    try {
        SSOToken ssoToken = context.asContext(SSOTokenContext.class).getCallerSSOToken();
        String realm = context.asContext(RealmContext.class).getResolvedRealm();
        AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realm);
        Set<String> authenticationServiceNames = AMAuthenticationManager.getAuthenticationServiceNames();
        for (String serviceName : authenticationServiceNames) {
            ServiceSchemaManager schemaManager = new ServiceSchemaManager(serviceName, adminToken);
            String resourceId = schemaManager.getResourceName();
            String typeI18N = getI18NValue(schemaManager, resourceId, debug);
            JsonValue result = json(object(field(ResourceResponse.FIELD_CONTENT_ID, resourceId), field("name", typeI18N)));
            handler.handleResource(newResourceResponse(resourceId, String.valueOf(result.hashCode()), result));
        }
        return newResultPromise(newQueryResponse());
    } catch (AMConfigurationException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: AMConfigurationException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) RealmContext(org.forgerock.openam.rest.RealmContext) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) SSOException(com.iplanet.sso.SSOException) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 22 with AMAuthenticationManager

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

the class AuthenticationModuleCollectionHandler method handleQuery.

/**
     * Returns the list of configured authentication module instances for the current realm.
     *
     * {@inheritDoc}
     */
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
    String searchForId;
    try {
        searchForId = request.getQueryFilter().accept(new AuthenticationModuleQueryFilterVisitor(), null);
    } catch (UnsupportedOperationException e) {
        return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
    }
    if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
        return new NotSupportedException("Query paging not currently supported").asPromise();
    }
    try {
        SSOToken ssoToken = context.asContext(SSOTokenContext.class).getCallerSSOToken();
        String realm = context.asContext(RealmContext.class).getResolvedRealm();
        AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realm);
        Set<AMAuthenticationInstance> moduleInstances = mgr.getAuthenticationInstances();
        List<ResourceResponse> resourceResponses = new ArrayList<>();
        for (AMAuthenticationInstance instance : moduleInstances) {
            String name = instance.getName();
            if (searchForId == null || searchForId.equalsIgnoreCase(name)) {
                try {
                    ServiceSchemaManager schemaManager = getSchemaManager(instance.getType());
                    String type = schemaManager.getResourceName();
                    String typeDescription = getI18NValue(schemaManager, instance.getType(), debug);
                    JsonValue result = json(object(field(ResourceResponse.FIELD_CONTENT_ID, name), field("typeDescription", typeDescription), field("type", type)));
                    resourceResponses.add(newResourceResponse(name, String.valueOf(result.hashCode()), result));
                } catch (AMConfigurationException ex) {
                    debug.error("AuthenticationModuleCollectionHandler.handleQuery(): Invalid auth module " + "instance configuration: {}", name);
                    if (debug.messageEnabled()) {
                        debug.message("AuthenticationModuleCollectionHandler.handleQuery(): Configuration exception: {}", name, ex);
                    }
                }
            }
        }
        return QueryResponsePresentation.perform(handler, request, resourceResponses);
    } catch (AMConfigurationException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: AMConfigurationException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) RealmContext(org.forgerock.openam.rest.RealmContext) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) SSOException(com.iplanet.sso.SSOException) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) NotSupportedException(org.forgerock.json.resource.NotSupportedException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 23 with AMAuthenticationManager

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

the class AllConfiguredModuleInstances method getChoiceValues.

/**
     * Returns the map of choice values for given environment params.
     * @param envParams to get the map of choice values
     * @return the map of choice values for given environment params.
     */
public Map getChoiceValues(Map envParams) {
    String orgDN = null;
    if (envParams != null) {
        orgDN = (String) envParams.get(Constants.ORGANIZATION_NAME);
    }
    if (orgDN == null || orgDN.length() == 0) {
        orgDN = SMSEntry.getRootSuffix();
    }
    Map<String, String> answer = new HashMap<String, String>();
    try {
        SSOToken adminToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
        AMAuthenticationManager amAM = new AMAuthenticationManager(adminToken, orgDN);
        Set<String> instanceNames = amAM.getAllowedModuleNames();
        for (String config : instanceNames) {
            answer.put(config, config);
        }
    } catch (Exception e) {
    // do nothing as instanceNames will be empty.
    }
    return answer;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 24 with AMAuthenticationManager

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

the class ConfigMonitoring method getRealmAuthMods.

HashMap getRealmAuthMods(String realmName) {
    String classMethod = "ConfigMonitoring.getRealmAuthMods: ";
    HashMap aMods = new HashMap();
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realmName);
        Set insts = mgr.getAuthenticationInstances();
        for (Iterator it = insts.iterator(); it.hasNext(); ) {
            AMAuthenticationInstance ai = (AMAuthenticationInstance) it.next();
            String stname = ai.getName();
            String sttype = ai.getType();
            aMods.put(stname, sttype);
        }
        /*
             *  all get an "Application" instance/type by default
             */
        aMods.put("Application", "Application");
    } catch (AMConfigurationException e) {
        debug.error(classMethod + "getting auth instances; " + e.getMessage());
    }
    return aMods;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 25 with AMAuthenticationManager

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

the class UpgradeLDAPAuthModulesStep method updateAttributes.

private void updateAttributes(final String realm, final Map<String, Boolean> instanceMap) throws SMSException, AMConfigurationException, SSOException {
    final AMAuthenticationManager mgr = new AMAuthenticationManager(getAdminToken(), realm);
    for (final Map.Entry<String, Boolean> instance : instanceMap.entrySet()) {
        final String instanceName = instance.getKey();
        final String newValue = getNewValue(instance.getValue());
        final AMAuthenticationInstance authModuleInstance = mgr.getAuthenticationInstance(instanceName);
        final Map<String, Set<String>> moduleSettings = authModuleInstance.getAttributeValues();
        final ServiceConfig moduleConfig = authModuleInstance.getServiceConfig();
        Set<String> attributeValues = moduleSettings.get(SSL_ENABLED_PROPERTY);
        if (attributeValues != null && !attributeValues.isEmpty()) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("Removing attribute " + SSL_ENABLED_PROPERTY + " from ldap/ad auth module instance <" + instanceName + "> in realm: " + realm);
            }
            moduleConfig.removeAttribute(SSL_ENABLED_PROPERTY);
        }
        attributeValues = moduleSettings.get(CONNECTION_MODE_PROPERTY);
        if (attributeValues != null && !attributeValues.isEmpty()) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("Upgrading attribute " + CONNECTION_MODE_PROPERTY + " for ldap/ad auth module instance <" + instanceName + "> to <" + newValue + "> in realm: " + realm);
            }
            final Map<String, Set<String>> newConnectionModeValues = new HashMap<String, Set<String>>();
            newConnectionModeValues.put(CONNECTION_MODE_PROPERTY, asSet(newValue));
            moduleConfig.setAttributes(newConnectionModeValues);
        }
    }
}
Also used : Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) HashMap(java.util.HashMap) Map(java.util.Map) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Aggregations

AMAuthenticationManager (com.sun.identity.authentication.config.AMAuthenticationManager)43 AMConfigurationException (com.sun.identity.authentication.config.AMConfigurationException)35 Set (java.util.Set)28 AMAuthenticationInstance (com.sun.identity.authentication.config.AMAuthenticationInstance)22 HashSet (java.util.HashSet)18 Iterator (java.util.Iterator)16 SSOToken (com.iplanet.sso.SSOToken)15 SSOException (com.iplanet.sso.SSOException)10 HashMap (java.util.HashMap)10 SMSException (com.sun.identity.sm.SMSException)9 Map (java.util.Map)8 AMAuthenticationSchema (com.sun.identity.authentication.config.AMAuthenticationSchema)7 CLIException (com.sun.identity.cli.CLIException)7 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)7 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)3 ServiceConfig (com.sun.identity.sm.ServiceConfig)3 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)3 AMException (com.iplanet.am.sdk.AMException)2 SessionException (com.iplanet.dpro.session.SessionException)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)2