throw new RuntimeException(e);
}
}
protected void establishThinRequestContext() {
BroadleafRequestContext oldBrc = BroadleafRequestContext.getBroadleafRequestContext();
if (oldBrc == null || oldBrc.getSite() == null || oldBrc.getTheme() == null) {
// Resolving sites and sandboxes is often dependent on having a security context present in the request.
// For example, resolving a sandbox requires the current user to have the BLC_ADMIN_USER in his Authentication.
// For performance reasons, we do not go through the entire Spring Security filter chain on requests
// for resources like JavaScript and CSS files. However, when theming is enabled, we potentially have to
// resolve a specific version of the theme for a sandbox so that we can replace variables appropriately. This
// then depends on the sandbox being resolved, which requires the Authentication object to be present.
// We will grab the Authentication object associated with this user's session and set it on the
// SecurityContextHolder since Spring Security will be bypassed.
HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = req.getSession(false);
SecurityContext ctx = readSecurityContextFromSession(session);
if (ctx != null) {
SecurityContextHolder.setContext(ctx);
}
BroadleafRequestContext newBrc = new BroadleafRequestContext();
if (!isGlobalAdmin(req)) {
ServletWebRequest swr = new ServletWebRequest(req);
newBrc.setSite(siteResolver.resolveSite(swr, true));
newBrc.setSandBox(sbResolver.resolveSandBox(swr, newBrc.getSite()));
BroadleafRequestContext.setBroadleafRequestContext(newBrc);
newBrc.setTheme(themeResolver.resolveTheme(swr));
}
}
}