Shiro通过验证Session来判断用户的登录状态,由于移动APP、小程序等没有Session,导致移动端无法判断用户登录状态。所以改为移动端登陆成功后返回token,在移动端获取其他系统资源时将token和用户ID(用户的唯一标识)设置为请求头,后台验证Session改为验证token的正确性。
1.新建LoginSessionManager继承 DefaultWebSessionManager
package com.caijiang.workorder.config;
import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.apache.shiro.web.util.WebUtils;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.Serializable;
public class LoginSessionManager extends DefaultWebSessionManager {
private static final String AUTHORIZATION = "token";
private static final String REFERENCED_SESSION_ID_SOURCE = "Stateless request";
public LoginSessionManager(){
supe