use of org.apereo.cas.support.saml.SamlException in project cas by apereo.
the class UrlResourceMetadataResolver method resolve.
@Override
public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service, final CriteriaSet criteriaSet) {
HttpResponse response = null;
try {
RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service);
val metadataLocation = getMetadataLocationForService(service, criteriaSet);
LOGGER.info("Loading SAML metadata from [{}]", metadataLocation);
val metadataResource = new UrlResource(metadataLocation);
val backupFile = getMetadataBackupFile(metadataResource, service);
if (backupFile.exists() && samlIdPProperties.getMetadata().getHttp().isForceMetadataRefresh()) {
cleanUpExpiredBackupMetadataFilesFor(metadataResource, service);
}
val canonicalPath = backupFile.getCanonicalPath();
LOGGER.debug("Metadata backup file will be at [{}]", canonicalPath);
FileUtils.forceMkdirParent(backupFile);
response = fetchMetadata(service, metadataLocation, criteriaSet, backupFile);
val status = HttpStatus.valueOf(response.getStatusLine().getStatusCode());
if (shouldHttpResponseStatusBeProcessed(status)) {
val metadataProvider = getMetadataResolverFromResponse(response, backupFile);
configureAndInitializeSingleMetadataResolver(metadataProvider, service);
return CollectionUtils.wrap(metadataProvider);
}
} catch (final UnauthorizedServiceException e) {
LoggingUtils.error(LOGGER, e);
throw new SamlException(e.getMessage(), e);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
} finally {
HttpUtils.close(response);
}
return new ArrayList<>(0);
}
Aggregations