简体   繁体   中英

Why does principal returns as type Object in spring security?

I have added blocking user functionality on the site.

I add isBlocked to my UserModel . When I user try to login - this fields checks.

Problem retains for already logged user. I want to force log out it when admin block user.

I have read following topic:

How do you log out all logged in users in spring-security?

But I have not ideas how to check that principal( java.lang.Object actually) related with user.

The principal is the object that you have to use in order to identify a user. Once identified you can expired the session of that user. Here you will find a nice explanation on what a Principal is in Spring.

You can cast the principal to the appropriate Class, but you have to know it before. The Class of the principal could be org.springframework.security.core.userdetails.User or whatever, it depends on how you are using SpringSecurity.

A quick way to know what is the correct Class is debugging the solution commented in the link you provided.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM