java - How to manage a custom user object in session when Spring Security autheticates user? -


When authenticates the user, it creates a UserDetail object and it is available to find the current user id in the web-app. is. But suppose I want to change user user or user department with preferences and other details about custom user object.

So, when Spring safety is successfully authenticated, how can you add custom user objects to the session? How to remove custom user objects from the session and when the Spring Security log-in user logs out

Or is there a proper way to do this?

This is the best way to IMO that one of your services (probably user service) is called UserDetailsService Be applicable and specify the spring security XML that you want to use your User Details service.

What the userDetailsService must do is implement a loadByUsername (String Username) method This method applies to UserDetails that will need to return a category. It may be your own custom object that you like. The advantage of this is that you can access the property properties from JSP through Spring Security telegleb and it is also always available in the Security Security by SecureTextHolder Singleton (Thread Safe).

Here is a link to Docs: There is a blog post about implementing Custom User Description Services for Password Encryption:

Hope this helps

P>

Edit: forgot to mention that the object will be removed from the session on security references and logout. What is most useful about it, it is fully managed by spring security.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -