List of usage examples for org.springframework.security.authentication LockedException getMessage
public String getMessage()
From source file:ru.org.linux.auth.LoginController.java
@RequestMapping(value = "/ajax_login_process", method = RequestMethod.POST) @ResponseBody/*from w w w .j a v a2 s. co m*/ public LoginStatus loginAjax(@RequestParam("nick") final String username, @RequestParam("passwd") final String password, HttpServletRequest request, HttpServletResponse response) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); try { UserDetailsImpl details = (UserDetailsImpl) userDetailsService.loadUserByUsername(username); token.setDetails(details); Authentication auth = authenticationManager.authenticate(token); UserDetailsImpl userDetails = (UserDetailsImpl) auth.getDetails(); if (!userDetails.getUser().isActivated()) { return new LoginStatus(false, "User not activated"); } SecurityContextHolder.getContext().setAuthentication(auth); rememberMeServices.loginSuccess(request, response, auth); AuthUtil.updateLastLogin(auth, userDao); return new LoginStatus(auth.isAuthenticated(), auth.getName()); } catch (LockedException e) { return new LoginStatus(false, "User locked"); } catch (UsernameNotFoundException e) { return new LoginStatus(false, "Bad credentials"); } catch (BadCredentialsException e) { return new LoginStatus(false, e.getMessage()); } }
From source file:org.egov.infra.config.security.authentication.provider.ApplicationAuthenticationProvider.java
private Authentication unlockAccount(Authentication authentication, LockedException le) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); HttpServletRequest request = attributes.getRequest(); if (isNotBlank(request.getParameter(RECAPTCHA_RESPONSE)) || isNotBlank(request.getParameter(J_CAPTCHA_RESPONSE))) { if (recaptchaUtils.captchaIsValid(request)) { loginAttemptService.resetFailedAttempt(authentication.getName()); return super.authenticate(authentication); } else {/*from w ww . j ava 2 s. co m*/ throw new LockedException(format(INVALID_CAPTCHA_MSG_FORMAT, le.getMessage())); } } throw le; }