JdbcUserDetailsManager implements UserDetailsService and UserDetailsManager, retrieving and managing Spring Security users directly through JDBC and a relational database. section 3.3.3 section 3.4
Authentication uses the inherited user lookup contract; user administration adds operations for creating, updating, deleting, checking, and changing user passwords. section 3.3.3 section 3.0
A basic JDBC arrangement uses the following pieces:
- Create users and authorities tables, using the default table names recognized by JdbcUserDetailsManager. section 3.3.3
- Store username, password, and enabled in users; store username and authority in authorities. section 3.3.3
- Expose a UserDetailsService bean that constructs JdbcUserDetailsManager with a DataSource. section 3.3.3
- Override the users and authorities queries when an existing schema does not match the defaults. section 3.3.3
Minimal configuration and verification
Register `new JdbcUserDetailsManager(dataSource)` as the UserDetailsService, configure a PasswordEncoder, and protect a `/hello` endpoint. With a stored `john` user, `curl -u john:12345 http://localhost:8080/hello` returns `Hello!`. section 3.3.3
public interface UserDetailsManager extends UserDetailsService {
void createUser(UserDetails user);
void updateUser(UserDetails user);
void deleteUser(String username);
void changePassword(String oldPassword, String newPassword);
boolean userExists(String username);
}
Inspect the UserDetailsManager contract to see the inherited lookup role alongside user-creation and account-management operations. section 3.3.3
