use of org.jaffa.presentation.portlet.session.UserSession in project jaffa-framework by jaffa-projects.
the class ContextManager method getSessionContext.
/**
* Create a session context and adds in the following entries
* <ul>
* <li>user.id (java.lang.String) ID of authenticated user
* <li>user.principal (java.security.Principal) authenticated user's principal
* <li>user.hostname (java.lang.String) Name of host user is comming from
* <li>user.data (java.lang.Object) custom object that can be bound to a user's profile at logon
* <li>user.sessionId (java.lang.String)
* <li>user.locale (java.lang.String) Locale of the user, default to local of server if not available
* <li>user.variation (java.lang.String) Varition applicable to this user. Defined at logon
* </ul>
*
* @param request the request being processed.
* @return the session context.
*/
private Map getSessionContext(HttpServletRequest request) {
if (request != null && UserSession.isUserSession(request)) {
UserSession us = UserSession.getUserSession(request);
HashMap h = new HashMap();
h.put(PROPERTY_USER_ID, us.getUserId());
h.put(PROPERTY_USER_PRINCIPAL, request.getUserPrincipal());
h.put(PROPERTY_USER_HOSTNAME, us.getUserHostAddr());
h.put(PROPERTY_USER_DATA, us.getUserData());
h.put(PROPERTY_USER_SESSION_ID, us.getSessionId());
h.put(PROPERTY_USER_LOCALE, request.getLocale());
h.put(PROPERTY_USER_VARIATION, us.getVariation());
return h;
} else {
return null;
}
}
use of org.jaffa.presentation.portlet.session.UserSession in project jaffa-framework by jaffa-projects.
the class GridTag method otherDoStartTagOperations.
/**
* Sets the GridModel and an iterator on the rows of the GridModel.
*/
public void otherDoStartTagOperations() throws JspException {
super.otherDoStartTagOperations();
// Ensure a correct value is passed in outputType
if (m_outputType == null)
m_outputType = OUTPUT_TYPE_WEB_PAGE;
else if (!OUTPUT_TYPE_WEB_PAGE.equals(m_outputType) && !OUTPUT_TYPE_EXCEL.equals(m_outputType) && !OUTPUT_TYPE_XML.equals(m_outputType))
throw new IllegalArgumentException("Illegal outputType '" + m_outputType + "' passed to the " + TAG_NAME + ". Valid values are " + OUTPUT_TYPE_WEB_PAGE + ',' + OUTPUT_TYPE_EXCEL + ',' + OUTPUT_TYPE_XML);
// The grid tag cannot be enclosed withing another tag !!!
if (TagHelper.isEnclosed(pageContext)) {
String str = "The " + TAG_NAME + " cannot be enclosed within another tag";
log.error(str);
throw new TagCannotBeEnclosedRuntimeException(str);
}
// Store the Original Attributes
m_originalAttributes = TagHelper.getOriginalAttributes(pageContext);
// Get the formtag from the page & register the widget
FormTag formTag = TagHelper.getFormTag(pageContext);
if (formTag == null) {
String str = "The " + TAG_NAME + " should be inside a FormTag";
log.error(str);
throw new OuterFormTagMissingRuntimeException(str);
}
// Get the model
try {
m_model = (GridModel) TagHelper.getModel(pageContext, getField(), TAG_NAME);
} catch (ClassCastException e) {
String str = "Wrong WidgetModel for " + TAG_NAME + " on field " + getField();
log.error(str, e);
throw new JspWriteRuntimeException(str, e);
}
if (m_model != null) {
Collection rows = m_model.getRows();
if (rows != null && rows.size() > 0) {
m_hasRows = true;
m_modelIterator = rows.iterator();
}
}
if (isUserGrid()) {
// raise an error, if the error-flag is set on the model
if (m_model.getErrorInSavingUserSettings()) {
TagHelper.getFormBase(pageContext).raiseError((HttpServletRequest) pageContext.getRequest(), ActionMessages.GLOBAL_MESSAGE, "error.widgets.usergrid.savefailed");
m_model.setErrorInSavingUserSettings(false);
}
// See if there are any user configuration settings available for this user and grid.
UserSession us = UserSession.getUserSession((HttpServletRequest) pageContext.getRequest());
UserGridManager userGridManager = new UserGridManager();
// returns null if no configuration settings are found.
m_selectedCols = userGridManager.getColSettings(us.getUserId(), getUserGridId());
// @todo: There was legacy code at this point as we used to store translated labels
// in the XML files. We have for a while now, only stored labels. This TODO is to add
// back in the legacy support...if the need arises.
}
// Determine based on widget type and Context rules if user has disabled hints
if (!m_popupHintsSet) {
m_popupHints = isUserGrid();
String rule = isUserGrid() ? RULE_USERGRID_POPUP : RULE_GRID_POPUP;
String popupHints = (String) ContextManagerFactory.instance().getProperty(rule);
if (popupHints != null)
m_popupHints = Boolean.valueOf(popupHints).booleanValue();
log.debug("popupHints (from rule: " + rule + ") defaults to " + m_popupHints);
}
}
use of org.jaffa.presentation.portlet.session.UserSession in project jaffa-framework by jaffa-projects.
the class ApplicationResourceLoaderTest method setup.
/**
* setting the up objects/properties before a Test is run
* @throws Exception
*/
@Before
public void setup() throws Exception {
ApplicationResourcesManager applicationResourcesManager = resourceLoaderConfig.getBean(ApplicationResourcesManager.class);
MockHttpServletRequest request = new MockHttpServletRequest();
// creating user session
UserSession us = UserSession.getUserSession(request);
us.setUserId("USER");
us.setVariation("NULL");
// creating mock http session for the same use session
MockHttpSession session = new MockHttpSession();
session.setAttribute("org.jaffa.presentation.portlet.session.UserInfo", us);
// setting the mock session into request
request.setSession(session);
ContextManagerFactory.instance().setThreadContext(request);
String overrideFileDir = ClassLoader.getSystemResource("ApplicationResourcesOverride.properties").getFile();
overrideFileDir = overrideFileDir.substring(1, overrideFileDir.lastIndexOf("/"));
ContextManagerFactory.instance().setProperty("data.directory", overrideFileDir);
}
use of org.jaffa.presentation.portlet.session.UserSession in project jaffa-framework by jaffa-projects.
the class ContextManagerTest method testContextManager.
/**
* testContextManager - Verifies that the application rules have been loaded correctly for both global and variation
* specific rules files.
*
* @throws Exception
*/
@Test
public void testContextManager() throws Exception {
ApplicationRulesManager applicationRulesManager = xmlLoaderConfig.getBean(ApplicationRulesManager.class);
assertNotNull(applicationRulesManager.getApplicationRulesRepository());
MockHttpServletRequest request = new MockHttpServletRequest();
// creating user session
UserSession us = UserSession.getUserSession(request);
us.setUserId(USER);
us.setVariation(VARIATION);
// creating mock http session for the same use session
MockHttpSession session = new MockHttpSession();
session.setAttribute(USER_ATTRIBUTE, us);
// setting the mock session into request
request.setSession(session);
ContextManagerFactory.instance().setThreadContext(request);
// Property from global
IContextManager iContextManager = ContextManagerFactory.instance();
assertNotNull(iContextManager.getProperty("org.jaffa.config.global"));
assertNull(iContextManager.getProperty("nonExistentKey"));
// Property from variation
assertNotNull(iContextManager.getProperty("org.jaffa.config.variation"));
// Property from variation
assertEquals("true", iContextManager.getProperty("org.jaffa.config.hidepanel"));
// Property from variation
assertEquals("true", iContextManager.getProperty("org.jaffa.config.hidemaintenancepanel"));
assertEquals("datadist_root/outbound", iContextManager.getProperty("datadist.outboundFolder"));
assertEquals("datadist_root/outbound/fragments", iContextManager.getProperty("datadist.outboundFolder.fragments"));
assertEquals("c:/test/interfaces_root/outbound/test", iContextManager.getProperty("interfaces.outboundTestFolder"));
assertEquals("http://pentaho_host.mypentaho.com:80967/pentaho", iContextManager.getProperty("pentaho.url"));
assertEquals("C:/apache-tomcat-8.5.16/server/Goldesp/conf/report-security.txt", iContextManager.getProperty("usersecurity.reportsecurity.securityFilterKeyFile"));
}
Aggregations