-
Notifications
You must be signed in to change notification settings - Fork 6k
Make JdbcUserDetailsManager to be able to handle UserDetails'es: nonLocked, nonExpired, credentialsNonExpired #4399
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
Comments
We run into this issue at work, it's problematic for us and it seems quite simple to fix, is there any reason it was never addressed ? Thanks ! |
Same issue here. I went around it by extending the JdbcUserDetailsManager. However then I run into issues with private validation functions: private void validateUserDetails(UserDetails user) and private void validateAuthorities(Collection<? extends GrantedAuthority> authorities). I would rather see them protected. |
Thanks for the ping @123raoul123 If someone wants to send a PR (the changes must be passive) for this, we'd gladly accept it. If anyone wants to work on it, please claim it via the comments |
Hello @rwinch, I would like to take this one |
Thank you for volunteering @pvliss! The issue is all yours. Please let us know if you have any questions! |
Hello @rwinch, Thanks!!! I have already actually created a first draft commit at my fork although I do have some questions that I need your help with before I submit the PR:
Thanks for all your hard work!!! Regards, |
Thanks for putting this together @pvliss! I think it might be easier if we specify the contract as if the column count is larger than 3, then it will get the accountNonExpired, credentialsNonExpired, accountNonLocked attributes. Then in the |
Hello @rwinch, Thanks for taking a look. While your suggestion/solution requires no additional configuration I think that it is not safe as there might be cases where it fails at run-time as an app might already have more columns on the user table and at the same time not fully customize What about other users? @paul-ovchinnikov, @avaud , @123raoul123 any comments Regards, |
I don't understand why you would retrieve the user prefs in that context since it won't be mapped anyway. |
Hello @avaud You misunderstood me or maybe I was not clear enough. I did not say I would retrieve the user prefs in that context, its obviously not needed. What I meant was that I had more columns added in the This could of-course be caught in your test run but that would be yet another assumption. I think that checking the schema with the help of DatabaseMetaData#getColumns() would be a safer solution. Ofcourse will be checking just the existence of a single column for simplicity and once at startup to avoid possible performance issues. Will create a new POC soon Regards, |
Hello, I get that but if you use ResultSetMetaData: int columnsNumber = rsmd.getColumnCount(); |
Hey, thanks for helping out. Yes, you are right but in order to use Am I missing something obvious here? |
I don't get why it would cause an error since it's written by a dev who should know the columns in the DB. But since @rwinch seemed to have an idea on how to do that, I suggest you wait for his advice. He will probably know better than me. |
So I am guessing you are talking about the case where someone also overrides the default queries. In that case, yes it would not be such a problem. I guess you are right, I will wait for @rwinch's advice. Nevertheless, I have taken another shot at it using |
Well I did not know there was default queries... That explains the confusion. |
I'm not sure I understand the concern. Spring Security does not have The |
Hello Rob. Thanks for your advice. So if I understood correctly we should not care about the default query and only have the user define custom queries in order to enable these attributes in a pre-defined order. Is that right? Please see my latest commit using that approach and let me know if that is what you had in mind. |
@pvliss Thanks for the fast turnaround. Sorry I wasn't clear about leaving the default query the same. We need to do this for passivity. Only user's needing the new functionality would leverage this by changing the query. Yes this is what I had in mind. A few pieces of feedback:
|
@rwinch No problem. Glad we are on the same page now. Should have asked for more clarifications before going on to implementing things. Now to answer your points:
|
@rwinch So I squashed the commits, hopefully the changes are more easier to spot now. Regarding your last point
Does that mean I should also revert my change from anonymous classes to lambdas as well or are you fine with them? |
Thanks!
I think they are ok changes, but not as a part of this issue. We want to keep changes isolated to the ticket in the commit so that we can track the changes. By keeping changes isolated we make thinks like backporting and tracking down issues a lot easier. Do you mind submitting this as a PR so it is easier to provide feedback? Commenting on the commit's isn't ideal since the feedback is lost if your branch is removed, forced push occurs, etc. |
Yes, I understand. I have reverted all lambda changes, squashed again and submitted the PR.
Should I create an issue just for these JDBC related classes or a more generic one for the whole project? IDEA reports 54 such cases and 90 incl. tests. |
Thank you.
Thank you. Yes that would be good. It might help (so we don't need to rebase) to wait till these changes get merged first. |
Just to avoid any misunderstandings I will ask again. A generic one(i.e. convert anonymous classes to lambdas throughout the whole project) or a JDBC code specific one? |
Check ResutSetMetaData to see if extra columns are present in order to also handle the UserDetails attributes: accountNonExpired, accountNonLocked and credentialsNonExpired. Fixes spring-projectsgh-4399
Check ResutSetMetaData to see if extra columns are present in order to also handle the UserDetails attributes: accountNonExpired, accountNonLocked and credentialsNonExpired. Fixes gh-4399
Summary
JdbcUserDetailsManager
has excellent native implementation CRUD and utility methods to handle User state (groups, authorities, roles and so on)org.springframework.security.core.userdetails.User
andorg.springframework.security.core.userdetails.UserDetails
also determines additional states:Actual Behavior
At the moment
org.springframework.security.provisioning.JdbcUserDetailsManager
andorg.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
only can handle enabled state of theUser
On the other hand oauth2 Spring implementation is able to handle this states already.
But security framework returns default hardcoded values for accountNonExpired, accountNonLocked, credentialsNonExpired (true, true, true)
Expected Behavior
Please extend
org.springframework.security.provisioning.JdbcUserDetailsManager
andorg.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
to support allUserDetails
andUser
states.And make private methods to be public:
Version
Spring Framework: 4.3.8.RELEASE
Spring Security Framework: 4.2.3.RELEASE
The text was updated successfully, but these errors were encountered: