Search in sources :

Example 1 with PortalRequest

use of org.apereo.portal.soffit.model.v1_0.PortalRequest in project uPortal by Jasig.

the class PortalRequestHeaderProvider method createHeader.

@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
    // Username
    final String username = getUsername(renderRequest);
    // Properties
    final Map<String, String> properties = new HashMap<>();
    final Enumeration<String> names = renderRequest.getPropertyNames();
    for (String propertyName = names.nextElement(); names.hasMoreElements(); propertyName = names.nextElement()) {
        properties.put(propertyName, renderRequest.getProperty(propertyName));
    }
    // Attributes
    final Map<String, List<String>> attributes = new HashMap<>();
    attributes.put(Attributes.NAMESPACE.getName(), Collections.singletonList(NAMESPACE_PREFIX + renderRequest.getWindowID()));
    attributes.put(Attributes.MODE.getName(), Collections.singletonList(renderRequest.getPortletMode().toString()));
    attributes.put(Attributes.WINDOW_STATE.getName(), Collections.singletonList(renderRequest.getWindowState().toString()));
    attributes.put(Attributes.PORTAL_INFO.getName(), Collections.singletonList(renderRequest.getPortalContext().getPortalInfo()));
    attributes.put(Attributes.SCHEME.getName(), Collections.singletonList(renderRequest.getScheme()));
    attributes.put(Attributes.SERVER_NAME.getName(), Collections.singletonList(renderRequest.getServerName()));
    attributes.put(Attributes.SERVER_PORT.getName(), Collections.singletonList(Integer.valueOf(renderRequest.getServerPort()).toString()));
    attributes.put(Attributes.SECURE.getName(), Collections.singletonList(Boolean.valueOf(renderRequest.isSecure()).toString()));
    // Parameters
    final Map<String, List<String>> parameters = new HashMap<>();
    for (Map.Entry<String, String[]> y : renderRequest.getParameterMap().entrySet()) {
        parameters.put(y.getKey(), Arrays.asList(y.getValue()));
    }
    // Preferences header
    final PortalRequest portalRequest = portalRequestService.createPortalRequest(properties, attributes, parameters, username, getExpiration(renderRequest));
    final Header rslt = new BasicHeader(Headers.PORTAL_REQUEST.getName(), portalRequest.getEncryptedToken());
    logger.debug("Produced the following PortalRequest header for username='{}':  {}", username, rslt);
    return rslt;
}
Also used : BasicHeader(org.apache.http.message.BasicHeader) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) PortalRequest(org.apereo.portal.soffit.model.v1_0.PortalRequest)

Example 2 with PortalRequest

use of org.apereo.portal.soffit.model.v1_0.PortalRequest in project uPortal by Jasig.

the class SoffitRendererController method render.

@RequestMapping(value = "/{module}", method = RequestMethod.GET)
public ModelAndView render(final HttpServletRequest req, final HttpServletResponse res, @PathVariable final String module) {
    logger.debug("Rendering for request URI '{}'", req.getRequestURI());
    // Soffit Object Model
    final PortalRequest portalRequest = getPortalRequest(req);
    final Bearer bearer = getBearer(req);
    final Preferences preferences = getPreferences(req);
    final Definition definition = getDefinition(req);
    // Select a view
    final String viewName = selectView(req, module, portalRequest);
    final Map<String, Object> model = modelAttributeService.gatherModelAttributes(viewName, req, res, portalRequest, bearer, preferences, definition);
    model.put(PORTAL_REQUEST_MODEL_NAME, portalRequest);
    model.put(BEARER_MODEL_NAME, bearer);
    model.put(PREFERENCES_MODEL_NAME, preferences);
    model.put(DEFINITION_MODEL_NAME, definition);
    // Set up cache headers appropriately
    configureCacheHeaders(res, module);
    return new ModelAndView(viewName, model);
}
Also used : Definition(org.apereo.portal.soffit.model.v1_0.Definition) ModelAndView(org.springframework.web.servlet.ModelAndView) Preferences(org.apereo.portal.soffit.model.v1_0.Preferences) Bearer(org.apereo.portal.soffit.model.v1_0.Bearer) PortalRequest(org.apereo.portal.soffit.model.v1_0.PortalRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PortalRequest

use of org.apereo.portal.soffit.model.v1_0.PortalRequest in project uPortal by Jasig.

the class ModelAttributeServiceTest method testGetModelAttributeFromMethod.

@Test
public void testGetModelAttributeFromMethod() {
    final ModelAttributeService modelAttributeService = new ModelAttributeService();
    final Class[] parameterClasses = new Class[] { HttpServletRequest.class, PortalRequest.class, Bearer.class };
    final Method method;
    try {
        method = getClass().getMethod("soffitModelAttributeMethod", parameterClasses);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
    // Object Model
    final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
    final HttpServletResponse res = Mockito.mock(HttpServletResponse.class);
    final PortalRequest portalRequest = Mockito.mock(PortalRequest.class);
    final Bearer bearer = Mockito.mock(Bearer.class);
    final Preferences preferences = Mockito.mock(Preferences.class);
    final Definition definition = Mockito.mock(Definition.class);
    final Object modelAttribute = modelAttributeService.getModelAttributeFromMethod(this, method, req, res, portalRequest, bearer, preferences, definition);
    assertEquals("Incorrect modelAttribute", modelAttribute, returnValue);
    final Method brokenMethod;
    try {
        brokenMethod = getClass().getMethod("brokenSoffitModelAttributeMethod", parameterClasses);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
    try {
        modelAttributeService.getModelAttributeFromMethod(this, brokenMethod, req, res, portalRequest, bearer, preferences, definition);
        fail("Expected IllegalStateException for void-declaring method");
    } catch (IllegalStateException e) {
    // Expected;  fall through...
    }
}
Also used : Definition(org.apereo.portal.soffit.model.v1_0.Definition) HttpServletResponse(javax.servlet.http.HttpServletResponse) Method(java.lang.reflect.Method) PortalRequest(org.apereo.portal.soffit.model.v1_0.PortalRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Preferences(org.apereo.portal.soffit.model.v1_0.Preferences) Bearer(org.apereo.portal.soffit.model.v1_0.Bearer) Test(org.junit.Test)

Example 4 with PortalRequest

use of org.apereo.portal.soffit.model.v1_0.PortalRequest in project uPortal by Jasig.

the class PortalRequestService method createPortalRequest.

public PortalRequest createPortalRequest(Map<String, String> properties, Map<String, List<String>> attributes, Map<String, List<String>> parameters, String username, Date expires) {
    final Claims claims = createClaims(PortalRequest.class, username, expires);
    // Properties
    claims.put(JwtClaims.PROPERTIES.getName(), properties);
    // Attributes
    claims.put(JwtClaims.ATTRIBUTES.getName(), attributes);
    // Parameters
    claims.put(JwtClaims.PARAMETERS.getName(), parameters);
    return new PortalRequest(generateEncryptedToken(claims), properties, attributes, parameters);
}
Also used : Claims(io.jsonwebtoken.Claims) PortalRequest(org.apereo.portal.soffit.model.v1_0.PortalRequest)

Example 5 with PortalRequest

use of org.apereo.portal.soffit.model.v1_0.PortalRequest in project uPortal by Jasig.

the class PortalRequestService method parsePortalRequest.

public PortalRequest parsePortalRequest(String portalRequestToken) {
    final Jws<Claims> claims = parseEncrypteToken(portalRequestToken, PortalRequest.class);
    final String username = claims.getBody().getSubject();
    // Properties
    @SuppressWarnings("unchecked") final Map<String, String> properties = (Map<String, String>) claims.getBody().get(JwtClaims.PROPERTIES.getName());
    // Attributes
    @SuppressWarnings("unchecked") final Map<String, List<String>> attributes = (Map<String, List<String>>) claims.getBody().get(JwtClaims.ATTRIBUTES.getName());
    // Parameters
    @SuppressWarnings("unchecked") final Map<String, List<String>> parameters = (Map<String, List<String>>) claims.getBody().get(JwtClaims.PARAMETERS.getName());
    PortalRequest rslt = new PortalRequest(portalRequestToken, properties, attributes, parameters);
    logger.debug("Produced the following PortalRequest for user '{}':  {}", username, rslt);
    return rslt;
}
Also used : Claims(io.jsonwebtoken.Claims) List(java.util.List) Map(java.util.Map) PortalRequest(org.apereo.portal.soffit.model.v1_0.PortalRequest)

Aggregations

PortalRequest (org.apereo.portal.soffit.model.v1_0.PortalRequest)6 Bearer (org.apereo.portal.soffit.model.v1_0.Bearer)3 Definition (org.apereo.portal.soffit.model.v1_0.Definition)3 Preferences (org.apereo.portal.soffit.model.v1_0.Preferences)3 Claims (io.jsonwebtoken.Claims)2 Method (java.lang.reflect.Method)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Test (org.junit.Test)2 List (java.util.List)1 Map (java.util.Map)1 Header (org.apache.http.Header)1 BasicHeader (org.apache.http.message.BasicHeader)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1