Example usage for org.apache.shiro.web.session.mgt WebSessionContext getServletRequest

List of usage examples for org.apache.shiro.web.session.mgt WebSessionContext getServletRequest

Introduction

In this page you can find the example usage for org.apache.shiro.web.session.mgt WebSessionContext getServletRequest.

Prototype

ServletRequest getServletRequest();

Source Link

Document

Returns the ServletRequest received by the servlet container triggering the creation of the Session instance.

Usage

From source file:cn.guoyukun.spring.shiro.session.mgt.OnlineSessionFactory.java

License:Apache License

@Override
public Session createSession(SessionContext initData) {
    OnlineSession session = new OnlineSession();
    if (initData != null && initData instanceof WebSessionContext) {
        WebSessionContext sessionContext = (WebSessionContext) initData;
        HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
        if (request != null) {
            session.setClientIp(IpUtils.getIpAddr(request));
            session.setUserAgent(request.getHeader("User-Agent"));
            session.setHost(request.getLocalAddr() + ":" + request.getLocalPort());
            session.setReferer(request.getHeader("Referer"));
        }//from   ww w.  j a va 2  s . c  o m
    }
    return session;
}

From source file:org.lazulite.boot.autoconfigure.osaam.shiro.session.mgt.OnlineSessionFactory.java

License:Apache License

@Override
public Session createSession(SessionContext initData) {
    OnlineSession session = new OnlineSession();
    if (initData != null && initData instanceof WebSessionContext) {
        WebSessionContext sessionContext = (WebSessionContext) initData;
        HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
        if (request != null) {
            session.setHost(IpUtils.getIpAddr(request));
            session.setUserAgent(request.getHeader("User-Agent"));
            session.setSystemHost(request.getLocalAddr() + ":" + request.getLocalPort());
        }//  ww w  .j av a2s.  co  m
    }
    return session;
}