代码语言:javascript复制
package com.ccb.web.shiro;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.SessionFactory;
import org.apache.shiro.session.mgt.SimpleSession;
import org.apache.shiro.web.session.mgt.DefaultWebSessionContext;
import projects.commons.utils.net.IpUtils;
import javax.servlet.http.HttpServletRequest;
/**
* session工厂类
*
* @author zhuyongsheng
* @date 2019/8/15
*/
@Slf4j
public class ShiroSessionFactory implements SessionFactory {
/**
* 重写创建session方法,使用自己的shiroSession
*
* @return org.apache.shiro.session.Session
* @author zhuyongsheng
* @date 2019/8/15
*/
@Override
public Session createSession(SessionContext initData) {
SimpleSession session = new SimpleSession();
HttpServletRequest request = (HttpServletRequest) initData.get(DefaultWebSessionContext.class.getName()
".SERVLET_REQUEST");
session.setHost(IpUtils.getRealIp(request));
return session;
}
}