Search in sources :

Example 1 with SamlIdPMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument in project cas by apereo.

the class FileSystemSamlIdPMetadataLocator method fetchInternal.

@SneakyThrows
@Override
protected SamlIdPMetadataDocument fetchInternal(final Optional<SamlRegisteredService> registeredService) {
    val doc = new SamlIdPMetadataDocument();
    doc.setMetadata(IOUtils.toString(resolveMetadata(registeredService).getInputStream(), StandardCharsets.UTF_8));
    doc.setEncryptionCertificate(IOUtils.toString(getEncryptionCertificate(registeredService).getInputStream(), StandardCharsets.UTF_8));
    doc.setEncryptionKey(IOUtils.toString(resolveEncryptionKey(registeredService).getInputStream(), StandardCharsets.UTF_8));
    doc.setSigningCertificate(IOUtils.toString(resolveSigningCertificate(registeredService).getInputStream(), StandardCharsets.UTF_8));
    doc.setSigningKey(IOUtils.toString(resolveSigningKey(registeredService).getInputStream(), StandardCharsets.UTF_8));
    doc.setAppliesTo(SamlIdPMetadataGenerator.getAppliesToFor(registeredService));
    return doc;
}
Also used : lombok.val(lombok.val) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) SneakyThrows(lombok.SneakyThrows)

Example 2 with SamlIdPMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument in project cas by apereo.

the class RestfulSamlIdPMetadataGeneratorWithArtifactsTests method setup.

@BeforeAll
public static void setup() throws Exception {
    val document = new SamlIdPMetadataDocument(1000, "CAS", IOUtils.toString(new ClassPathResource("metadata/idp-metadata.xml").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.key").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.key").getInputStream(), StandardCharsets.UTF_8));
    val entity = MAPPER.writeValueAsString(document);
    val resource = new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output");
    SERVER = new MockWebServer(9443, resource, HttpStatus.OK);
    SERVER.start();
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with SamlIdPMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument in project cas by apereo.

the class RestfulSamlIdPMetadataGeneratorTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    var document = new SamlIdPMetadataDocument();
    var entity = MAPPER.writeValueAsString(document);
    try (val webServer = new MockWebServer(9453, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        assertNotNull(samlIdPMetadataGenerator.generate(Optional.empty()));
    }
    document.setEncryptionCertificate(UUID.randomUUID().toString());
    document.setSigningKey(UUID.randomUUID().toString());
    document.setSigningCertificate(UUID.randomUUID().toString());
    document.setEncryptionKey(UUID.randomUUID().toString());
    document.setMetadata(UUID.randomUUID().toString());
    entity = MAPPER.writeValueAsString(document);
    try (val webServer = new MockWebServer(9453, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val service = new SamlRegisteredService();
        service.setName("TestShib");
        service.setId(1000);
        assertNotNull(samlIdPMetadataGenerator.generate(Optional.of(service)));
    }
    try (val webServer = new MockWebServer(9453, new ByteArrayResource("___".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        assertNotNull(samlIdPMetadataGenerator.generate(Optional.empty()));
    }
}
Also used : lombok.val(lombok.val) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) Test(org.junit.jupiter.api.Test)

Example 4 with SamlIdPMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument in project cas by apereo.

the class RestfulSamlIdPMetadataLocatorTests method setup.

@BeforeAll
public static void setup() throws Exception {
    val document = new SamlIdPMetadataDocument(1000, "CAS", IOUtils.toString(new ClassPathResource("metadata/idp-metadata.xml").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.key").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.key").getInputStream(), StandardCharsets.UTF_8));
    val entity = MAPPER.writeValueAsString(document);
    val resource = new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output");
    SERVER = new MockWebServer(9433, resource, HttpStatus.OK);
    SERVER.start();
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with SamlIdPMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument in project cas by apereo.

the class RedisSamlIdPMetadataLocator method fetchInternal.

@Override
public SamlIdPMetadataDocument fetchInternal(final Optional<SamlRegisteredService> registeredService) {
    val appliesTo = SamlIdPMetadataGenerator.getAppliesToFor(registeredService);
    val keys = redisTemplate.keys(CAS_PREFIX + appliesTo + ":*", this.scanCount);
    return keys.findFirst().map(key -> redisTemplate.boundValueOps(key).get()).orElse(null);
}
Also used : lombok.val(lombok.val) AbstractSamlIdPMetadataLocator(org.apereo.cas.support.saml.idp.metadata.locator.AbstractSamlIdPMetadataLocator) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) CipherExecutor(org.apereo.cas.util.crypto.CipherExecutor) SamlIdPMetadataGenerator(org.apereo.cas.support.saml.idp.metadata.generator.SamlIdPMetadataGenerator) lombok.val(lombok.val) Optional(java.util.Optional) CasRedisTemplate(org.apereo.cas.redis.core.CasRedisTemplate) Cache(com.github.benmanes.caffeine.cache.Cache)

Aggregations

lombok.val (lombok.val)7 SamlIdPMetadataDocument (org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument)7 MockWebServer (org.apereo.cas.util.MockWebServer)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 SneakyThrows (lombok.SneakyThrows)2 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Cache (com.github.benmanes.caffeine.cache.Cache)1 Optional (java.util.Optional)1 NoResultException (javax.persistence.NoResultException)1 CasRedisTemplate (org.apereo.cas.redis.core.CasRedisTemplate)1 SamlIdPMetadataGenerator (org.apereo.cas.support.saml.idp.metadata.generator.SamlIdPMetadataGenerator)1 AbstractSamlIdPMetadataLocator (org.apereo.cas.support.saml.idp.metadata.locator.AbstractSamlIdPMetadataLocator)1 CipherExecutor (org.apereo.cas.util.crypto.CipherExecutor)1 Test (org.junit.jupiter.api.Test)1