I'm trying to learn Spring security currently. I used BCryptPasswordEncoder to encode user password before persisting into a database
Code:
@Override
public void saveUser(User user) {
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
user.setActive(1);
Role userRole = roleRepository.findByRole("ADMIN");
user.setRoles(new HashSet<Role>(Arrays.asList(userRole)));
userRepository.save(user);
}
Then used it during authentication as well and User was getting authenticated as expected.
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.
jdbcAuthentication()
.usersByUsernameQuery(usersQuery)
.authoritiesByUsernameQuery(rolesQuery)
.dataSource(dataSource).passwordEncoder(bCryptPasswordEncoder);
}
Then I removed .passwordEncoder(bCryptPasswordEncoder); from configure() method, still users with encoded password is getting authenticated successfully.
Then I removed password encoder from both the saveUser() and the configure() method, and persisted a User into the database(i.e without password encoding) and tried to access an authenticated page but I got AccessedDeniedException,
But users with encoded password still gets authenticated even though i removed passwordEncoder() from configure() method. Why is this happening?
Does spring security by default use password encoder during authentication?
If so how to use spring security without password encoding?
{noop}<the-password>and it will use a plain encoder. Use{bcrypt}as the prefix for crypt (which is also the default). See docs.spring.io/spring-security/site/docs/current/reference/…