Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. private void authenticate(String username, String password) {
  2.  
  3. Objects.requireNonNull(username);
  4. Objects.requireNonNull(password);
  5.  
  6. if (StringUtils.isEmpty(username)) throw new AuthenticationException();
  7. if (StringUtils.isEmpty(password)) throw new AuthenticationException();
  8.  
  9. try {
  10. authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
  11. } catch (DisabledException e) {
  12. throw new AuthenticationException("User is disabled!", e);
  13. } catch (BadCredentialsException e) {
  14. throw new AuthenticationException("Bad credentials!", e);
  15. }
  16. }
  17.  
  18. @Bean
  19. public BCryptPasswordEncoder passwordEncoder() {
  20. return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes()));
  21. }
  22.  
  23.  
  24. String encryptedPassword = passwordEncoder().encode(user.getPassword());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement