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();
}
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;
}
Aggregations