У меня проблема со входом в систему. Каждый раз, когда в блоке перехвата возникает ошибка Введено неверное имя пользователя / пароль . При входе в систему я ввожу правильное имя пользователя и пароль. Пароль в моей программе хешируется
Я пробовал много решений, но ничего не помогает
UserServiceImpl
@Override
public String login(User user) {
try {
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword()));
return jwtTockenCreator.createTocken(user.getUsername());
} catch (AuthenticationException e) {
throw new CustomException("Invalid username/password supplied", HttpStatus.UNPROCESSABLE_ENTITY);
}
}
WebSecurityConfig
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.authorizeRequests()
.antMatchers("/user/login").permitAll()
.antMatchers("/user/addUser").permitAll()
.anyRequest().authenticated();
http.exceptionHandling().accessDeniedPage("/login");
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(myUserDetalis).passwordEncoder(bCryptPasswordEncoder);
auth.userDetailsService(myUserDetalis);
}
MyUserDetails
@Service
public class MyUserDetails implements UserDetailsService {
@Autowired
private UserRepository userRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
final User user = userRepository.findByUsername(username);
if (user == null) {
throw new UsernameNotFoundException("User '" + username + "' not found");
}
return org.springframework.security.core.userdetails.User
.withUsername(username)
.password(user.getPassword())
.accountExpired(false)
.accountLocked(false)
.credentialsExpired(false)
.disabled(false)
.build();
}
}