Search in sources :

Example 1 with UserSessionSetupException

use of org.jaffa.presentation.portlet.session.UserSessionSetupException 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)

Example 2 with UserSessionSetupException

use of org.jaffa.presentation.portlet.session.UserSessionSetupException in project jaffa-framework by jaffa-projects.

the class GraphCreateThread method run.

@Override
public void run() {
    UserContextWrapper ucw = null;
    ApplicationExceptions appExps = new ApplicationExceptions();
    try {
        synchronized (this) {
            ucw = UserContextWrapperFactory.instance(userId);
        }
        List<GraphDataObject> graphs = new ArrayList<GraphDataObject>();
        graphs.add(this.graph);
        GraphService service = (GraphService) serviceClazz.newInstance();
        Object graphArray = Array.newInstance(graph.getClass(), 1);
        Array.set(graphArray, 0, graph);
        Method m = serviceClazz.getDeclaredMethod("update", graphArray.getClass());
        GraphUpdateResponse[] responses = (GraphUpdateResponse[]) m.invoke(serviceClazz.newInstance(), graphArray);
        if (responses != null && responses.length > 0) {
            for (GraphUpdateResponse response : responses) {
                ServiceError[] faults = response.getErrors();
                if (faults != null && faults.length > 0) {
                    for (ServiceError fault : faults) {
                        appExps.add(new ApplicationException("error", new String[] { fault.getLocalizedMessage() }));
                    }
                }
                synchronized (this) {
                    test.getUpdateResponses().add(response);
                }
            }
        }
        if (appExps.size() > 0)
            throw appExps;
    } catch (ApplicationExceptions | UserSessionSetupException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        log.error(e);
    } finally {
        synchronized (this) {
            if (ucw != null)
                ucw.unsetContext();
        }
    }
}
Also used : ServiceError(org.jaffa.soa.graph.ServiceError) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) GraphDataObject(org.jaffa.soa.graph.GraphDataObject) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) UserSessionSetupException(org.jaffa.presentation.portlet.session.UserSessionSetupException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GraphService(org.jaffa.soa.dataaccess.GraphService) ApplicationException(org.jaffa.exceptions.ApplicationException) UserContextWrapper(org.jaffa.modules.user.services.UserContextWrapper) GraphDataObject(org.jaffa.soa.graph.GraphDataObject) GraphUpdateResponse(org.jaffa.soa.graph.GraphUpdateResponse)

Example 3 with UserSessionSetupException

use of org.jaffa.presentation.portlet.session.UserSessionSetupException in project jaffa-framework by jaffa-projects.

the class PortletFilter method autoAuthenticate.

/**
 * On entry it is assumed that there is no UserSession record. If there are some
 * special reasons for a UserSession to be automatically created, this is the place
 * to do it.
 *
 * On exit from this method, if a UserSession object has been created, it assumes that
 * this is an authenticated Session.
 *
 * @param request HttpRequest that holds any log in context information
 * @param userContext holds any log in context information
 * @param register that lets you register the current session to SessionManager
 */
public void autoAuthenticate(HttpServletRequest request, UserContext userContext, boolean register) throws IOException, ServletException {
    // Make sure there is an authenticated user
    if (request.getUserPrincipal() != null) {
        // This will create a new session if one doesn't exist
        UserSession us = UserSession.getUserSession(request, register);
        us.setUserId(request.getUserPrincipal().getName());
        try {
            if (userContext == null) {
                initUserInfo(us);
            } else {
                initUserInfo(us, userContext);
            }
        } catch (UserSessionSetupException e) {
            ApplicationExceptions appExps = new ApplicationExceptions();
            appExps.add(e);
            // This exception can be picked by some generic error-handling JSP, which will loop thru the ApplicationException objects inside the ApplicationExceptions, printing the corresponding error message.
            throw new ServletException("Error in initializing the UserSession. " + e, appExps);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) UserSession(org.jaffa.presentation.portlet.session.UserSession) UserSessionSetupException(org.jaffa.presentation.portlet.session.UserSessionSetupException)

Aggregations

UserSessionSetupException (org.jaffa.presentation.portlet.session.UserSessionSetupException)3 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 UserContextWrapper (org.jaffa.modules.user.services.UserContextWrapper)1 UOWException (org.jaffa.persistence.exceptions.UOWException)1 PortletFilter (org.jaffa.presentation.portlet.PortletFilter)1 UserSession (org.jaffa.presentation.portlet.session.UserSession)1 GraphService (org.jaffa.soa.dataaccess.GraphService)1 GraphDataObject (org.jaffa.soa.graph.GraphDataObject)1 GraphUpdateResponse (org.jaffa.soa.graph.GraphUpdateResponse)1 ServiceError (org.jaffa.soa.graph.ServiceError)1