Search in sources :

Example 1 with RestEndpointProperties

use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.

the class RestfulPrincipalFactoryTests method verifyBadResponse.

@Test
public void verifyBadResponse() {
    try (val webServer = new MockWebServer(9157, new ByteArrayResource("abcde123456".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new RestEndpointProperties();
        props.setUrl("http://localhost:9157");
        val factory = PrincipalFactoryUtils.newRestfulPrincipalFactory(props);
        assertThrows(IllegalArgumentException.class, () -> factory.createPrincipal("casuser", CollectionUtils.wrap("name", List.of("CAS"))));
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 2 with RestEndpointProperties

use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.

the class RestfulPrincipalFactoryTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val entity = MAPPER.writeValueAsString(CoreAuthenticationTestUtils.getPrincipal("casuser"));
    try (val webServer = new MockWebServer(9155, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new RestEndpointProperties();
        props.setUrl("http://localhost:9155");
        val factory = PrincipalFactoryUtils.newRestfulPrincipalFactory(props);
        val p = factory.createPrincipal("casuser", CollectionUtils.wrap("name", List.of("CAS")));
        assertEquals("casuser", p.getId());
        assertEquals(5, p.getAttributes().size());
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 3 with RestEndpointProperties

use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.

the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyFindByEmail.

@Test
public void verifyFindByEmail() throws Exception {
    var data = MAPPER.writeValueAsString(CollectionUtils.wrap("email", "cas@example.org"));
    try (val webServer = new MockWebServer(9312, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        this.webServer = webServer;
        this.webServer.start();
        assertTrue(this.webServer.isRunning());
        val props = new RestEndpointProperties();
        props.setUrl("http://localhost:9312");
        val repo = new OidcRestfulWebFingerUserInfoRepository(props);
        val results = repo.findByEmailAddress("cas@example.org");
        assertNotNull(results);
        assertTrue(results.containsKey("email"));
        assertEquals("cas@example.org", results.get("email"));
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) OidcRestfulWebFingerUserInfoRepository(org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 4 with RestEndpointProperties

use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.

the class RestfulDelegatedClientUserProfileProvisionerTests method verifyAllowedOperation.

@Test
public void verifyAllowedOperation() {
    val commonProfile = new CommonProfile();
    commonProfile.setClientName("CasClient");
    commonProfile.setId("testuser");
    val client = new CasClient(new CasConfiguration("http://cas.example.org"));
    try (val webServer = new MockWebServer(9192, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new RestEndpointProperties();
        props.setUrl("http://localhost:9192");
        val service = new RestfulDelegatedClientUserProfileProvisioner(props);
        service.execute(CoreAuthenticationTestUtils.getPrincipal(), commonProfile, client, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) CommonProfile(org.pac4j.core.profile.CommonProfile) CasConfiguration(org.pac4j.cas.config.CasConfiguration) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) CasClient(org.pac4j.cas.client.CasClient) Test(org.junit.jupiter.api.Test)

Example 5 with RestEndpointProperties

use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.

the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyBadPayload.

@Test
public void verifyBadPayload() throws Exception {
    try (val webServer = new MockWebServer(9312, new ByteArrayResource("-@@-".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        this.webServer = webServer;
        this.webServer.start();
        assertTrue(this.webServer.isRunning());
        val props = new RestEndpointProperties();
        props.setUrl("http://localhost:9312");
        val repo = new OidcRestfulWebFingerUserInfoRepository(props);
        val results = repo.findByEmailAddress("cas@example.org");
        assertTrue(results.isEmpty());
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) OidcRestfulWebFingerUserInfoRepository(org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)7 RestEndpointProperties (org.apereo.cas.configuration.model.RestEndpointProperties)7 MockWebServer (org.apereo.cas.util.MockWebServer)7 Test (org.junit.jupiter.api.Test)7 ByteArrayResource (org.springframework.core.io.ByteArrayResource)7 OidcRestfulWebFingerUserInfoRepository (org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository)3 CasClient (org.pac4j.cas.client.CasClient)1 CasConfiguration (org.pac4j.cas.config.CasConfiguration)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1