Package org.tamacat.httpd.session

Examples of org.tamacat.httpd.session.Session


      if (path.endsWith(loginPageUrl)) {
        logoutAction(request, sessionId);
        return;
      } else if (isFreeAccessExtensions(path)) {
        if (sessionId != null) {
          Session session = SessionManager.getInstance().getSession(sessionId, false);
          if (session != null) {
            remoteUser = (String) session.getAttribute(sessionUsernameKey);
            if (remoteUser != null) {
              context.setAttribute(remoteUserKey, remoteUser);
            }
          }
        }
        return; //skip by this filter.
      } else if (isMatchLoginUrl(request)) {
        //login check
        remoteUser = checkUser(request, context);
        context.setAttribute(remoteUserKey, remoteUser);
        Session session = SessionManager.getInstance().createSession();
        session.setAttribute(sessionUsernameKey, remoteUser);
        response.setHeader("Set-Cookie", sessionCookieName + "=" + session.getId() + "; Path=/");
        context.setAttribute(SC_AUTHORIZED, Boolean.TRUE);
      } else if (StringUtils.isNotEmpty(sessionId)) {
        //already login. -> session check
        Session session = SessionManager.getInstance().getSession(sessionId, false);
        if (session == null) { //invalid session.
          throw new UnauthorizedException();
        }
        remoteUser = (String) session.getAttribute(sessionUsernameKey);
        if (remoteUser == null) { //invalid session.
          throw new UnauthorizedException();
        }
        context.setAttribute(remoteUserKey, remoteUser);
        if (path.endsWith(logoutActionUrl)) {
View Full Code Here


  @Override
  public void doFilter(HttpRequest request, HttpResponse response,
      HttpContext context) {
    Header[] headers = request.getHeaders("Cookie");
    synchronized(MANAGER) {
      Session session = null;
      if (headers != null) {
        for (Header header : headers) {
          String id = HeaderUtils.getCookieValue(
            header.getValue(), getSessionCookieName());
          if (StringUtils.isNotEmpty(id)) {
            session = MANAGER.getSession(id, false);
            break;
          }
        }
      }
      if (session == null) {
        session = MANAGER.createSession();
        response.addHeader("Set-Cookie",
          getSessionCookieName() + "=" + session.getId() + "; Path=/");
        request.addHeader("Cookie",
          getSessionCookieName() + "=" + session.getId()); //for ReverseProxy
      }
      context.setAttribute(SESSION_ATTRIBUTE_KEY, session);
    }
  }
View Full Code Here

   * Logout the system with invalidate this session.
   * @param sessionId
   */
  protected void logoutAction(HttpRequest request, String sessionId) {
    if (StringUtils.isNotEmpty(sessionId)) {
      Session session = SessionManager.getInstance().getSession(sessionId, false);
      if (session != null) {
        session.invalidate();
      }
    }
  }
View Full Code Here

  public void testDoFilter() {
    HttpRequest request = HttpObjectFactory.createHttpRequest("GET", "/test/");
    HttpResponse response = HttpObjectFactory.createHttpResponse(200, "OK");
    HttpContext context = HttpObjectFactory.createHttpContext();
    filter.doFilter(request, response, context);
    Session session = (Session) context.getAttribute(SESSION_ATTRIBUTE_KEY);
    assertNotNull(session);
    assertNotNull(session.getId());
    assertEquals("Session=" + session.getId() + "; Path=/",
        response.getFirstHeader("Set-Cookie").getValue());
  }
View Full Code Here

TOP

Related Classes of org.tamacat.httpd.session.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.