use of org.springframework.web.servlet.View in project cas by apereo.
the class OAuth20AuthorizeControllerTests method verifyCodeRedirectToClientWithState.
@Test
public void verifyCodeRedirectToClientWithState() throws Exception {
clearAllServices();
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.AUTHORIZE_URL);
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.name().toLowerCase());
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
mockRequest.setParameter(OAuth20Constants.STATE, STATE);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuthRegisteredService service = getRegisteredService(REDIRECT_URI, SERVICE_NAME);
service.setBypassApprovalPrompt(true);
this.servicesManager.save(service);
final CasProfile profile = new CasProfile();
profile.setId(ID);
final Map<String, Object> attributes = new HashMap<>();
attributes.put(FIRST_NAME_ATTRIBUTE, FIRST_NAME);
attributes.put(LAST_NAME_ATTRIBUTE, LAST_NAME);
profile.addAttributes(attributes);
final MockHttpSession session = new MockHttpSession();
mockRequest.setSession(session);
session.putValue(Pac4jConstants.USER_PROFILES, profile);
final ModelAndView modelAndView = oAuth20AuthorizeEndpointController.handleRequest(mockRequest, mockResponse);
final View view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
final RedirectView redirectView = (RedirectView) view;
final String redirectUrl = redirectView.getUrl();
assertTrue(redirectUrl.startsWith(REDIRECT_URI + "?code=OC-"));
final String code = StringUtils.substringBefore(StringUtils.substringAfter(redirectUrl, "?code="), "&state=");
final OAuthCode oAuthCode = (OAuthCode) this.ticketRegistry.getTicket(code);
assertNotNull(oAuthCode);
final Principal principal = oAuthCode.getAuthentication().getPrincipal();
assertEquals(ID, principal.getId());
final Map<String, Object> principalAttributes = principal.getAttributes();
assertEquals(attributes.size(), principalAttributes.size());
assertEquals(FIRST_NAME, principalAttributes.get(FIRST_NAME_ATTRIBUTE));
}
use of org.springframework.web.servlet.View in project cas by apereo.
the class ThemeViewResolver method loadView.
@Override
protected View loadView(final String viewName, final Locale locale) throws Exception {
final View view = delegate.resolveViewName(viewName, locale);
if (view instanceof AbstractThymeleafView) {
final AbstractThymeleafView thymeleafView = (AbstractThymeleafView) view;
configureTemplateThemeDefaultLocation(thymeleafView);
}
return view;
}
use of org.springframework.web.servlet.View in project cxf by apache.
the class SpringViewResolverProvider method writeTo.
public void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException {
View view = getView(clazz, o);
String attributeName = getBeanName(o);
Map<String, Object> model = Collections.singletonMap(attributeName, o);
try {
getMessageContext().put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.TRUE);
logRedirection(view, attributeName, o);
view.render(model, getMessageContext().getHttpServletRequest(), getMessageContext().getHttpServletResponse());
} catch (Throwable ex) {
handleViewRenderingException(view.toString(), ex);
}
}
use of org.springframework.web.servlet.View in project cxf by apache.
the class SpringViewResolverProviderTest method testIsWriteableEnum2.
@Test
public void testIsWriteableEnum2() {
String viewName = "/test";
View view = expectGetView(viewName);
viewResolver.setEnumResources(Collections.singletonMap(TestEnum.ONE, viewName));
replayAll();
assertTrue(viewResolver.isWriteable(TestEnum.ONE.getClass(), null, null, null));
assertEquals(view, viewResolver.getView(TestEnum.ONE.getClass(), TestEnum.ONE));
}
use of org.springframework.web.servlet.View in project cas by apereo.
the class Cas20ResponseViewTests method verifyView.
@Test
public void verifyView() throws Exception {
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
final MockHttpServletResponse resp = new MockHttpServletResponse();
final View delegatedView = new View() {
@Override
public String getContentType() {
return "text/html";
}
@Override
public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) {
map.forEach(request::setAttribute);
}
};
final Cas20ResponseView view = new Cas20ResponseView(true, null, null, "attribute", delegatedView, new DefaultAuthenticationAttributeReleasePolicy(), new DefaultAuthenticationServiceSelectionPlan());
view.render(modelAndView.getModel(), req, resp);
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_CHAINED_AUTHENTICATIONS));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRIMARY_AUTHENTICATION));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL));
assertNotNull(req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_PROXY_GRANTING_TICKET_IOU));
}
Aggregations