Search in sources :

Example 6 with UserSession

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;
    }
}
Also used : UserSession(org.jaffa.presentation.portlet.session.UserSession)

Example 7 with UserSession

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);
    }
}
Also used : JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) UserSession(org.jaffa.presentation.portlet.session.UserSession) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) TagCannotBeEnclosedRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.TagCannotBeEnclosedRuntimeException) UserGridManager(org.jaffa.presentation.portlet.widgets.controller.UserGridManager)

Example 8 with UserSession

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);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UserSession(org.jaffa.presentation.portlet.session.UserSession) ApplicationResourcesManager(org.jaffa.loader.config.ApplicationResourcesManager) MockHttpSession(org.springframework.mock.web.MockHttpSession) Before(org.junit.Before)

Example 9 with UserSession

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"));
}
Also used : ApplicationRulesManager(org.jaffa.loader.config.ApplicationRulesManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UserSession(org.jaffa.presentation.portlet.session.UserSession) MockHttpSession(org.springframework.mock.web.MockHttpSession) IContextManager(org.jaffa.session.IContextManager) Test(org.junit.Test)

Aggregations

UserSession (org.jaffa.presentation.portlet.session.UserSession)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpSession (org.springframework.mock.web.MockHttpSession)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ServletRequest (javax.servlet.ServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JspException (javax.servlet.jsp.JspException)1 JspWriter (javax.servlet.jsp.JspWriter)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 ApplicationResourcesManager (org.jaffa.loader.config.ApplicationResourcesManager)1 ApplicationRulesManager (org.jaffa.loader.config.ApplicationRulesManager)1 FormBase (org.jaffa.presentation.portlet.FormBase)1 FormKey (org.jaffa.presentation.portlet.FormKey)1 Component (org.jaffa.presentation.portlet.component.Component)1 UserSessionSetupException (org.jaffa.presentation.portlet.session.UserSessionSetupException)1 UserGridManager (org.jaffa.presentation.portlet.widgets.controller.UserGridManager)1 JspWriteRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException)1 OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)1 TagCannotBeEnclosedRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.TagCannotBeEnclosedRuntimeException)1