use of org.jaffa.presentation.portlet.PortletFilter in project jaffa-framework by jaffa-projects.
the class UserContextWrapper method initializeUserContext.
/**
* Loads user information into the thread context
*
* @param portletFilterClass defined the version of the PortletFilter class to use during setup
* @throws UserSessionSetupException if any error occurs while creating a UserSession for the user.
*/
private void initializeUserContext(Class portletFilterClass) throws UserSessionSetupException {
try {
if (log.isDebugEnabled()) {
log.debug("Creating ThreadContext For User " + userContext.getUserId() + " with PortletFilter " + portletFilterClass);
}
if (portletFilterClass == null) {
portletFilterClass = PortletFilter.class;
}
PortletFilter pf = (PortletFilter) portletFilterClass.newInstance();
// Read the roles from the database if they are not already defined
if (userContext.getRoles() == null) {
userContext.setRoles(readUserRoles(userContext.getUserId()));
}
// Create a Mock Request
m_request = new MockHttpServletRequest(userContext.getUserId(), userContext.getRoles());
// Set security context
SecurityTag.setThreadContext(m_request);
// Create a user session and initialize
pf.autoAuthenticate(m_request, userContext, false);
// Set Variation and Locale Context
pf.setContexts(m_request);
// Set Context Manager
ContextManagerFactory.instance().setThreadContext(m_request);
} catch (Exception e) {
if (!(e instanceof UserSessionSetupException)) {
log.error("Can't Set up UserContext", e);
throw new UserSessionSetupException(new String[] { userContext.getUserId() }, e);
} else {
throw (UserSessionSetupException) e;
}
}
}
Aggregations