无法在SecurityUtils.getSubject()中获取主体

时间:2017-08-15 09:18:28

标签: java shiro

登录时使用Shiro

@RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity<RestResult> login(@Valid @RequestBody User user, BindingResult result,
                                            HttpSession session, HttpServletRequest request) {
        Subject subject = SecurityUtils.getSubject();
        Result result = userService.login(user.getName(), user.getPassword());
        if (result.isSuccess()) {
            UsernamePasswordToken token = new UsernamePasswordToken(user.getName(), user.getPassword(), false,
                            request.getRemoteHost());
            subject.login(token);
        }
        return result.toResponseEntity();
    }

并以注销方式:

   @RequestMapping("/logout")
@ResponseBody
public ResponseEntity<RestResult> logout(HttpSession session) {
    Subject subject = SecurityUtils.getSubject();
    subject.logout();
    return Result.success().build();
}

该片段似乎没问题,但在注销方法中,主题中的成员如下, enter image description here

因为图片显示校长是空的,所以,问题是什么?

0 个答案:

没有答案