Search in sources :

Example 11 with ModuleAuthenticationImpl

use of com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl in project midpoint by Evolveum.

the class MidPointAbstractAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication originalAuthentication) throws AuthenticationException {
    AuthenticationRequirements authRequirements = new AuthenticationRequirements();
    try {
        Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
        Authentication processingAuthentication = originalAuthentication;
        if (isAnonymous(originalAuthentication)) {
            // hack for specific situation when user is anonymous, but accessDecisionManager resolve it
            return originalAuthentication;
        }
        processingAuthentication = initAuthRequirements(processingAuthentication, originalAuthentication, actualAuthentication, authRequirements);
        Authentication token = internalAuthentication(processingAuthentication, authRequirements.requireAssignment, authRequirements.channel, authRequirements.focusType);
        if (actualAuthentication instanceof MidpointAuthentication) {
            MidpointAuthentication mpAuthentication = (MidpointAuthentication) actualAuthentication;
            ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) getProcessingModule(mpAuthentication);
            if (token.getPrincipal() instanceof MidPointPrincipal) {
                MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal();
                token = createNewAuthenticationToken(token, mpAuthentication.getAuthenticationChannel().resolveAuthorities(principal.getAuthorities()));
            } else {
                token = createNewAuthenticationToken(token, token.getAuthorities());
            }
            writeAuthentication(processingAuthentication, mpAuthentication, moduleAuthentication, token);
            return mpAuthentication;
        }
        return token;
    } catch (RuntimeException | Error e) {
        // Make sure to explicitly log all runtime errors here. Spring security is doing very poor job and does not log this properly.
        LOGGER.error("Authentication (runtime) error: {}", e.getMessage(), e);
        throw e;
    }
}
Also used : ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 12 with ModuleAuthenticationImpl

use of com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl in project midpoint by Evolveum.

the class RemoteModuleWebSecurityConfigurer method createAnonymousFilter.

@Override
protected AnonymousAuthenticationFilter createAnonymousFilter() {
    AnonymousAuthenticationFilter filter = new MidpointAnonymousAuthenticationFilter(authRegistry, authChannelRegistry, PrismContext.get(), UUID.randomUUID().toString(), "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS")) {

        @Override
        protected void processAuthentication(ServletRequest req) {
            if (SecurityContextHolder.getContext().getAuthentication() instanceof MidpointAuthentication) {
                MidpointAuthentication mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication();
                ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
                if (moduleAuthentication != null && (moduleAuthentication.getAuthentication() == null || getAuthTokenClass().isAssignableFrom(moduleAuthentication.getAuthentication().getClass()))) {
                    Authentication authentication = createBasicAuthentication((HttpServletRequest) req);
                    moduleAuthentication.setAuthentication(authentication);
                    mpAuthentication.setPrincipal(authentication.getPrincipal());
                }
            }
        }
    };
    filter.setAuthenticationDetailsSource(new RemoteAuthenticationDetailsSource(getAuthTokenClass()));
    return filter;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) MidpointAnonymousAuthenticationFilter(com.evolveum.midpoint.authentication.impl.filter.MidpointAnonymousAuthenticationFilter) AnonymousAuthenticationFilter(org.springframework.security.web.authentication.AnonymousAuthenticationFilter) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAnonymousAuthenticationFilter(com.evolveum.midpoint.authentication.impl.filter.MidpointAnonymousAuthenticationFilter) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 13 with ModuleAuthenticationImpl

use of com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl in project midpoint by Evolveum.

the class MidPointLdapAuthenticationProvider method getFocusType.

private Class<? extends FocusType> getFocusType() {
    Class<? extends FocusType> focusType = UserType.class;
    Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
    if (actualAuthentication instanceof MidpointAuthentication) {
        MidpointAuthentication mpAuthentication = (MidpointAuthentication) actualAuthentication;
        ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) getProcessingModule(mpAuthentication);
        if (moduleAuthentication != null && moduleAuthentication.getFocusType() != null) {
            focusType = PrismContext.get().getSchemaRegistry().determineCompileTimeClass(moduleAuthentication.getFocusType());
        }
    }
    return focusType;
}
Also used : ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) LdapModuleAuthentication(com.evolveum.midpoint.authentication.impl.module.authentication.LdapModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 14 with ModuleAuthenticationImpl

use of com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl in project midpoint by Evolveum.

the class OidcResourceServerModuleFactory method createModuleFilter.

@Override
public AuthModule createModuleFilter(AbstractAuthenticationModuleType moduleType, String sequenceSuffix, ServletRequest request, Map<Class<?>, Object> sharedObjects, AuthenticationModulesType authenticationsPolicy, CredentialsPolicyType credentialPolicy, AuthenticationChannel authenticationChannel) throws Exception {
    if (!(moduleType instanceof OidcAuthenticationModuleType)) {
        LOGGER.error("This factory support only OidcAuthenticationModuleType, but modelType is " + moduleType);
        return null;
    }
    if (((OidcAuthenticationModuleType) moduleType).getResourceServer() == null) {
        LOGGER.error("Resource configuration of OidcAuthenticationModuleType is null");
        return null;
    }
    isSupportedChannel(authenticationChannel);
    OidcResourceServerModuleWebSecurityConfiguration.setProtector(getProtector());
    OidcResourceServerModuleWebSecurityConfiguration configuration = OidcResourceServerModuleWebSecurityConfiguration.build((OidcAuthenticationModuleType) moduleType, sequenceSuffix);
    configuration.setSequenceSuffix(sequenceSuffix);
    OidcResourceServerAuthenticationModuleType resourceServer = ((OidcAuthenticationModuleType) moduleType).getResourceServer();
    JwtAuthenticationConverter jwtAuthenticationConverter = new JwtAuthenticationConverter();
    if (resourceServer.getNameOfUsernameClaim() != null) {
        jwtAuthenticationConverter.setPrincipalClaimName(resourceServer.getNameOfUsernameClaim());
    }
    configuration.addAuthenticationProvider(getObjectObjectPostProcessor().postProcess(new OidcResourceServerProvider(configuration.getDecoder(), jwtAuthenticationConverter)));
    OidcResourceServerModuleWebSecurityConfigurer<OidcResourceServerModuleWebSecurityConfiguration> module = getObjectObjectPostProcessor().postProcess(new OidcResourceServerModuleWebSecurityConfigurer<>(configuration));
    module.setObjectPostProcessor(getObjectObjectPostProcessor());
    HttpSecurity http = module.getNewHttpSecurity();
    setSharedObjects(http, sharedObjects);
    ModuleAuthenticationImpl moduleAuthentication = createEmptyModuleAuthentication(configuration, resourceServer);
    moduleAuthentication.setFocusType(moduleType.getFocusType());
    SecurityFilterChain filter = http.build();
    return AuthModuleImpl.build(filter, configuration, moduleAuthentication);
}
Also used : SecurityFilterChain(org.springframework.security.web.SecurityFilterChain) OidcResourceServerProvider(com.evolveum.midpoint.authentication.impl.provider.OidcResourceServerProvider) ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) JwtAuthenticationConverter(org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter) OidcResourceServerModuleWebSecurityConfiguration(com.evolveum.midpoint.authentication.impl.module.configuration.OidcResourceServerModuleWebSecurityConfiguration)

Example 15 with ModuleAuthenticationImpl

use of com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl in project midpoint by Evolveum.

the class MidpointAnonymousAuthenticationFilter method createAuthentication.

protected Authentication createAuthentication(HttpServletRequest request) {
    Authentication auth = createBasicAuthentication(request);
    MidpointAuthentication authentication = new MidpointAuthentication(SecurityPolicyUtil.createDefaultSequence());
    AuthenticationsPolicyType authenticationsPolicy;
    try {
        authenticationsPolicy = SecurityPolicyUtil.createDefaultAuthenticationPolicy(NO_CUSTOM_IGNORED_LOCAL_PATH, prismContext.getSchemaRegistry());
    } catch (SchemaException e) {
        LOGGER.error("Couldn't get default authentication policy");
        throw new IllegalArgumentException("Couldn't get default authentication policy", e);
    }
    AuthenticationSequenceType sequence = SecurityPolicyUtil.createDefaultSequence();
    AuthenticationChannel authenticationChannel = AuthSequenceUtil.buildAuthChannel(authChannelRegistry, sequence);
    List<AuthModule> authModules = AuthSequenceUtil.buildModuleFilters(authRegistry, sequence, request, authenticationsPolicy.getModules(), null, new HashMap<>(), authenticationChannel);
    authentication.setAuthModules(authModules);
    if (authModules != null) {
        ModuleAuthenticationImpl module = (ModuleAuthenticationImpl) authModules.get(0).getBaseModuleAuthentication();
        module.setAuthentication(auth);
        authentication.addAuthentications(module);
    }
    authentication.setPrincipal(auth.getPrincipal());
    return authentication;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) AuthenticationChannel(com.evolveum.midpoint.authentication.api.AuthenticationChannel) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) AuthenticationSequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationSequenceType) AuthModule(com.evolveum.midpoint.authentication.api.AuthModule) AuthenticationsPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationsPolicyType) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Aggregations

ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl)19 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)9 Authentication (org.springframework.security.core.Authentication)8 HttpSecurity (org.springframework.security.config.annotation.web.builders.HttpSecurity)7 SecurityFilterChain (org.springframework.security.web.SecurityFilterChain)7 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)2 LdapModuleAuthentication (com.evolveum.midpoint.authentication.impl.module.authentication.LdapModuleAuthentication)2 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)2 AuthModule (com.evolveum.midpoint.authentication.api.AuthModule)1 AuthenticationChannel (com.evolveum.midpoint.authentication.api.AuthenticationChannel)1 ModuleWebSecurityConfiguration (com.evolveum.midpoint.authentication.api.ModuleWebSecurityConfiguration)1 MidpointAnonymousAuthenticationFilter (com.evolveum.midpoint.authentication.impl.filter.MidpointAnonymousAuthenticationFilter)1 LdapDirContextAdapter (com.evolveum.midpoint.authentication.impl.ldap.LdapDirContextAdapter)1 CredentialModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.CredentialModuleAuthenticationImpl)1 OidcClientModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.OidcClientModuleAuthenticationImpl)1 RemoteModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.RemoteModuleAuthenticationImpl)1 Saml2ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl)1 HttpHeaderModuleWebSecurityConfiguration (com.evolveum.midpoint.authentication.impl.module.configuration.HttpHeaderModuleWebSecurityConfiguration)1 LdapModuleWebSecurityConfiguration (com.evolveum.midpoint.authentication.impl.module.configuration.LdapModuleWebSecurityConfiguration)1 OidcClientModuleWebSecurityConfiguration (com.evolveum.midpoint.authentication.impl.module.configuration.OidcClientModuleWebSecurityConfiguration)1