Search in sources :

Example 1 with AuthenticationChannel

use of com.evolveum.midpoint.authentication.api.AuthenticationChannel in project midpoint by Evolveum.

the class AuthSequenceUtil method buildAuthChannel.

public static AuthenticationChannel buildAuthChannel(AuthChannelRegistryImpl registry, AuthenticationSequenceType sequence) {
    Validate.notNull(sequence, "Couldn't build authentication channel object, because sequence is null");
    String channelId = null;
    AuthenticationSequenceChannelType channelSequence = sequence.getChannel();
    if (channelSequence != null) {
        channelId = channelSequence.getChannelId();
    }
    AbstractChannelFactory factory = registry.findModelFactory(channelId);
    if (factory == null) {
        LOGGER.error("Couldn't find factory for {}", channelId);
        return null;
    }
    AuthenticationChannel channel = null;
    try {
        channel = factory.createAuthChannel(channelSequence);
    } catch (Exception e) {
        LOGGER.error("Couldn't create channel for {}", channelId);
    }
    return channel;
}
Also used : AuthenticationChannel(com.evolveum.midpoint.authentication.api.AuthenticationChannel) AbstractChannelFactory(com.evolveum.midpoint.authentication.impl.factory.channel.AbstractChannelFactory) ServletException(javax.servlet.ServletException) AuthenticationException(org.springframework.security.core.AuthenticationException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) IOException(java.io.IOException)

Example 2 with AuthenticationChannel

use of com.evolveum.midpoint.authentication.api.AuthenticationChannel 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)

Example 3 with AuthenticationChannel

use of com.evolveum.midpoint.authentication.api.AuthenticationChannel in project midpoint by Evolveum.

the class HttpHeaderModuleWebSecurityConfigurer method requestHeaderAuthenticationFilter.

private RequestHeaderAuthenticationFilter requestHeaderAuthenticationFilter() {
    MidpointRequestHeaderAuthenticationFilter filter = new MidpointRequestHeaderAuthenticationFilter();
    filter.setPrincipalRequestHeader(getConfiguration().getPrincipalRequestHeader());
    filter.setExceptionIfHeaderMissing(false);
    filter.setAuthenticationManager(authenticationManager);
    filter.setAuthenticationFailureHandler(new MidpointAuthenticationFailureHandler() {

        @Override
        protected String getPathAfterUnsuccessfulAuthentication(AuthenticationChannel authenticationChannel) {
            return "/error/401";
        }
    });
    MidPointAuthenticationSuccessHandler successHandler = new MidPointAuthenticationSuccessHandler() {

        @Override
        public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
            if (getRequestCache().getRequest(request, response) == null) {
                getRequestCache().saveRequest(request, response);
            }
            super.onAuthenticationSuccess(request, response, authentication);
        }
    };
    filter.setAuthenticationSuccessHandler(getObjectPostProcessor().postProcess(successHandler));
    filter.setSessionRegistry(getSessionRegistry());
    return filter;
}
Also used : MidPointAuthenticationSuccessHandler(com.evolveum.midpoint.authentication.impl.handler.MidPointAuthenticationSuccessHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationChannel(com.evolveum.midpoint.authentication.api.AuthenticationChannel) MidpointAuthenticationFailureHandler(com.evolveum.midpoint.authentication.impl.handler.MidpointAuthenticationFailureHandler) Authentication(org.springframework.security.core.Authentication) MidpointRequestHeaderAuthenticationFilter(com.evolveum.midpoint.authentication.impl.filter.MidpointRequestHeaderAuthenticationFilter) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

AuthenticationChannel (com.evolveum.midpoint.authentication.api.AuthenticationChannel)3 Authentication (org.springframework.security.core.Authentication)2 AuthModule (com.evolveum.midpoint.authentication.api.AuthModule)1 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)1 AbstractChannelFactory (com.evolveum.midpoint.authentication.impl.factory.channel.AbstractChannelFactory)1 MidpointRequestHeaderAuthenticationFilter (com.evolveum.midpoint.authentication.impl.filter.MidpointRequestHeaderAuthenticationFilter)1 MidPointAuthenticationSuccessHandler (com.evolveum.midpoint.authentication.impl.handler.MidPointAuthenticationSuccessHandler)1 MidpointAuthenticationFailureHandler (com.evolveum.midpoint.authentication.impl.handler.MidpointAuthenticationFailureHandler)1 ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 AuthenticationSequenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationSequenceType)1 AuthenticationsPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationsPolicyType)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1