Examples of IPortalCookie


Examples of org.jasig.portal.portlet.om.IPortalCookie

    Cookie [] cookies = new Cookie[1];
    Cookie cookie = new Cookie(IPortletCookieService.DEFAULT_PORTAL_COOKIE_NAME, "ABCDEF");
    cookies[0] = cookie;
    request.setCookies(cookies);
   
    IPortalCookie result = cookieService.getOrCreatePortalCookie(request);
    Assert.assertEquals(portalCookie, result);
    EasyMock.verify(portletCookieDao);
  }
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

    cookieService.setPortletCookieDao(portletCookieDao);
   
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(PortletCookieServiceImpl.SESSION_ATTRIBUTE__PORTAL_COOKIE_ID, "ABCDEF");
   
    IPortalCookie result = cookieService.getOrCreatePortalCookie(request);
    Assert.assertEquals(portalCookie, result);
    EasyMock.verify(portletCookieDao);
  }
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

  @Test
  public void testPortalCookieLifeCycle() {
        final String value = this.execute(new Callable<String>() {
            @Override
            public String call() throws Exception {
            final IPortalCookie portalCookie = portletCookieDao.createPortalCookie(1);
            assertNotNull(portalCookie);
           
            final String cookieValue = portalCookie.getValue();
            assertNotNull(cookieValue);
            assertEquals(40, cookieValue.length());
            assertEquals(0, portalCookie.getPortletCookies().size());
            assertNotNull(portalCookie.getCreated());
            assertNotNull(portalCookie.getExpires());
           
            return cookieValue;
            }
        });

        this.execute(new Callable<String>() {
            @Override
            public String call() throws Exception {
                final IPortalCookie portalCookie = portletCookieDao.getPortalCookie(value);
                assertNotNull(portalCookie);
               
                Cookie cookie2 = new Cookie("cookieName2", "cookieValue2");
               
                portletCookieDao.addOrUpdatePortletCookie(portalCookie, cookie2);
               
                return null;
            }
        });

        this.execute(new Callable<String>() {
            @Override
            public String call() throws Exception {
                final IPortalCookie portalCookie = portletCookieDao.getPortalCookie(value);
                assertNotNull(portalCookie);
               
                long expirationDelay = portalCookie.getExpires().getMillis() - System.currentTimeMillis();
                if (expirationDelay > 0) {
                    Thread.sleep(Math.max(500, expirationDelay));
                }
               
                portletCookieDao.purgeExpiredCookies(1);
               
                return null;
            }
        });

        this.execute(new Callable<String>() {
            @Override
            public String call() throws Exception {
                final IPortalCookie portalCookie = portletCookieDao.getPortalCookie(value);
                assertNull(portalCookie);
               
                return null;
            }
        });
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

     * @see org.jasig.portal.portlet.container.services.IPortletCookieService#updatePortalCookie(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    @Override
    public void updatePortalCookie(HttpServletRequest request, HttpServletResponse response) {
        //Get the portal cookie object
        final IPortalCookie portalCookie = this.getOrCreatePortalCookie(request);
       
        //Create the browser cookie
        final Cookie cookie = this.convertToCookie(portalCookie, this.portalCookieAlwaysSecure || request.isSecure());
       
        //Update the expiration date of the portal cookie stored in the DB if the update interval has passed
        final DateTime expires = portalCookie.getExpires();
        if (DateTime.now().minusMillis(this.maxAgeUpdateInterval).isAfter(expires.minusSeconds(this.maxAge))) {
            this.portletCookieDao.updatePortalCookieExpiration(portalCookie, cookie.getMaxAge());
           
            // Update expiration dates of portlet cookies stored in session
            removeExpiredPortletCookies(request);
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

     }
   }
   
    @Override
    public Cookie[] getAllPortletCookies(HttpServletRequest request, IPortletWindowId portletWindowId) {
      final IPortalCookie portalCookie = this.getPortalCookie(request);
      
      //Get the cookies from the servlet request
        Cookie[] servletCookies = request.getCookies();
        if (servletCookies == null) {
            servletCookies = new Cookie[0];
        } else if(portalCookie != null) {
          for(int i=0; i< servletCookies.length; i++) {
            if(servletCookies[i].getName().equals(this.cookieName)) {
              // replace cookie in the array with converted IPortalCookie (so secure, domain, path, maxAge are set)
              servletCookies[i] = convertToCookie(portalCookie, this.portalCookieAlwaysSecure || request.isSecure());
            }
          }
        }
       
        //Get cookies that have been set by portlets, suppressing expired
        Set<IPortletCookie> portletCookies = new HashSet<IPortletCookie>();
        if(portalCookie != null) {
          for(IPortletCookie portletCookie: portalCookie.getPortletCookies()) {
            if(portletCookie.getExpires().isAfterNow()) {
              portletCookies.add(portletCookie);
            }
          }
        }
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

        return cookies;
    }
   
    @Override
    public void addCookie(HttpServletRequest request, IPortletWindowId portletWindowId, Cookie cookie) {
        final IPortalCookie portalCookie = this.getOrCreatePortalCookie(request);
        if(cookie.getMaxAge() < 0) {
          // persist only in the session
            Map<String, SessionOnlyPortletCookieImpl> sessionOnlyPortletCookies = getSessionOnlyPortletCookieMap(request);
            SessionOnlyPortletCookieImpl sessionOnlyCookie = new SessionOnlyPortletCookieImpl(cookie);
            sessionOnlyPortletCookies.put(cookie.getName(), sessionOnlyCookie);
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

      synchronized(WebUtils.getSessionMutex(session)) {
        final String portalCookieId = (String) session.getAttribute(SESSION_ATTRIBUTE__PORTAL_COOKIE_ID);
        if(portalCookieId == null) {
          return null;
        }
        IPortalCookie portalCookie = this.portletCookieDao.getPortalCookie(portalCookieId);
        return portalCookie;
      }
    }
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

     *
     * @param request
     * @return the {@link IPortalCookie} - never null
     */
    protected IPortalCookie getOrCreatePortalCookie(HttpServletRequest request) {
      IPortalCookie result = null;
     
      // first check in request
        final Cookie cookie = this.getCookieFromRequest(this.cookieName, request);
        if (cookie != null) {
          // found a potential cookie, call off to the dao
          final String value = cookie.getValue();
          result = this.portletCookieDao.getPortalCookie(value);
        }
       
        // still null? check in the session
        if(result == null) {
          result = locatePortalCookieInSession(request.getSession());
        }
        // if by this point we still haven't found the portal cookie, create one
        if(result == null) {
          result = this.portletCookieDao.createPortalCookie(this.maxAge);
          // store the portal cookie value value in the session
          HttpSession session = request.getSession();
          synchronized(WebUtils.getSessionMutex(session)) {
            session.setAttribute(SESSION_ATTRIBUTE__PORTAL_COOKIE_ID, result.getValue());
          }
        }
       
        return result;
    }
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

     */
    protected IPortalCookie getPortalCookie(HttpServletRequest request) {
        final Cookie cookie = this.getCookieFromRequest(this.cookieName, request);
        if (cookie == null) {
          // check the session
          IPortalCookie portalCookieInSession = locatePortalCookieInSession(request.getSession());
          if(null != portalCookieInSession) {
            return  portalCookieInSession;
          }

        return null;
View Full Code Here

Examples of org.jasig.portal.portlet.om.IPortalCookie

   
    //Calculate the expiration date for the cookie
    final DateTime expiration = DateTime.now().plusSeconds(maxAge);
   
    //Create and persist
    final IPortalCookie portalCookie = new PortalCookieImpl(uniqueId, expiration);
    this.getEntityManager().persist(portalCookie);
   
    return portalCookie;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.