@ExceptionHandler( UsernameNotFoundException.class ) public ResponseEntity serviceErrorHandler ( UsernameNotFoundException e ) { LogUtils.getLogger().error( "error" , e ); return ResponseEntityPro.unauthorized( e.getMessage() , e.getMessage() ); }
@ExceptionHandler(value = UsernameNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody public ApiResponse handleUsernameNotFoundException(UsernameNotFoundException ex) { ApiResponse apiResponse = new ApiResponse(); apiResponse.setSuccess(false); apiResponse.setData(ex.getMessage()); return apiResponse; }
@Override public SocialUserDetails loadUserByUserId(final String username) throws UsernameNotFoundException, DataAccessException { try { log.debug("LOAD USER : {}", username); UserDetails userDetails = userDetailsService.loadUserByUsername(username); return new SocialUser(username, "N/A", userDetails.getAuthorities()); } catch (UsernameNotFoundException e) { log.warn(e.getMessage(), e); } return null; }
@PreAuthorize("hasRole('USER')") @DeleteMapping(path = "/api/user/remove", produces = "application/json") public ResponseEntity<?> removeUser() { try { accountService.removeAuthenticatedAccount(); return new ResponseEntity<Object>(new RestResponse("User removed."), HttpStatus.OK); } catch (UsernameNotFoundException e) { e.printStackTrace(); return new ResponseEntity<Object>(new RestError(e.getMessage()), HttpStatus.OK); } }
errors.add(e.getMessage()); model.addAttribute("errors", errors); return new ModelAndView("users/forgotPassword", model);
@Override public Authentication authenticate(T authenticationToken) throws AuthenticationException { if (authenticationToken == null) { throw new InvalidTokenException("Null authentication token"); } org.springframework.security.core.Authentication authentication = getAuthentication(authenticationToken); if (authentication == null) { throw new InvalidTokenException("Invalid authentication token: missing Spring Security Authentication"); } try { authentication = authenticationManager.authenticate(authentication); } catch (UsernameNotFoundException e) { throw new UnknownAccountException(e.getMessage()); } catch (BadCredentialsException e) { throw new InvalidCredentialsException(e.getMessage()); } catch (CredentialsExpiredException | AccountExpiredException e) { throw new ExpiredCredentialsException(e.getMessage()); } catch (DisabledException e) { throw new DisabledAccountException(e.getMessage()); } catch (LockedException e) { throw new LockedAccountException(e.getMessage()); } catch (Exception e) { throw new UnexpectedAuthenticationException(e.getMessage(), e); } return SpringSecurityAuthentication.create(authentication); }