-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make mapToUser and mapToGrantedAuthority protected in JdbcUserDetails… #16561
base: main
Are you sure you want to change the base?
Make mapToUser and mapToGrantedAuthority protected in JdbcUserDetails… #16561
Conversation
6b6a462
to
548be22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @big-cir! Can we try composition first? I've left some feedback inline for details on how that could be done.
@@ -181,7 +181,7 @@ protected List<UserDetails> loadUsersByUsername(String username) { | |||
return getJdbcTemplate().query(getUsersByUsernameQuery(), this::mapToUser, username); | |||
} | |||
|
|||
private UserDetails mapToUser(ResultSet rs, int rowNum) throws SQLException { | |||
protected UserDetails mapToUser(ResultSet rs, int rowNum) throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of opening these methods up, could we first try using RowMapper<UserDetails>
? I think it could work like this:
- add a new member called
RowMapper<UserDetails> userDetailsMapper = this::mapToUser
- use this mapper in the
JdbcTemplate
invocation - add
setUserDetailsMapper(RowMapper)
to the class
This reflects what newer Jdbc-based Spring Security components have been doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jzheaux
Thank you for your feedback! I've implemented the changes as per your suggestion. Could you please confirm if I've correctly understood and applied your recommendations?
78af6dc
to
52faf76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @big-cir, yes, that's what I'm thinking. Please see some additional feedback about the method and then let's also proceed with doing the same for mapToGrantedAuthority
.
public JdbcUserDetailsManager() { | ||
} | ||
|
||
public JdbcUserDetailsManager(DataSource dataSource) { | ||
setDataSource(dataSource); | ||
} | ||
|
||
public void setUserDetailsMapper(RowMapper<UserDetails> mapper) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please add a JavaDoc description. It should include the following:
@@ -178,7 +186,7 @@ protected void initDao() throws ApplicationContextException { | |||
*/ | |||
@Override | |||
protected List<UserDetails> loadUsersByUsername(String username) { | |||
return getJdbcTemplate().query(getUsersByUsernameQuery(), this::mapToUser, username); | |||
return getJdbcTemplate().query(getUsersByUsernameQuery(), userDetailsMapper, username); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add two unit tests:
- One that confirms that setting a
null
value forsetUserDetailsMapper
will throw an exception - One that confirms that setting a mock value gets used when querying (call
setUserDetailMapper
with a Mockito mock, search for a user, and verify that the mock row mapper was used)
…Manager - Closes spring-projectsgh-16540 Signed-off-by: dae won <[email protected]>
Signed-off-by: dae won <[email protected]>
Signed-off-by: dae won <[email protected]>
Signed-off-by: dae won <[email protected]>
52faf76
to
d506c1a
Compare
@jzheaux, Thank you again for your time and expertise. |
7ee7de6
to
50fd7c0
Compare
- Add unit tests for setGrantedAuthorityMapper method Signed-off-by: dae won <[email protected]>
50fd7c0
to
f06c979
Compare
Changed
mapToUser
method to protectedmapToGrantedAuthority
method to protectedRelated