Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AuthProviderImpl implements AuthenticationProvider {
- @Autowired
- UserRepository userRepository;
- BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
- @Override
- public Authentication authenticate(Authentication authentication) throws AuthenticationException {
- String login = authentication.getName();
- Users user = userRepository.findByLogin(login);
- if (user == null) {
- System.out.println("user not found");
- throw new UsernameNotFoundException("user not found");
- }
- String password = authentication.getCredentials().toString();
- System.out.println(password);
- if (!encoder.matches(password, user.getPassword()) && !password.equals(user.getPassword())) {
- System.out.println("invalid password");
- throw new BadCredentialsException("invalid password");
- }
- List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
- authorities.add(new SimpleGrantedAuthority(user.getRole()));
- return new UsernamePasswordAuthenticationToken(user, null, authorities);
- }
- @Override
- public boolean supports(Class<?> aClass) {
- return aClass.equals(UsernamePasswordAuthenticationToken.class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement