Subject currentUser = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(entity.getLoginName(), entity.getPassword()); currentUser.login(token);SysUser sysUser = ShiroUtils.getUserInfo();是什么意思
时间: 2023-06-05 21:08:15 浏览: 54
这段代码是Java语言中使用Apache Shiro框架进行用户身份认证和获取用户信息的代码段。具体来说,先通过输入的用户名和密码生成一个用户名密码令牌,然后通过Shiro的SecurityUtils类获取当前主题(即当前登录的用户),并使用生成的令牌进行登录认证。最后使用ShiroUtils类获取登录用户的信息。
相关问题
Subject subject = SecurityUtils.getSubject();
这段代码是什么意思?
这段代码使用 Apache Shiro 框架中的 SecurityUtils 类获取当前正在执行的主体(Subject)。主体指代当前的用户或程序,可以是一个已经认证过的用户、一个匿名用户或一个程序。通过获取主体,可以进行身份认证、授权等操作。在这段代码中,我们可以利用获取到的主体进行一些安全相关的操作,比如判断当前用户是否有权限执行某个操作。
Subject subject=SecurityUtils.getSubject();不能成功报错
这段代码在使用前需要先初始化SecurityUtils,常见的初始化方式是在应用程序的启动类中调用SecurityUtils.init()方法。如果没有进行初始化,调用SecurityUtils.getSubject()方法会返回null,导致该行代码报错。建议检查是否进行了初始化或者尝试在代码中手动初始化SecurityUtils。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)