use of org.apereo.portal.portlet.om.IPortalCookie in project uPortal by Jasig.
the class PortletCookieServiceImpl method updatePortalCookie.
/**
* (non-Javadoc)
*
* @see
* org.apereo.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))) {
try {
this.portletCookieDao.updatePortalCookieExpiration(portalCookie, cookie.getMaxAge());
} catch (HibernateOptimisticLockingFailureException e) {
// Especially with ngPortal UI multiple requests for individual portlet content may
// come at
// the same time. Sometimes another thread updated the portal cookie between our
// dao fetch and
// dao update. If this happens, simply ignore the update since another thread has
// already
// made the update.
logger.debug("Attempted to update expired portal cookie but another thread beat me to it." + " Ignoring update since the other thread handled it.");
return;
}
// Update expiration dates of portlet cookies stored in session
removeExpiredPortletCookies(request);
}
// Update the cookie in the users browser
response.addCookie(cookie);
}
use of org.apereo.portal.portlet.om.IPortalCookie in project uPortal by Jasig.
the class PortletCookieServiceImpl method convertToCookie.
/**
* Convert the {@link IPortalCookie} into a servlet {@link Cookie}.
*
* @param portalCookie
* @return
*/
protected Cookie convertToCookie(IPortalCookie portalCookie, boolean secure) {
final Cookie cookie = new Cookie(this.cookieName, portalCookie.getValue());
// Set the cookie's fields
cookie.setComment(this.comment);
cookie.setMaxAge(this.maxAge);
cookie.setSecure(secure);
cookie.setHttpOnly(true);
if (this.domain != null) {
cookie.setDomain(this.domain);
}
cookie.setPath(this.path);
return cookie;
}
use of org.apereo.portal.portlet.om.IPortalCookie in project uPortal by Jasig.
the class PortletCookieServiceImpl method getOrCreatePortalCookie.
/**
* Locate the existing {@link IPortalCookie} with the request, or create a new one.
*
* @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;
}
use of org.apereo.portal.portlet.om.IPortalCookie in project uPortal by Jasig.
the class PortletCookieServiceImpl method locatePortalCookieInSession.
/**
* Check the {@link HttpSession} for the ID of the Portal Cookie. This is useful if the customer
* does not wish to accept cookies.
*
* @param session
* @return
*/
protected IPortalCookie locatePortalCookieInSession(HttpSession session) {
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;
}
}
use of org.apereo.portal.portlet.om.IPortalCookie in project uPortal by Jasig.
the class PortletCookieServiceImpl method getPortalCookie.
/**
* Get THE {@link IPortalCookie} from the {@link HttpServletRequest}, if it exists. Gracefully
* returns null if not in the request.
*
* @param request
* @return
*/
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;
}
final String value = cookie.getValue();
return this.portletCookieDao.getPortalCookie(value);
}
Aggregations