org.apache.shiro.session.mgt.SessionContext Java Examples

The following examples show how to use org.apache.shiro.session.mgt.SessionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OnlineSessionFactory.java    From ruoyiplus with MIT License 6 votes vote down vote up
@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)
        {
            UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
            // 获取客户端操作系统
            String os = userAgent.getOperatingSystem().getName();
            // 获取客户端浏览器
            String browser = userAgent.getBrowser().getName();
            session.setHost(IpUtils.getIpAddr(request));
            session.setBrowser(browser);
            session.setOs(os);
        }
    }
    return session;
}
 
Example #2
Source File: OnlineSessionFactory.java    From supplierShop with MIT License 6 votes vote down vote up
@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)
        {
            UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
            // 获取客户端操作系统
            String os = userAgent.getOperatingSystem().getName();
            // 获取客户端浏览器
            String browser = userAgent.getBrowser().getName();
            session.setHost(IpUtils.getIpAddr(request));
            session.setBrowser(browser);
            session.setOs(os);
        }
    }
    return session;
}
 
Example #3
Source File: HttpRequestSessionManager.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public Session start( SessionContext context ) throws AuthorizationException {
    if ( !WebUtils.isHttp( context ) ) {
        String msg = "SessionContext must be an HTTP compatible implementation.";
        throw new IllegalArgumentException( msg );
    }

    HttpServletRequest request = WebUtils.getHttpRequest( context );

    String host = getHost( context );

    Session session = createSession( request, host );
    request.setAttribute( REQUEST_ATTRIBUTE_KEY, session );

    return session;
}
 
Example #4
Source File: DefaultWebSessionManager.java    From nano-framework with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStart(final Session session, final SessionContext context) {
    if (!WebUtils.isHttp(context)) {
        LOGGER.debug("SessionContext argument is not HTTP compatible or does not have an HTTP request/response " +
                "pair. No session ID cookie will be set.");
        return;
    }
    
    final HttpServletRequest request = WebUtils.getHttpRequest(context);
    final HttpServletResponse response = WebUtils.getHttpResponse(context);

    if (isSessionIdCookieEnabled()) {
        final Serializable sessionId = session.getId();
        storeSessionId(sessionId, request, response);
    } else {
        LOGGER.debug("Session ID cookie is disabled.  No cookie has been set for new session with id {}", session.getId());
    }

    request.removeAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE);
    request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_IS_NEW, Boolean.TRUE);
}
 
Example #5
Source File: AbstractIamSessionManager.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStart(Session session, SessionContext context) {
	if (!WebUtils.isHttp(context)) {
		throw new IllegalStateException(String.format("IAM currently only supports HTTP protocol family!"));
	}

	HttpServletRequest request = WebUtils.getHttpRequest(context);
	HttpServletResponse response = WebUtils.getHttpResponse(context);
	if (isSessionIdCookieEnabled()) {
		if (StringUtils2.isEmpty(session.getId())) {
			throw new IllegalArgumentException("sessionId cannot be null when persisting for subsequent requests.");
		}
		// Storage session token
		saveSessionIdCookieIfNecessary(request, response, session.getId().toString());
	} else {
		log.debug("Session ID cookie is disabled.  No cookie has been set for new session with id {}", session.getId());
	}
	request.removeAttribute(REFERENCED_SESSION_ID_SOURCE);
	request.setAttribute(REFERENCED_SESSION_IS_NEW, TRUE);
}
 
Example #6
Source File: OnlineSessionFactory.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
@Override
public Session createSession(SessionContext initData) {
    OnlineSession session = new OnlineSession();
    if (initData instanceof WebSessionContext) {
        WebSessionContext sessionContext = (WebSessionContext) initData;
        HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
        if (request != null) {
            UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
            // 获取客户端操作系统
            String os = userAgent.getOperatingSystem().getName();
            // 获取客户端浏览器
            String browser = userAgent.getBrowser().getName();
            session.setHost(IpUtils.getIpAddr(request));
            session.setBrowser(browser);
            session.setOs(os);
        }
    }
    return session;
}
 
Example #7
Source File: OnlineSessionFactory.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Session createSession(SessionContext initData)
{
    OnlineSession session = new OnlineSession();
    if (initData instanceof WebSessionContext)
    {
        WebSessionContext sessionContext = (WebSessionContext) initData;
        HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
        if (request != null)
        {
            UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
            // 获取客户端操作系统
            String os = userAgent.getOperatingSystem().getName();
            // 获取客户端浏览器
            String browser = userAgent.getBrowser().getName();
            session.setHost(IpUtils.getIpAddr(request));
            session.setBrowser(browser);
            session.setOs(os);
        }
    }
    return session;
}
 
Example #8
Source File: HttpRequestSessionManager.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private String getHost( SessionContext context ) {
    String host = context.getHost();
    if ( host == null ) {
        ServletRequest request = WebUtils.getRequest( context );
        if ( request != null ) {
            host = request.getRemoteHost();
        }
    }
    return host;
}
 
Example #9
Source File: NexusSessionFactory.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Ensure {@link SimpleSessionImpl} is used and provides logging.
 */
@Override
public Session createSession(final SessionContext initData) {
  log.trace("Creating session w/init-data: {}", initData);

  // duplicated from SimpleSessionFactory, retaining class-hierarchy for sanity
  if (initData != null) {
    String host = initData.getHost();
    if (host != null) {
      return new SimpleSessionImpl(host);
    }
  }
  return new SimpleSessionImpl();
}
 
Example #10
Source File: TelegramLongPollingSessionBot.java    From TelegramBots with MIT License 5 votes vote down vote up
public Optional<Session> getSession(Message message){
    try {
        return Optional.of(sessionManager.getSession(chatIdConverter));
    } catch (UnknownSessionException e) {
        SessionContext botSession = new DefaultChatSessionContext(message.getChatId(), message.getFrom().getUserName());
        return Optional.of(sessionManager.start(botSession));
    }
}
 
Example #11
Source File: UpmsSessionFactory.java    From zheng with MIT License 5 votes vote down vote up
@Override
public Session createSession(SessionContext sessionContext) {
    UpmsSession session = new UpmsSession();
    if (null != sessionContext && sessionContext instanceof WebSessionContext) {
        WebSessionContext webSessionContext = (WebSessionContext) sessionContext;
        HttpServletRequest request = (HttpServletRequest) webSessionContext.getServletRequest();
        if (null != request) {
            session.setHost(request.getRemoteAddr());
            session.setUserAgent(request.getHeader("User-Agent"));
        }
    }
    return session;
}
 
Example #12
Source File: SessionManager.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
@Override
  public Session start(SessionContext context) {
  	try{
  		return super.start(context);
}catch (NullPointerException e) {
	SimpleSession session = new SimpleSession();
	session.setId(0);
	return session;
}
  }
 
Example #13
Source File: SessionManager.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
@Override
  protected Session doCreateSession(SessionContext context) {
  	try{
  		return super.doCreateSession(context);
}catch (IllegalStateException e) {
	return null;
}
  }
 
Example #14
Source File: SessionManager.java    From easyweb with Apache License 2.0 5 votes vote down vote up
@Override
  public Session start(SessionContext context) {
  	try{
  		return super.start(context);
}catch (NullPointerException e) {
	SimpleSession session = new SimpleSession();
	session.setId(0);
	return session;
}
  }
 
Example #15
Source File: SessionManager.java    From easyweb with Apache License 2.0 5 votes vote down vote up
@Override
  protected Session doCreateSession(SessionContext context) {
  	try{
  		return super.doCreateSession(context);
}catch (IllegalStateException e) {
	return null;
}
  }
 
Example #16
Source File: IamSessionFactory.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link SimpleSession SimpleSession} instance retaining the
 * context's {@link SessionContext#getHost() host} if one can be found.
 *
 * @param initData
 *            the initialization data to be used during {@link Session}
 *            creation.
 * @return a new {@link SimpleSession SimpleSession} instance
 */
@Override
public Session createSession(SessionContext initData) {
	if (initData != null) {
		String host = initData.getHost();
		if (host != null) {
			return new IamSession(host);
		}
	}
	return new IamSession();
}
 
Example #17
Source File: AbstractIamSessionManager.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public Session start(SessionContext context) {
	try {
		return super.start(context);
	} catch (NullPointerException e) {
		return new IamSession(0);
	}
}
 
Example #18
Source File: AbstractIamSessionManager.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
protected Session doCreateSession(SessionContext context) {
	try {
		return super.doCreateSession(context);
	} catch (IllegalStateException e) {
		// Ignore exceptions
		return null;
	}
}
 
Example #19
Source File: SessionManager.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Override
protected Session newSessionInstance(SessionContext context) {
	Session session = super.newSessionInstance(context);
	session.setTimeout(getGlobalSessionTimeout());
	return session;
}
 
Example #20
Source File: SessionManager.java    From easyweb with Apache License 2.0 4 votes vote down vote up
@Override
protected Session newSessionInstance(SessionContext context) {
	Session session = super.newSessionInstance(context);
	session.setTimeout(getGlobalSessionTimeout());
	return session;
}
 
Example #21
Source File: ShiroSessionFactory.java    From Spring-Shiro-Spark with Apache License 2.0 4 votes vote down vote up
@Override
public Session createSession(SessionContext sessionContext) {
    ShiroSession session = new ShiroSession();
    return session;
}
 
Example #22
Source File: CustomWebSessionManager.java    From jee-universal-bms with Apache License 2.0 4 votes vote down vote up
protected void onStart(Session session, SessionContext context) {
    super.onStart(session,context);
    HttpServletRequest request = WebUtils.getHttpRequest(context);
    request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE, ShiroHttpServletRequest.COOKIE_SESSION_ID_SOURCE);
}
 
Example #23
Source File: AbstractIamSessionManager.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
@Override
protected Session newSessionInstance(SessionContext context) {
	Session session = super.newSessionInstance(context);
	session.setTimeout(getGlobalSessionTimeout());
	return session;
}