Add userDetailsMapper as a class member

Signed-off-by: dae won <eodnjs01477@gmail.com>
This commit is contained in:
dae won 2025-02-14 09:58:19 +09:00 committed by Josh Cummings
parent e8fe003c4c
commit 6ac3426e39

View File

@ -30,6 +30,7 @@ import org.springframework.context.ApplicationContextException;
import org.springframework.core.log.LogMessage; import org.springframework.core.log.LogMessage;
import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -156,6 +157,8 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
private UserCache userCache = new NullUserCache(); private UserCache userCache = new NullUserCache();
private RowMapper<UserDetails> userDetailsMapper = this::mapToUser;
public JdbcUserDetailsManager() { public JdbcUserDetailsManager() {
} }
@ -163,6 +166,11 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
setDataSource(dataSource); setDataSource(dataSource);
} }
public void setUserDetailsMapper(RowMapper<UserDetails> mapper) {
Assert.notNull(mapper, "userDetailsMapper cannot be null");
this.userDetailsMapper = mapper;
}
@Override @Override
protected void initDao() throws ApplicationContextException { protected void initDao() throws ApplicationContextException {
if (this.authenticationManager == null) { if (this.authenticationManager == null) {
@ -178,7 +186,7 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
*/ */
@Override @Override
protected List<UserDetails> loadUsersByUsername(String username) { protected List<UserDetails> loadUsersByUsername(String username) {
return getJdbcTemplate().query(getUsersByUsernameQuery(), this::mapToUser, username); return getJdbcTemplate().query(getUsersByUsernameQuery(), userDetailsMapper, username);
} }
protected UserDetails mapToUser(ResultSet rs, int rowNum) throws SQLException { protected UserDetails mapToUser(ResultSet rs, int rowNum) throws SQLException {