@@ -159,6 +159,8 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
159
159
160
160
private RowMapper <UserDetails > userDetailsMapper = this ::mapToUser ;
161
161
162
+ private RowMapper <GrantedAuthority > grantedAuthorityMapper = this ::mapToGrantedAuthority ;
163
+
162
164
public JdbcUserDetailsManager () {
163
165
}
164
166
@@ -182,6 +184,21 @@ public void setUserDetailsMapper(RowMapper<UserDetails> mapper) {
182
184
this .userDetailsMapper = mapper ;
183
185
}
184
186
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
+
185
202
@ Override
186
203
protected void initDao () throws ApplicationContextException {
187
204
if (this .authenticationManager == null ) {
@@ -405,11 +422,10 @@ public void removeUserFromGroup(final String username, final String groupName) {
405
422
public List <GrantedAuthority > findGroupAuthorities (String groupName ) {
406
423
this .logger .debug ("Loading authorities for group '" + groupName + "'" );
407
424
Assert .hasText (groupName , "groupName should have text" );
408
- return getJdbcTemplate ().query (this .groupAuthoritiesSql , new String [] { groupName },
409
- this ::mapToGrantedAuthority );
425
+ return getJdbcTemplate ().query (this .groupAuthoritiesSql , new String [] { groupName }, grantedAuthorityMapper );
410
426
}
411
427
412
- protected GrantedAuthority mapToGrantedAuthority (ResultSet rs , int rowNum ) throws SQLException {
428
+ private GrantedAuthority mapToGrantedAuthority (ResultSet rs , int rowNum ) throws SQLException {
413
429
String roleName = getRolePrefix () + rs .getString (3 );
414
430
return new SimpleGrantedAuthority (roleName );
415
431
}
0 commit comments