@@ -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 ) {
@@ -405,11 +422,10 @@ public void removeUserFromGroup(final String username, final String groupName) {
405422 public List <GrantedAuthority > findGroupAuthorities (String groupName ) {
406423 this .logger .debug ("Loading authorities for group '" + groupName + "'" );
407424 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 );
410426 }
411427
412- protected GrantedAuthority mapToGrantedAuthority (ResultSet rs , int rowNum ) throws SQLException {
428+ private GrantedAuthority mapToGrantedAuthority (ResultSet rs , int rowNum ) throws SQLException {
413429 String roleName = getRolePrefix () + rs .getString (3 );
414430 return new SimpleGrantedAuthority (roleName );
415431 }
0 commit comments