Get User details from Session in Spring Security -
i new spring mvc , spring security. have performed log-in , registration functionality using spring security , mvc. not able find way session management .
i want access user details on pages (email, name,id,role etc). want save these session object can these on of page.
i following way session in spring
authentication auth = securitycontextholder.getcontext().getauthentication(); auth.getprincipal();
but object returned can username , password details.
but need access more details of user.
- is there way saving session , on jsp page?
- or there ootb way in spring done?
please me solution this. in advance.
i want model class object returned securitycontextholder.getcontext().getauthentication().getdetails(); need configure.
regards, pranav
you need make model class implement userdetails interface
class myusermodel implements userdetails { //all fields , setter/getters //all interface methods implementation }
then in spring controller can this:
authentication auth = securitycontextholder.getcontext().getauthentication(); object myuser = (auth != null) ? auth.getprincipal() : null; if (myuser instanceof myusermodel) { myusermodel user = (myusermodel) myuser; //get details model object }
Comments
Post a Comment