Search in sources :

Example 6 with ModuleAuthentication

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

the class MidpointRequestHeaderAuthenticationFilter method requiresAuthentication.

private boolean requiresAuthentication() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication instanceof MidpointAuthentication) {
        MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
        ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
        if (moduleAuthentication != null && moduleAuthentication.getAuthentication() == null) {
            return true;
        }
    }
    return false;
}
Also used : ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) 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)

Example 7 with ModuleAuthentication

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

the class OidcClientModuleAuthenticationImpl method clone.

@Override
public ModuleAuthenticationImpl clone() {
    OidcClientModuleAuthenticationImpl module = new OidcClientModuleAuthenticationImpl();
    module.setClientsRepository(this.getClientsRepository());
    module.setProviders(this.getProviders());
    Authentication actualAuth = SecurityContextHolder.getContext().getAuthentication();
    Authentication newAuthentication = this.getAuthentication();
    if (actualAuth instanceof MidpointAuthentication && ((MidpointAuthentication) actualAuth).getAuthentications() != null && !((MidpointAuthentication) actualAuth).getAuthentications().isEmpty()) {
        ModuleAuthentication actualModule = ((MidpointAuthentication) actualAuth).getAuthentications().get(0);
        if (actualModule instanceof OidcClientModuleAuthenticationImpl && actualModule.getAuthentication() instanceof OAuth2LoginAuthenticationToken) {
            newAuthentication = actualModule.getAuthentication();
        }
    }
    module.setAuthentication(newAuthentication);
    super.clone(module);
    return module;
}
Also used : RemoteModuleAuthentication(com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) RemoteModuleAuthentication(com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) OAuth2LoginAuthenticationToken(org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken)

Example 8 with ModuleAuthentication

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

the class OidcClientLogoutSuccessHandler method determineTargetUrl.

protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    String targetUrl = null;
    if (authentication instanceof MidpointAuthentication) {
        MidpointAuthentication mPAuthentication = (MidpointAuthentication) authentication;
        ModuleAuthentication moduleAuthentication = mPAuthentication.getProcessingModuleAuthentication();
        if (moduleAuthentication instanceof OidcClientModuleAuthenticationImpl) {
            Authentication internalAuthentication = moduleAuthentication.getAuthentication();
            if (internalAuthentication instanceof PreAuthenticatedAuthenticationToken || internalAuthentication instanceof AnonymousAuthenticationToken) {
                Object details = internalAuthentication.getDetails();
                if (details instanceof OAuth2LoginAuthenticationToken && ((OAuth2LoginAuthenticationToken) details).getDetails() instanceof OidcUser) {
                    OAuth2LoginAuthenticationToken oidcAuthentication = (OAuth2LoginAuthenticationToken) details;
                    String registrationId = oidcAuthentication.getClientRegistration().getRegistrationId();
                    ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(registrationId);
                    URI endSessionEndpoint = this.endSessionEndpoint(clientRegistration);
                    if (endSessionEndpoint != null) {
                        String idToken = this.idToken(oidcAuthentication);
                        String postLogoutRedirectUri = this.postLogoutRedirectUri(request);
                        targetUrl = this.endpointUri(endSessionEndpoint, idToken, postLogoutRedirectUri);
                    }
                }
            }
        }
    }
    return targetUrl != null ? targetUrl : super.determineTargetUrl(request, response);
}
Also used : ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) OidcClientModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.OidcClientModuleAuthenticationImpl) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) URI(java.net.URI) OAuth2LoginAuthenticationToken(org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken) OidcUser(org.springframework.security.oauth2.core.oidc.user.OidcUser)

Example 9 with ModuleAuthentication

use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication 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 10 with ModuleAuthentication

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

the class MidPointAbstractAuthenticationProvider method isAnonymous.

private boolean isAnonymous(Authentication originalAuthentication) {
    if (originalAuthentication instanceof MidpointAuthentication) {
        MidpointAuthentication mpAuthentication = (MidpointAuthentication) originalAuthentication;
        ModuleAuthentication moduleAuthentication = getProcessingModule(mpAuthentication);
        return moduleAuthentication.getAuthentication() instanceof AnonymousAuthenticationToken;
    }
    return false;
}
Also used : ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Aggregations

ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)32 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)29 Authentication (org.springframework.security.core.Authentication)21 HttpModuleAuthentication (com.evolveum.midpoint.authentication.impl.module.authentication.HttpModuleAuthentication)6 RemoteModuleAuthentication (com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication)5 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)4 IdentityProvider (com.evolveum.midpoint.authentication.api.IdentityProvider)3 CredentialModuleAuthentication (com.evolveum.midpoint.authentication.api.config.CredentialModuleAuthentication)2 MailNonceModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.MailNonceModuleAuthenticationImpl)2 ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl)2 ArrayList (java.util.ArrayList)2 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)2 OAuth2LoginAuthenticationToken (org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken)2 Saml2AuthenticationToken (org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken)2 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)2 AuthenticationModuleState (com.evolveum.midpoint.authentication.api.AuthenticationModuleState)1 MidpointAnonymousAuthenticationFilter (com.evolveum.midpoint.authentication.impl.filter.MidpointAnonymousAuthenticationFilter)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