Search in sources :

Example 6 with AuthenticationServiceException

use of org.springframework.security.authentication.AuthenticationServiceException in project spring-security by spring-projects.

the class UsernamePasswordAuthenticationFilter method attemptAuthentication.

// ~ Methods
// ========================================================================================================
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
    if (postOnly && !request.getMethod().equals("POST")) {
        throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    }
    String username = obtainUsername(request);
    String password = obtainPassword(request);
    if (username == null) {
        username = "";
    }
    if (password == null) {
        password = "";
    }
    username = username.trim();
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
    // Allow subclasses to set the "details" property
    setDetails(request, authRequest);
    return this.getAuthenticationManager().authenticate(authRequest);
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Example 7 with AuthenticationServiceException

use of org.springframework.security.authentication.AuthenticationServiceException in project spring-security by spring-projects.

the class DaoAuthenticationProviderTests method testDetectsNullBeingReturnedFromAuthenticationDao.

@Test
public void testDetectsNullBeingReturnedFromAuthenticationDao() {
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("rod", "koala");
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
    provider.setUserDetailsService(new MockAuthenticationDaoReturnsNull());
    try {
        provider.authenticate(token);
        fail("Should have thrown AuthenticationServiceException");
    } catch (AuthenticationServiceException expected) {
        assertThat("UserDetailsService returned null, which is an interface contract violation").isEqualTo(expected.getMessage());
    }
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) InternalAuthenticationServiceException(org.springframework.security.authentication.InternalAuthenticationServiceException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) Test(org.junit.Test)

Example 8 with AuthenticationServiceException

use of org.springframework.security.authentication.AuthenticationServiceException in project midpoint by Evolveum.

the class AuthenticationEvaluatorImpl method getPassword.

private String getPassword(ConnectionEnvironment connEnv, @NotNull MidPointPrincipal principal, ProtectedStringType protectedString) {
    String decryptedPassword;
    if (protectedString.getEncryptedDataType() != null) {
        try {
            decryptedPassword = protector.decryptString(protectedString);
        } catch (EncryptionException e) {
            recordAuthenticationFailure(principal, connEnv, "error decrypting password: " + e.getMessage());
            throw new AuthenticationServiceException("web.security.provider.unavailable", e);
        }
    } else {
        LOGGER.warn("Authenticating user based on clear value. Please check objects, " + "this should not happen. Protected string should be encrypted.");
        decryptedPassword = protectedString.getClearValue();
    }
    return decryptedPassword;
}
Also used : EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Example 9 with AuthenticationServiceException

use of org.springframework.security.authentication.AuthenticationServiceException in project midpoint by Evolveum.

the class MidPointAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String enteredUsername = (String) authentication.getPrincipal();
    LOGGER.trace("Authenticating username '{}'", enteredUsername);
    ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI);
    Authentication token;
    if (authentication instanceof UsernamePasswordAuthenticationToken) {
        String enteredPassword = (String) authentication.getCredentials();
        token = passwordAuthenticationEvaluator.authenticate(connEnv, new PasswordAuthenticationContext(enteredUsername, enteredPassword));
    } else if (authentication instanceof PreAuthenticatedAuthenticationToken) {
        token = passwordAuthenticationEvaluator.authenticateUserPreAuthenticated(connEnv, enteredUsername);
    } 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 : PasswordAuthenticationContext(com.evolveum.midpoint.model.api.context.PasswordAuthenticationContext) Authentication(org.springframework.security.core.Authentication) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 10 with AuthenticationServiceException

use of org.springframework.security.authentication.AuthenticationServiceException in project opennms by OpenNMS.

the class HybridOpenNMSUserAuthenticationProvider method checkUserPassword.

protected void checkUserPassword(final String authUsername, final String authPassword, final SpringSecurityUser user) throws AuthenticationException {
    final String existingPassword = user.getPassword();
    boolean hasUser = false;
    try {
        hasUser = m_userManager.hasUser(user.getUsername());
    } catch (final Throwable e) {
        throw new AuthenticationServiceException("An error occurred while checking for " + authUsername + " in the UserManager", e);
    }
    if (hasUser) {
        if (!m_userManager.comparePasswords(authUsername, authPassword)) {
            LOG.warn("Password auth failed for user: " + authUsername);
            throw new BadCredentialsException("Bad credentials");
        }
    } else {
        if (!m_userManager.checkSaltedPassword(authPassword, existingPassword)) {
            LOG.warn("Salted password auth failed for user: " + authUsername);
            throw new BadCredentialsException("Bad credentials");
        }
    }
}
Also used : BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Aggregations

AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)17 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)6 Authentication (org.springframework.security.core.Authentication)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 Test (org.junit.Test)3 ConnectionEnvironment (com.evolveum.midpoint.security.api.ConnectionEnvironment)2 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 LockedException (org.springframework.security.authentication.LockedException)2 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)2 PasswordAuthenticationContext (com.evolveum.midpoint.model.api.context.PasswordAuthenticationContext)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1