Search in sources :

Example 6 with SamlIdPMetadataDocument

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

the class JpaSamlIdPMetadataLocator method fetchInternal.

@Override
public SamlIdPMetadataDocument fetchInternal(final Optional<SamlRegisteredService> registeredService) {
    try {
        if (registeredService.isPresent()) {
            val query = buildQuery(registeredService);
            val results = query.getResultList();
            if (!results.isEmpty()) {
                return results.get(0);
            }
        }
        return buildQuery(Optional.empty()).getSingleResult();
    } catch (final NoResultException e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return new SamlIdPMetadataDocument();
}
Also used : lombok.val(lombok.val) NoResultException(javax.persistence.NoResultException) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument)

Example 7 with SamlIdPMetadataDocument

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

the class AmazonS3SamlIdPMetadataLocator method fetchInternal.

@Override
@SneakyThrows
public SamlIdPMetadataDocument fetchInternal(final Optional<SamlRegisteredService> registeredService) {
    val metadataDocument = new SamlIdPMetadataDocument();
    val bucketToUse = AmazonS3SamlIdPMetadataUtils.determineBucketNameFor(registeredService, this.bucketName, s3Client);
    LOGGER.debug("Locating S3 object(s) from bucket [{}]...", bucketToUse);
    if (s3Client.listBuckets(ListBucketsRequest.builder().build()).buckets().stream().noneMatch(b -> b.name().equalsIgnoreCase(bucketToUse))) {
        LOGGER.debug("S3 bucket [{}] does not exist", bucketToUse);
        return metadataDocument;
    }
    val result = s3Client.listObjectsV2(ListObjectsV2Request.builder().bucket(bucketToUse).build());
    val objects = result.contents();
    LOGGER.debug("Located [{}] S3 object(s) from bucket [{}]", objects.size(), bucketToUse);
    if (objects.isEmpty()) {
        throw new IllegalArgumentException("No objects found in bucket " + bucketToUse);
    }
    val obj = objects.get(0);
    val objectKey = obj.key();
    LOGGER.debug("Fetching object [{}] from bucket [{}]", objectKey, bucketToUse);
    val object = s3Client.getObject(GetObjectRequest.builder().bucket(bucketToUse).key(objectKey).build());
    metadataDocument.setMetadata(IOUtils.toString(object, StandardCharsets.UTF_8));
    val objectMetadata = object.response().metadata();
    metadataDocument.setEncryptionCertificate(objectMetadata.get("encryptionCertificate"));
    metadataDocument.setSigningCertificate(objectMetadata.get("signingCertificate"));
    metadataDocument.setEncryptionKey(objectMetadata.get("encryptionKey"));
    metadataDocument.setSigningKey(objectMetadata.get("signingKey"));
    metadataDocument.setAppliesTo(bucketToUse);
    return metadataDocument;
}
Also used : lombok.val(lombok.val) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) SneakyThrows(lombok.SneakyThrows)

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