@@ -159,6 +159,8 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
159159
160160 private RowMapper <UserDetails > userDetailsMapper = this ::mapToUser ;
161161
162+ private RowMapper <GrantedAuthority > grantedAuthorityMapper = this ::mapToGrantedAuthority ;
163+
162164 public JdbcUserDetailsManager () {
163165 }
164166
@@ -182,6 +184,21 @@ public void setUserDetailsMapper(RowMapper<UserDetails> mapper) {
182184 this .userDetailsMapper = mapper ;
183185 }
184186
187+ /**
188+ * Sets the {@code RowMapper} to convert each authority result row into a
189+ * {@link GrantedAuthority} object.
190+ *
191+ * The default mapper expects columns with names like 'authority' or 'role', and maps
192+ * them directly to SimpleGrantedAuthority objects.
193+ * @param mapper the {@code RowMapper} to use for mapping rows in the database to
194+ * GrantedAuthority objects, must not be null
195+ * @since 6.5
196+ */
197+ public void setGrantedAuthorityMapper (RowMapper <GrantedAuthority > mapper ) {
198+ Assert .notNull (mapper , "grantedAuthorityMapper cannot be null" );
199+ this .grantedAuthorityMapper = mapper ;
200+ }
201+
185202 @ Override
186203 protected void initDao () throws ApplicationContextException {
187204 if (this .authenticationManager == null ) {
@@ -197,7 +214,7 @@ protected void initDao() throws ApplicationContextException {
197214 */
198215 @ Override
199216 protected List <UserDetails > loadUsersByUsername (String username ) {
200- return getJdbcTemplate ().query (getUsersByUsernameQuery (), userDetailsMapper , username );
217+ return getJdbcTemplate ().query (getUsersByUsernameQuery (), this . userDetailsMapper , username );
201218 }
202219
203220 private UserDetails mapToUser (ResultSet rs , int rowNum ) throws SQLException {
@@ -406,10 +423,10 @@ public List<GrantedAuthority> findGroupAuthorities(String groupName) {
406423 this .logger .debug ("Loading authorities for group '" + groupName + "'" );
407424 Assert .hasText (groupName , "groupName should have text" );
408425 return getJdbcTemplate ().query (this .groupAuthoritiesSql , new String [] { groupName },
409- this :: mapToGrantedAuthority );
426+ this . grantedAuthorityMapper );
410427 }
411428
412- protected GrantedAuthority mapToGrantedAuthority (ResultSet rs , int rowNum ) throws SQLException {
429+ private GrantedAuthority mapToGrantedAuthority (ResultSet rs , int rowNum ) throws SQLException {
413430 String roleName = getRolePrefix () + rs .getString (3 );
414431 return new SimpleGrantedAuthority (roleName );
415432 }
0 commit comments