简体   繁体   English

为什么主体在Spring Security中返回为Object类型?

[英]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 . 我将isBlocked添加到我的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? 如何在spring-security中注销所有已登录的用户?

But I have not ideas how to check that principal( java.lang.Object actually) related with user. 但是我不知道如何检查与用户相关的主体(实际上是java.lang.Object )。

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. 主体的类可以是org.springframework.security.core.userdetails.User或其他任何类,这取决于您如何使用SpringSecurity。

A quick way to know what is the correct Class is debugging the solution commented in the link you provided. 知道什么是正确的类的快速方法是调试您提供的链接中注释的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 安全,本金返回 null - Spring security , Principal returns null Spring Security 中 JSON 的主体对象 - Principal Object to JSON in Spring Security Spring Security 如何将主体注入 Controller 中? - How does Spring Security inject principal into Controller? Spring安全性返回String作为主体而不是登录失败时的UserDetails? - Spring security returns String as principal instead of UserDetails on failed login? 使用Spring安全主体对象进行身份验证时,Spring RestController上的IllegalArgumentException - IllegalArgumentException on Spring RestController when using Spring security Principal object for authentication Spring安全访问主体 - Spring security accessing principal Spring Security Principal转换 - Spring Security Principal transformation 向存储在 spring 安全上下文中的主体 object 添加其他详细信息 - Adding additional details to principal object stored in spring security context 即使在使用setAuthenticated(false)之后,也可以获得Spring Security中的主体对象 - getting principal object in spring security even after using setAuthenticated(false) Spring Security的ACL(访问控制列表)如何处理每个OBJECT_IDENTITY具有多个权限的主体? - How does Spring Security's ACL (access control list) deal with a principal having multiple permissions per OBJECT_IDENTITY?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM