Search in sources :

Example 1 with SamlAdditionalConfiguration

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

the class Saml2ModuleFactory method createEmptyModuleAuthentication.

public ModuleAuthenticationImpl createEmptyModuleAuthentication(SamlModuleWebSecurityConfiguration configuration, ServletRequest request) {
    Saml2ModuleAuthenticationImpl moduleAuthentication = new Saml2ModuleAuthenticationImpl();
    List<IdentityProvider> providers = new ArrayList<>();
    configuration.getRelyingPartyRegistrationRepository().forEach(p -> {
        String authRequestPrefixUrl = request.getServletContext().getContextPath() + configuration.getPrefixOfModule() + RemoteModuleAuthenticationImpl.AUTHENTICATION_REQUEST_PROCESSING_URL_SUFFIX_WITH_REG_ID;
        SamlAdditionalConfiguration config = configuration.getAdditionalConfiguration().get(p.getRegistrationId());
        IdentityProvider mp = new IdentityProvider().setLinkText(config.getLinkText()).setRedirectLink(authRequestPrefixUrl.replace("{registrationId}", p.getRegistrationId()));
        providers.add(mp);
    });
    moduleAuthentication.setProviders(providers);
    moduleAuthentication.setAdditionalConfiguration(configuration.getAdditionalConfiguration());
    moduleAuthentication.setNameOfModule(configuration.getNameOfModule());
    moduleAuthentication.setPrefix(configuration.getPrefixOfModule());
    return moduleAuthentication;
}
Also used : SamlAdditionalConfiguration(com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration) ArrayList(java.util.ArrayList) Saml2ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl) IdentityProvider(com.evolveum.midpoint.authentication.api.IdentityProvider)

Example 2 with SamlAdditionalConfiguration

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

the class Saml2Provider method internalAuthentication.

@Override
protected Authentication internalAuthentication(Authentication authentication, List requireAssignment, AuthenticationChannel channel, Class focusType) throws AuthenticationException {
    Authentication token;
    if (authentication instanceof Saml2AuthenticationToken) {
        Saml2AuthenticationToken samlAuthenticationToken = (Saml2AuthenticationToken) authentication;
        Saml2Authentication samlAuthentication;
        try {
            samlAuthentication = (Saml2Authentication) openSamlProvider.authenticate(samlAuthenticationToken);
        } catch (AuthenticationException e) {
            getAuditProvider().auditLoginFailure(null, null, createConnectEnvironment(getChannel()), e.getMessage());
            throw e;
        }
        Saml2ModuleAuthenticationImpl samlModule = (Saml2ModuleAuthenticationImpl) AuthUtil.getProcessingModule();
        try {
            DefaultSaml2AuthenticatedPrincipal principal = (DefaultSaml2AuthenticatedPrincipal) samlAuthentication.getPrincipal();
            samlAuthenticationToken.setDetails(principal);
            Map<String, List<Object>> attributes = principal.getAttributes();
            String enteredUsername;
            SamlAdditionalConfiguration config = samlModule.getAdditionalConfiguration().get(samlAuthenticationToken.getRelyingPartyRegistration().getRegistrationId());
            String nameOfSamlAttribute = config.getNameOfUsernameAttribute();
            enteredUsername = defineEnteredUsername(attributes, nameOfSamlAttribute);
            token = getPreAuthenticationToken(enteredUsername, focusType, requireAssignment, channel);
        } catch (AuthenticationException e) {
            samlModule.setAuthentication(samlAuthenticationToken);
            LOGGER.info("Authentication with saml module failed: {}", e.getMessage());
            throw e;
        }
    } else {
        LOGGER.error("Unsupported authentication {}", authentication);
        throw new AuthenticationServiceException("web.security.provider.unavailable");
    }
    MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal();
    LOGGER.debug("User '{}' authenticated ({}), authorities: {}", authentication.getPrincipal(), authentication.getClass().getSimpleName(), principal.getAuthorities());
    return token;
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) Saml2Authentication(org.springframework.security.saml2.provider.service.authentication.Saml2Authentication) Authentication(org.springframework.security.core.Authentication) Saml2Authentication(org.springframework.security.saml2.provider.service.authentication.Saml2Authentication) SamlAdditionalConfiguration(com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration) DefaultSaml2AuthenticatedPrincipal(org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal) Saml2ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl) List(java.util.List) Saml2AuthenticationToken(org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

Saml2ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl)2 SamlAdditionalConfiguration (com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration)2 IdentityProvider (com.evolveum.midpoint.authentication.api.IdentityProvider)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1 Authentication (org.springframework.security.core.Authentication)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 DefaultSaml2AuthenticatedPrincipal (org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal)1 Saml2Authentication (org.springframework.security.saml2.provider.service.authentication.Saml2Authentication)1 Saml2AuthenticationToken (org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken)1