Search in sources :

Example 1 with MailNonceAuthenticationToken

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

the class MailNonceAuthenticationFilter method attemptAuthentication.

public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
    if (!request.getMethod().equals("GET")) {
        throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    } else {
        String username = this.obtainUsername(request);
        String password = this.obtainPassword(request);
        if (username == null) {
            username = "";
        }
        if (password == null) {
            password = "";
        }
        username = username.trim();
        MailNonceAuthenticationToken authRequest = new MailNonceAuthenticationToken(username, password);
        this.setDetails(request, authRequest);
        return this.getAuthenticationManager().authenticate(authRequest);
    }
}
Also used : MailNonceAuthenticationToken(com.evolveum.midpoint.authentication.impl.module.authentication.token.MailNonceAuthenticationToken) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Example 2 with MailNonceAuthenticationToken

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

the class MailNonceProvider 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 MailNonceAuthenticationToken) {
            String nonce = (String) authentication.getCredentials();
            NonceAuthenticationContext authContext = new NonceAuthenticationContext(enteredUsername, focusType, nonce, getNoncePolicy(enteredUsername), requireAssignment);
            if (channel != null) {
                authContext.setSupportActivationByChannel(channel.isSupportActivationByChannel());
            }
            token = getEvaluator().authenticate(connEnv, authContext);
        } 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 : NonceAuthenticationContext(com.evolveum.midpoint.model.api.context.NonceAuthenticationContext) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) AuthenticationException(org.springframework.security.core.AuthenticationException) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MailNonceAuthenticationToken(com.evolveum.midpoint.authentication.impl.module.authentication.token.MailNonceAuthenticationToken) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

MailNonceAuthenticationToken (com.evolveum.midpoint.authentication.impl.module.authentication.token.MailNonceAuthenticationToken)2 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)2 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)1 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)1 GuiProfiledPrincipal (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)1 NonceAuthenticationContext (com.evolveum.midpoint.model.api.context.NonceAuthenticationContext)1 ConnectionEnvironment (com.evolveum.midpoint.security.api.ConnectionEnvironment)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 Authentication (org.springframework.security.core.Authentication)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1