Search in sources :

Example 1 with PortletFilter

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;
        }
    }
}
Also used : UOWException(org.jaffa.persistence.exceptions.UOWException) FrameworkException(org.jaffa.exceptions.FrameworkException) IOException(java.io.IOException) UserSessionSetupException(org.jaffa.presentation.portlet.session.UserSessionSetupException) UserSessionSetupException(org.jaffa.presentation.portlet.session.UserSessionSetupException) PortletFilter(org.jaffa.presentation.portlet.PortletFilter)

Aggregations

IOException (java.io.IOException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 UOWException (org.jaffa.persistence.exceptions.UOWException)1 PortletFilter (org.jaffa.presentation.portlet.PortletFilter)1 UserSessionSetupException (org.jaffa.presentation.portlet.session.UserSessionSetupException)1