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;
}
}
}
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();
}
}
}
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);
}
}
}
Aggregations