use of org.apereo.cas.git.PathRegexPatternTreeFilter in project cas by apereo.
the class GitSamlRegisteredServiceMetadataResolver method resolve.
@Override
public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service, final CriteriaSet criteriaSet) throws Exception {
if (gitRepository.pull()) {
LOGGER.debug("Successfully pulled metadata changes from the remote repository");
} else {
LOGGER.warn("Unable to pull changes from the remote repository. Metadata files may be stale.");
}
val metadataFiles = gitRepository.getObjectsInRepository(new PathRegexPatternTreeFilter(PATTERN_METADATA_FILES));
val signatureFiles = gitRepository.getObjectsInRepository(new PathRegexPatternTreeFilter(PATTERN_SIGNATURE_FILES));
return metadataFiles.stream().filter(Objects::nonNull).map(object -> parseGitObjectContentIntoSamlMetadataDocument(object, signatureFiles)).map(doc -> buildMetadataResolverFrom(service, doc)).filter(Objects::nonNull).collect(Collectors.toCollection(ArrayList::new));
}
use of org.apereo.cas.git.PathRegexPatternTreeFilter in project cas by apereo.
the class GitServiceRegistry method load.
@Synchronized
@Override
public Collection<RegisteredService> load() {
try {
if (gitRepository.pull()) {
LOGGER.debug("Successfully pulled changes from the remote repository");
} else {
LOGGER.info("Unable to pull changes from the remote repository. Service definition files may be stale.");
}
val objectPatternStr = StringUtils.isBlank(rootDirectory) ? GitRepositoryRegisteredServiceLocator.PATTEN_ACCEPTED_REPOSITORY_FILES : rootDirectory + '/' + GitRepositoryRegisteredServiceLocator.PATTEN_ACCEPTED_REPOSITORY_FILES;
val objectPattern = RegexUtils.createPattern(objectPatternStr, Pattern.CASE_INSENSITIVE);
val objects = gitRepository.getObjectsInRepository(new PathRegexPatternTreeFilter(objectPattern));
registeredServices = objects.stream().filter(Objects::nonNull).map(this::parseGitObjectContentIntoRegisteredService).flatMap(Collection::stream).map(this::invokeServiceRegistryListenerPostLoad).filter(Objects::nonNull).collect(Collectors.toList());
return registeredServices;
} catch (final Exception e) {
LoggingUtils.warn(LOGGER, e);
val parentDir = StringUtils.isBlank(rootDirectory) ? gitRepository.getRepositoryDirectory() : new File(gitRepository.getRepositoryDirectory(), rootDirectory);
val files = FileUtils.listFiles(parentDir, GitRepositoryRegisteredServiceLocator.FILE_EXTENSIONS.toArray(ArrayUtils.EMPTY_STRING_ARRAY), true);
LOGGER.debug("Located [{}] files(s)", files.size());
registeredServices = files.stream().filter(file -> file.isFile() && file.canRead() && file.canWrite() && file.length() > 0).map(Unchecked.function(file -> {
try (val in = Files.newBufferedReader(file.toPath())) {
return registeredServiceSerializers.stream().filter(s -> s.supports(file)).map(s -> s.load(in)).filter(Objects::nonNull).flatMap(Collection::stream).map(this::invokeServiceRegistryListenerPostLoad).filter(Objects::nonNull).collect(Collectors.toList());
} catch (final Exception ex) {
LOGGER.error("Error reading configuration file [{}]", file.toPath());
LoggingUtils.error(LOGGER, ex);
}
return new ArrayList<RegisteredService>(0);
})).flatMap(List::stream).sorted().map(this::invokeServiceRegistryListenerPostLoad).filter(Objects::nonNull).collect(Collectors.toList());
return registeredServices;
}
}
Aggregations