Example usage for org.springframework.security.core AuthenticationException AuthenticationException

List of usage examples for org.springframework.security.core AuthenticationException AuthenticationException

Introduction

In this page you can find the example usage for org.springframework.security.core AuthenticationException AuthenticationException.

Prototype

public AuthenticationException(String msg) 

Source Link

Document

Constructs an AuthenticationException with the specified message and no root cause.

Usage

From source file:oobbit.security.JpaAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication a) throws AuthenticationException {
    String username = a.getPrincipal().toString();
    String password = a.getCredentials().toString();

    try {// ww w.  j  a  v a  2 s  .c o m
        User user = users.attemptLogin(username, password);
        return new UsernamePasswordAuthenticationToken(user.getUsername(), password,
                accessLevelToGrantedAuthority.accessLevelToSimpleGrantedAuthorityList(user.getAccessLevel()));
    } catch (SQLException ex) {
        Logger.getLogger(JpaAuthenticationProvider.class.getName()).log(Level.SEVERE,
                "SQLException was thrown while authenticating a user in JpaAuthenticationProvider.", ex);
    } catch (FailedLoginException ex) {
        Logger.getLogger(JpaAuthenticationProvider.class.getName()).log(Level.SEVERE,
                "FailedLoginException was thrown while tyring to authenticate a user.", ex);
    }

    throw new AuthenticationException("Unable to authenticate user " + username) {
    };
}

From source file:com.tlantic.integration.authentication.service.security.UserAuthProviderService.java

@Override
public Authentication authenticate(Authentication a) throws AuthenticationException {
    String email = a.getName();/*w  ww  .j  a  v  a  2s.  c  o  m*/
    String password = a.getCredentials().toString();
    User user = authConfigService.getUser(email);
    if (null != user) {
        if (passwordEncoder.matches(password, user.getPassword())) {
            List<GrantedAuthority> roleAuthority = authConfigService.getRights(user);
            return signInUser(user, roleAuthority);
        }
        throw new AuthenticationException("Password for '" + email + "' not correct.") {
        };
    }

    throw new AuthenticationException("Could not find user with name '" + email + "'") {
    };
}

From source file:nl.surfnet.mujina.spring.security.CustomAuthenticationProvider.java

@SuppressWarnings("serial")
@Override//from  www.j  ava  2  s  . co m
public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
    final String name = authentication.getName();
    final String password = authentication.getCredentials().toString();

    /*
     * First check if we know this user. Fallback user if Method.ALL otherwise
     * an Exception
     */
    Authentication authenticationForUser = getAuthenticationForUser(name, password);
    if (idpConfiguration.getAuthentication() == AuthenticationMethod.Method.ALL) {
        return authenticationForUser != null ? authenticationForUser
                : new SimpleAuthentication(name, password,
                        Arrays.asList((GrantedAuthority) new GrantedAuthorityImpl("ROLE_USER"),
                                (GrantedAuthority) new GrantedAuthorityImpl("ROLE_ADMIN")));
    } else {
        if (authenticationForUser == null) {
            throw new AuthenticationException("Can not log in") {
            };
        }
        return authenticationForUser;

    }
}

From source file:com.ebay.pulsar.analytics.spring.security.GlobalSecuritySettingTest.java

@Test
public void testPlainTextBasicAuthenticationEntryPoint() throws IOException, ServletException {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    when(response.getWriter()).thenReturn(new PrintWriter(System.out));
    PlainTextBasicAuthenticationEntryPoint point = new PlainTextBasicAuthenticationEntryPoint();
    point.setRealmName("Test query");
    point.commence(request, response, new AuthenticationException("Test Exception message") {

        /**// ww  w  .  ja v a2  s  .co m
         * 
         */
        private static final long serialVersionUID = 8643273901705238777L;

    });

}

From source file:org.wise.portal.presentation.web.filters.WISEAuthenticationProcessingFilter.java

/**
 * Check if the user is required to enter ReCaptcha text. If the
 * user is required to enter ReCaptcha text we will check if the
 * user has entered the correct ReCaptcha text. If ReCaptcha is 
 * not required or if the ReCaptcha has been entered correctly,
 * continue on with the authentication process.
 * /*from  www . j  a  v  a 2  s.  c  om*/
 * @param request
 * @param response
 */
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
        throws AuthenticationException {

    // check if the user is required to enter ReCaptcha text
    if (isReCaptchaRequired(request, response)) {
        // the user is required to enter ReCaptcha text

        String errorMessage = null;

        if (!isReCaptchaResponseValid(request, response)) {
            //the user has not answered the ReCaptcha correctly
            errorMessage = "Please verify that you are not a robot.";
        }

        if (errorMessage != null) {
            try {
                /*
                 * the user has not been authenticated because they did not
                 * pass the ReCaptcha
                 */
                unsuccessfulAuthentication(request, response, new AuthenticationException(errorMessage) {
                });

                return null;
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ServletException e) {
                e.printStackTrace();
            }
        }
    }

    return super.attemptAuthentication(request, response);
}