Search in sources :

Example 1 with PreAuthenticationContext

use of com.evolveum.midpoint.model.api.context.PreAuthenticationContext in project midpoint by Evolveum.

the class RemoteModuleProvider method getPreAuthenticationToken.

protected PreAuthenticatedAuthenticationToken getPreAuthenticationToken(String enteredUsername, Class<? extends FocusType> focusType, List<ObjectReferenceType> requireAssignment, AuthenticationChannel channel) {
    ConnectionEnvironment connEnv = createEnvironment(channel);
    PreAuthenticationContext authContext = new PreAuthenticationContext(enteredUsername, focusType, requireAssignment);
    if (channel != null) {
        authContext.setSupportActivationByChannel(channel.isSupportActivationByChannel());
    }
    return getEvaluator().authenticateUserPreAuthenticated(connEnv, authContext);
}
Also used : PreAuthenticationContext(com.evolveum.midpoint.model.api.context.PreAuthenticationContext) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment)

Example 2 with PreAuthenticationContext

use of com.evolveum.midpoint.model.api.context.PreAuthenticationContext in project midpoint by Evolveum.

the class PasswordProvider method internalAuthentication.

@Override
protected Authentication internalAuthentication(Authentication authentication, List<ObjectReferenceType> requireAssignment, AuthenticationChannel channel, Class<? extends FocusType> focusType) throws AuthenticationException {
    if (authentication.isAuthenticated() && authentication.getPrincipal() instanceof GuiProfiledPrincipal) {
        return authentication;
    }
    String enteredUsername = (String) authentication.getPrincipal();
    LOGGER.trace("Authenticating username '{}'", enteredUsername);
    ConnectionEnvironment connEnv = createEnvironment(channel);
    try {
        Authentication token;
        if (authentication instanceof UsernamePasswordAuthenticationToken) {
            String enteredPassword = (String) authentication.getCredentials();
            PasswordAuthenticationContext authContext = new PasswordAuthenticationContext(enteredUsername, enteredPassword, focusType, requireAssignment);
            if (channel != null) {
                authContext.setSupportActivationByChannel(channel.isSupportActivationByChannel());
            }
            token = getEvaluator().authenticate(connEnv, authContext);
        } else if (authentication instanceof PreAuthenticatedAuthenticationToken) {
            token = getEvaluator().authenticateUserPreAuthenticated(connEnv, new PreAuthenticationContext(enteredUsername, focusType, requireAssignment));
        } 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;
    } catch (AuthenticationException e) {
        LOGGER.info("Authentication failed for {}: {}", enteredUsername, e.getMessage());
        throw e;
    }
}
Also used : PasswordAuthenticationContext(com.evolveum.midpoint.model.api.context.PasswordAuthenticationContext) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) AuthenticationException(org.springframework.security.core.AuthenticationException) Authentication(org.springframework.security.core.Authentication) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) PreAuthenticationContext(com.evolveum.midpoint.model.api.context.PreAuthenticationContext) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

PreAuthenticationContext (com.evolveum.midpoint.model.api.context.PreAuthenticationContext)2 ConnectionEnvironment (com.evolveum.midpoint.security.api.ConnectionEnvironment)2 GuiProfiledPrincipal (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)1 PasswordAuthenticationContext (com.evolveum.midpoint.model.api.context.PasswordAuthenticationContext)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1