Search in sources :

Example 6 with RestEndpointProperties

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

the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyFindByUsername.

@Test
public void verifyFindByUsername() throws Exception {
    var data = MAPPER.writeValueAsString(CollectionUtils.wrap("username", "casuser"));
    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.findByUsername("casuser");
        assertNotNull(results);
        assertTrue(results.containsKey("username"));
        assertEquals("casuser", results.get("username"));
    }
}
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 7 with RestEndpointProperties

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

the class RestfulPrincipalFactoryTests method verifyNullPrincipal.

@Test
public void verifyNullPrincipal() throws Exception {
    val entity = MAPPER.writeValueAsString(CoreAuthenticationTestUtils.getPrincipal("casuser"));
    try (val webServer = new MockWebServer(9156, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.EXPECTATION_FAILED)) {
        webServer.start();
        val props = new RestEndpointProperties();
        props.setUrl("http://localhost:9156");
        val factory = PrincipalFactoryUtils.newRestfulPrincipalFactory(props);
        val p = factory.createPrincipal("casuser", CollectionUtils.wrap("name", List.of("CAS")));
        assertNull(p);
    }
}
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)

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