Search in sources :

Example 36 with JEEContext

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());
}
Also used : lombok.val(lombok.val) ProfileManager(org.pac4j.core.profile.ProfileManager) CommonProfile(org.pac4j.core.profile.CommonProfile) JEEContext(org.pac4j.core.context.JEEContext) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 37 with JEEContext

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());
}
Also used : lombok.val(lombok.val) ProfileManager(org.pac4j.core.profile.ProfileManager) CommonProfile(org.pac4j.core.profile.CommonProfile) JEEContext(org.pac4j.core.context.JEEContext) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 38 with JEEContext

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());
}
Also used : lombok.val(lombok.val) BrowserWebStorageSessionStore(org.apereo.cas.pac4j.BrowserWebStorageSessionStore) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BrowserSessionStorage(org.apereo.cas.web.BrowserSessionStorage) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with JEEContext

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());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DistributedJEESessionStore(org.apereo.cas.pac4j.DistributedJEESessionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with JEEContext

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"));
}
Also used : lombok.val(lombok.val) JEEContext(org.pac4j.core.context.JEEContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

JEEContext (org.pac4j.core.context.JEEContext)224 lombok.val (lombok.val)215 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)158 Test (org.junit.jupiter.api.Test)157 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)155 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)34 ProfileManager (org.pac4j.core.profile.ProfileManager)28 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)24 CommonProfile (org.pac4j.core.profile.CommonProfile)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 HashMap (java.util.HashMap)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 RedirectView (org.springframework.web.servlet.view.RedirectView)14 CasProfile (org.pac4j.cas.profile.CasProfile)13 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)13 MockRequestContext (org.springframework.webflow.test.MockRequestContext)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Map (java.util.Map)10 Slf4j (lombok.extern.slf4j.Slf4j)10