use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class UmaPermissionRegistrationEndpointControllerTests method verifyBadProfile.
@Test
public void verifyBadProfile() throws Exception {
val results = authenticateUmaRequestWithProtectionScope();
var body = createUmaResourceRegistrationRequest().toJson();
var response = umaCreateResourceSetRegistrationEndpointController.registerResourceSet(body, results.getLeft(), results.getMiddle());
var model = (Map) response.getBody();
val resourceId = (long) model.get("resourceId");
val profile = getCurrentProfile(results.getLeft(), results.getMiddle());
body = createUmaPolicyRegistrationRequest(profile).toJson();
response = umaCreatePolicyForResourceSetEndpointController.createPolicyForResourceSet(resourceId, body, results.getLeft(), results.getMiddle());
assertEquals(HttpStatus.OK, response.getStatusCode());
body = createUmaPermissionRegistrationRequest(resourceId).toJson();
val context = new JEEContext(results.getLeft(), results.getMiddle());
val manager = new ProfileManager(context, oauthDistributedSessionStore);
manager.removeProfiles();
val commonProfile = new CommonProfile();
commonProfile.setClientName("CasClient");
commonProfile.setId("testuser");
commonProfile.setPermissions(Set.of(OAuth20Constants.UMA_PROTECTION_SCOPE));
manager.save(true, commonProfile, false);
response = umaPermissionRegistrationEndpointController.handle(body, results.getLeft(), results.getMiddle());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class UmaDeleteResourceSetRegistrationEndpointControllerTests method verifyBadClientId.
@Test
public void verifyBadClientId() {
val results = authenticateUmaRequestWithProtectionScope();
var body = createUmaResourceRegistrationRequest().toJson();
var response = umaCreateResourceSetRegistrationEndpointController.registerResourceSet(body, results.getLeft(), results.getMiddle());
assertNotNull(response.getBody());
var model = (Map) response.getBody();
val resourceId = (long) model.get("resourceId");
val context = new JEEContext(results.getLeft(), results.getMiddle());
val manager = new ProfileManager(context, oauthDistributedSessionStore);
manager.removeProfiles();
response = umaDeleteResourceSetRegistrationEndpointController.deleteResourceSet(resourceId, results.getLeft(), results.getMiddle());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
val commonProfile = new CommonProfile();
commonProfile.setClientName("CasClient");
commonProfile.setId("testuser");
commonProfile.setPermissions(Set.of(OAuth20Constants.UMA_PROTECTION_SCOPE));
manager.save(true, commonProfile, false);
response = umaDeleteResourceSetRegistrationEndpointController.deleteResourceSet(resourceId, results.getLeft(), results.getMiddle());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class BrowserWebStorageSessionStoreTests method verifyOperation.
@Test
public void verifyOperation() {
val store = new BrowserWebStorageSessionStore(webflowCipherExecutor);
val request = new MockHttpServletRequest();
val ctx = new JEEContext(request, new MockHttpServletResponse());
store.set(ctx, "key1", "value1");
store.set(ctx, "key2", List.of("HelloWorld"));
store.set(ctx, "key3", 1234567);
store.set(ctx, "dummy", new Dummy());
var session = store.getTrackableSession(ctx);
assertTrue(session.isPresent());
store.renewSession(ctx);
val trackableSession = (BrowserSessionStorage) session.get();
store.buildFromTrackableSession(ctx, trackableSession.getPayload());
assertTrue(store.get(ctx, "key1").isPresent());
assertTrue(store.get(ctx, "key2").isPresent());
assertTrue(store.get(ctx, "key3").isPresent());
assertTrue(store.get(ctx, "dummy").isPresent());
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class DistributedJEESessionStoreTests method verifyTracking.
@Test
public void verifyTracking() {
val cookie = casProperties.getSessionReplication().getCookie();
val cookieGenerator = CookieUtils.buildCookieRetrievingGenerator(cookie);
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val store = new DistributedJEESessionStore(centralAuthenticationService, ticketFactory, cookieGenerator);
val context = new JEEContext(request, response);
assertNotNull(request.getSession());
assertFalse(store.renewSession(context));
assertTrue(store.buildFromTrackableSession(context, "trackable-session").isPresent());
assertTrue(store.getTrackableSession(context).isPresent());
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class SSOSamlIdPProfileCallbackHandlerController method handleCallbackProfileRequestPost.
/**
* Handle callback profile request post.
*
* @param response the response
* @param request the request
* @return the model and view
* @throws Exception the exception
*/
@PostMapping(path = SamlIdPConstants.ENDPOINT_SAML2_SSO_PROFILE_CALLBACK)
protected ModelAndView handleCallbackProfileRequestPost(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
autoConfigureCookiePath(request);
val properties = configurationContext.getCasProperties();
val type = properties.getAuthn().getSamlIdp().getCore().getSessionStorageType();
if (type == SamlIdPCoreProperties.SessionStorageTypes.BROWSER_SESSION_STORAGE) {
val storage = request.getParameter(BrowserSessionStorage.KEY_SESSION_STORAGE);
val context = new JEEContext(request, response);
configurationContext.getSessionStore().buildFromTrackableSession(context, storage);
return handleProfileRequest(response, request);
}
return WebUtils.produceErrorView(new IllegalArgumentException("Unable to build SAML response"));
}
Aggregations