use of org.apereo.portal.portlet.om.IPortletCookie in project uPortal by Jasig.
the class PortletCookieServiceImpl method getAllPortletCookies.
@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);
}
}
}
// finally get portlet cookies from session (all maxAge -1)
Map<String, SessionOnlyPortletCookieImpl> sessionOnlyPortletCookieMap = getSessionOnlyPortletCookieMap(request);
Collection<SessionOnlyPortletCookieImpl> sessionOnlyCookies = sessionOnlyPortletCookieMap.values();
// Merge into a single array
final Cookie[] cookies = new Cookie[servletCookies.length + portletCookies.size() + sessionOnlyCookies.size()];
System.arraycopy(servletCookies, 0, cookies, 0, servletCookies.length);
int cookieIdx = servletCookies.length;
for (final IPortletCookie portletCookie : portletCookies) {
final Cookie cookie = portletCookie.toCookie();
cookies[cookieIdx++] = cookie;
}
for (SessionOnlyPortletCookieImpl sessionOnlyCookie : sessionOnlyCookies) {
cookies[cookieIdx++] = sessionOnlyCookie.toCookie();
}
return cookies;
}
use of org.apereo.portal.portlet.om.IPortletCookie in project uPortal by Jasig.
the class JpaPortletCookieDaoImpl method addOrUpdatePortletCookie.
/*
* (non-Javadoc)
* @see org.apereo.portal.portlet.dao.IPortletCookieDao#updatePortletCookie(org.apereo.portal.portlet.om.IPortalCookie, javax.servlet.http.Cookie)
*/
@Override
@PortalTransactional
public IPortalCookie addOrUpdatePortletCookie(IPortalCookie portalCookie, Cookie cookie) {
final Set<IPortletCookie> portletCookies = portalCookie.getPortletCookies();
boolean found = false;
final String name = cookie.getName();
final EntityManager entityManager = this.getEntityManager();
for (final Iterator<IPortletCookie> portletCookieItr = portletCookies.iterator(); portletCookieItr.hasNext(); ) {
final IPortletCookie portletCookie = portletCookieItr.next();
if (name.equals(portletCookie.getName())) {
// Delete cookies with a maxAge of 0
if (cookie.getMaxAge() == 0) {
portletCookieItr.remove();
entityManager.remove(portletCookie);
} else {
portletCookie.updateFromCookie(cookie);
}
found = true;
break;
}
}
if (!found) {
IPortletCookie newPortletCookie = new PortletCookieImpl(portalCookie, cookie);
portletCookies.add(newPortletCookie);
}
entityManager.persist(portalCookie);
return portalCookie;
}
Aggregations