Java Code Examples for org.eclipse.jetty.http.HttpCookie

Following code examples demonstrate how to use org.eclipse.jetty.http.HttpCookie from jetty. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.eclipse.jetty.http.HttpCookie and various code implementation of this class.
Example 1
Project : jetty Source File : Response.java View Source Code on GitHub

    }

    public HttpCookie getCookie(String name)
    {
        for (HttpCookie cookie : cookies) {
            if (cookie.getName().equals(name)) {
                return cookie;
            }
        }

        return null;
    }
			
Example 2
Project : jetty Source File : Response.java View Source Code on GitHub

    }

    public void addCookie(HttpCookie cookie)
    {
        HttpCookie c = getCookie(cookie.getName());
        if (null != c) {
            cookies.remove(c);
        }

        cookies.add(cookie);
    }
			
Example 3
Project : jetty Source File : TerracottaSessionHandler.java View Source Code on GitHub

    }

    public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        setRequestedId(baseRequest,request);

        SessionManager old_session_manager=null;
        HttpSession old_session=null;
        TerracottaSessionManager sessionManager = (TerracottaSessionManager)getSessionManager();
        Request currentRequest = (request instanceof Request) ? (Request)request : HttpConnection.getCurrentConnection().getRequest();
        try
        {
            old_session_manager = baseRequest.getSessionManager();
            old_session = baseRequest.getSession(false);
           
            if (old_session_manager != sessionManager)
            {
                baseRequest.setSessionManager(sessionManager);
                baseRequest.setSession(null);
            }
            if (sessionManager != null) 
                sessionManager.enter(currentRequest);
            
            HttpSession session=null;
            if (sessionManager!=null)
            {
                session=baseRequest.getSession(false);
                if (session!=null)
                {
                    if(session!=old_session)
                    {
                        HttpCookie cookie = sessionManager.access(session,request.isSecure());
                            baseRequest.getResponse().addCookie(cookie);
                    }
                }
                else
                {
                    session=baseRequest.recoverNewSession(sessionManager);
                    if (session!=null)
                        baseRequest.setSession(session);
                }
            }

            if(Log.isDebugEnabled())
            {
                Log.debug("sessionManager="+sessionManager);
                Log.debug("session="+session);
            }

            if (false)
                nextScope(target,baseRequest,request,response);
            else if (_nextScope!=null)
                _nextScope.doScope(target,baseRequest,request, response);
            else if (_outerScope!=null)
                _outerScope.doHandle(target,baseRequest,request, response);
            else 
                doHandle(target,baseRequest,request, response);

        }
        finally
        {
            HttpSession session=request.getSession(false);
            if (sessionManager != null)
            {
                HttpSession currentSession = currentRequest.getSession(false);
                if (currentSession != null) 
                    sessionManager.complete(currentSession);

                sessionManager.exit(currentRequest);
            }
            
            if (old_session_manager != sessionManager)
            {
                if (session!=null)
                    sessionManager.complete(session);
                baseRequest.setSessionManager(old_session_manager);
                baseRequest.setSession(old_session);
            }
        }
    }
			
Example 4
Project : jetty Source File : AuthenticatedEncryptedCookieFactory.java View Source Code on GitHub

  public NewCookie cookieFor(String value, ZonedDateTime expiration) {
    long maxAge = Duration.between(ZonedDateTime.now(clock), expiration).getSeconds();

    HttpCookie cookie = new HttpCookie(config.getName(), value, config.getDomain(),
        config.getPath(), maxAge, config.isHttpOnly(), config.isSecure());

    Response response = newResponse();
    response.addCookie(cookie);
    return NewCookie.valueOf(response.getHttpFields().get(HttpHeader.SET_COOKIE));
  }
			
Example 5
Project : jetty Source File : AuthenticatedEncryptedCookieFactory.java View Source Code on GitHub

  public NewCookie getExpiredSessionCookie() {
    HttpCookie cookie = new HttpCookie(config.getName(), "expired", config.getDomain(), config.getPath(),
        0, config.isHttpOnly(), config.isSecure());

    Response response = newResponse();
    response.addCookie(cookie);
    return NewCookie.valueOf(response.getHttpFields().getStringField(HttpHeader.SET_COOKIE));
  }
			
Example 6
Project : jetty Source File : InfinispanSessionManagerTest.java View Source Code on GitHub

    public void getSessionCookie() throws Exception {
        HttpSession session = ism.newHttpSession(req());
        HttpCookie cookie = ism.getSessionCookie(session, "/", false);
        assertEquals(ism.getSessionCookieConfig().getName(), cookie.getName());
        assertEquals(session.getId(), cookie.getValue());
        assertEquals(ism.getSessionCookieConfig().getDomain(), cookie.getDomain());
        assertEquals("/", cookie.getPath());
        assertEquals(ism.getSessionCookieConfig().getMaxAge(), cookie.getMaxAge());
        assertEquals(ism.getHttpOnly(), cookie.isHttpOnly());
        assertFalse(cookie.isSecure());
    }
			
Example 7
Project : jetty Source File : SessionCookieTest.java View Source Code on GitHub

    @Test
    public void testSecureSessionCookie () throws Exception
    {
        Server server = new Server();
        MockSessionIdManager idMgr = new MockSessionIdManager(server);
        idMgr.setWorkerName("node1");
        SessionHandler mgr = new SessionHandler();
        MockSessionStore store = new MockSessionStore(mgr);
        store.setSessionDataStore(new NullSessionDataStore());
        mgr.setSessionCache(store);
        mgr.setSessionIdManager(idMgr);
        
        long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
        
        Session session = new Session(mgr, new SessionData("123", "_foo", "0.0.0.0", now, now, now, 30)); 

        SessionCookieConfig sessionCookieConfig = mgr.getSessionCookieConfig();
        sessionCookieConfig.setSecure(true);

        HttpCookie cookie = mgr.getSessionCookie(session, "/foo", true);
        assertTrue(cookie.isSecure());
        cookie = mgr.getSessionCookie(session, "/foo", false);
        assertTrue(cookie.isSecure());

        sessionCookieConfig.setSecure(false);
        cookie = mgr.getSessionCookie(session, "/foo", true);
        assertTrue(cookie.isSecure());

        cookie = mgr.getSessionCookie(session, "/foo", false);
        assertFalse(cookie.isSecure());

        mgr.setSecureRequestOnly(false);
        cookie = mgr.getSessionCookie(session, "/foo", false);
        assertFalse(cookie.isSecure());

        cookie = mgr.getSessionCookie(session, "/foo", true);
        assertFalse(cookie.isSecure());
    }