use of org.springframework.web.context.request.ServletRequestAttributes in project cas by apereo.
the class RestfulUrlTemplateResolverTests method verifyAction.
@Test
public void verifyAction() {
val request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, new MockHttpServletResponse()));
try (val webServer = new MockWebServer(9302, new ByteArrayResource("template".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val props = new CasConfigurationProperties();
props.getView().getRest().setUrl("http://localhost:9302");
var themeResolver = new FixedThemeResolver();
themeResolver.setDefaultThemeName("sample-theme");
val r = new RestfulUrlTemplateResolver(props, themeResolver);
val res = r.resolveTemplate(mock(IEngineConfiguration.class), "cas", "template", new LinkedHashMap<>());
assertNotNull(res);
}
}
use of org.springframework.web.context.request.ServletRequestAttributes in project cas by apereo.
the class ThemeBasedViewResolver method resolveViewName.
@Override
public View resolveViewName(final String viewName, final Locale locale) {
try {
val theme = Optional.of(RequestContextHolder.currentRequestAttributes()).filter(ServletRequestAttributes.class::isInstance).map(ServletRequestAttributes.class::cast).map(ServletRequestAttributes::getRequest).map(themeResolver::resolveThemeName);
val delegate = theme.map(this::getViewResolver);
if (delegate.isPresent()) {
return delegate.get().resolveViewName(viewName, locale);
}
} catch (final Exception e) {
LOGGER.debug("error resolving view [{}] for theme", viewName, e);
}
return null;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project cas by apereo.
the class OidcServicesManagerRegisteredServiceLocatorTests method verifyWithCallback.
@Test
public void verifyWithCallback() throws Exception {
val callbackUrl = "http://localhost:8443/cas" + OAuth20Constants.BASE_OAUTH20_URL + '/' + OAuth20Constants.CALLBACK_AUTHORIZE_URL;
val service0 = RegisteredServiceTestUtils.getRegisteredService(callbackUrl + ".*");
service0.setEvaluationOrder(0);
val service1 = getOidcRegisteredService("application1");
service1.setEvaluationOrder(100);
val service2 = getOidcRegisteredService("application-catch-all", ".*");
service2.setEvaluationOrder(1000);
val candidateServices = CollectionUtils.wrapList(service0, service1, service2);
servicesManager.save(candidateServices.toArray(new RegisteredService[0]));
Collections.sort(candidateServices);
val url = new URIBuilder(callbackUrl + '?' + OAuth20Constants.CLIENT_ID + "=application1");
val request = new MockHttpServletRequest();
request.setRequestURI(callbackUrl);
url.getQueryParams().forEach(param -> request.addParameter(param.getName(), param.getValue()));
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, new MockHttpServletResponse()));
val service = webApplicationServiceFactory.createService(url.toString());
val result = servicesManager.findServiceBy(service);
assertEquals(result, service1);
}
use of org.springframework.web.context.request.ServletRequestAttributes in project cas by apereo.
the class WsFederationServicesManagerRegisteredServiceLocatorTests method verifyWithCallback.
@Test
public void verifyWithCallback() throws Exception {
val callbackUrl = "http://localhost:8443/cas" + WSFederationConstants.ENDPOINT_FEDERATION_REQUEST_CALLBACK;
val service0 = RegisteredServiceTestUtils.getRegisteredService(callbackUrl + ".*");
service0.setEvaluationOrder(0);
val service1 = getWsFederationRegisteredService("application1", "CAS");
service1.setEvaluationOrder(100);
val service2 = getWsFederationRegisteredService(".*", "CAS");
service2.setEvaluationOrder(1000);
val candidateServices = CollectionUtils.wrapList(service0, service1, service2);
servicesManager.save(candidateServices.toArray(new RegisteredService[0]));
Collections.sort(candidateServices);
val url = new URIBuilder(callbackUrl + '?' + WSFederationConstants.WTREALM + "=CAS&" + WSFederationConstants.WREPLY + "=application1");
val request = new MockHttpServletRequest();
request.setRequestURI(callbackUrl);
url.getQueryParams().forEach(param -> request.addParameter(param.getName(), param.getValue()));
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, new MockHttpServletResponse()));
val service = webApplicationServiceFactory.createService(url.toString());
val result = servicesManager.findServiceBy(service);
assertEquals(service1, result);
}
use of org.springframework.web.context.request.ServletRequestAttributes in project cas by apereo.
the class OAuth20AuthenticationServiceSelectionStrategyTests method verifyJwtRequest.
@Test
public void verifyJwtRequest() {
val claims = new JWTClaimsSet.Builder().subject("cas").claim("scope", new String[] { "profile" }).claim("redirect_uri", REDIRECT_URI).claim("grant_type", OAuth20GrantTypes.CLIENT_CREDENTIALS.getType()).claim("client_id", CLIENT_ID).build();
val jwt = new PlainJWT(claims);
val jwtRequest = jwt.serialize();
val request = new MockHttpServletRequest();
request.addParameter(OAuth20Constants.REQUEST, jwtRequest);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, new MockHttpServletResponse()));
val service = strategy.resolveServiceFrom(RegisteredServiceTestUtils.getService("https://example.org?" + OAuth20Constants.REQUEST + '=' + jwtRequest));
assertNotNull(service);
assertTrue(service.getAttributes().containsKey(OAuth20Constants.CLIENT_ID));
}
Aggregations