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