use of org.springframework.core.io.AbstractResource in project cas by apereo.
the class GroovyRegisteredServiceUsernameProvider method resolveUsernameFromExternalGroovyScript.
private String resolveUsernameFromExternalGroovyScript(final Principal principal, final Service service, final String scriptFile) {
try {
LOGGER.debug("Found groovy script to execute");
final AbstractResource resourceFrom = ResourceUtils.getResourceFrom(scriptFile);
final String script = IOUtils.toString(resourceFrom.getInputStream(), StandardCharsets.UTF_8);
final Object result = getGroovyAttributeValue(principal, script);
if (result != null) {
LOGGER.debug("Found username [{}] from script [{}]", result, scriptFile);
return result.toString();
}
} catch (final IOException e) {
LOGGER.error(e.getMessage(), e);
}
LOGGER.warn("Groovy script [{}] returned no value for username attribute. Fallback to default [{}]", this.groovyScript, principal.getId());
return principal.getId();
}
use of org.springframework.core.io.AbstractResource in project cas by apereo.
the class UrlResourceMetadataResolver method resolve.
@Override
public Collection<MetadataResolver> resolve(final SamlRegisteredService service) {
try {
final String metadataLocation = service.getMetadataLocation();
LOGGER.info("Loading SAML metadata from [{}]", metadataLocation);
final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
final File backupFile = getMetadataBackupFile(metadataResource, service);
final String canonicalPath = backupFile.getCanonicalPath();
LOGGER.debug("Metadata backup file will be at [{}]", canonicalPath);
FileUtils.forceMkdirParent(backupFile);
cleanUpExpiredBackupMetadataFilesFor(metadataResource, service);
final FileBackedHTTPMetadataResolver metadataProvider = new FileBackedHTTPMetadataResolver(this.httpClient.getWrappedHttpClient(), metadataResource.getURL().toExternalForm(), canonicalPath);
configureAndInitializeSingleMetadataResolver(metadataProvider, service);
return CollectionUtils.wrap(metadataProvider);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new ArrayList<>(0);
}
use of org.springframework.core.io.AbstractResource in project cas by apereo.
the class UrlResourceMetadataResolver method supports.
@Override
public boolean supports(final SamlRegisteredService service) {
try {
final String metadataLocation = service.getMetadataLocation();
final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
return metadataResource instanceof UrlResource;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
use of org.springframework.core.io.AbstractResource in project spring-framework by spring-projects.
the class YamlMapFactoryBeanTests method testFirstFound.
@Test
public void testFirstFound() {
this.factory.setResolutionMethod(YamlProcessor.ResolutionMethod.FIRST_FOUND);
this.factory.setResources(new AbstractResource() {
@Override
public String getDescription() {
return "non-existent";
}
@Override
public InputStream getInputStream() throws IOException {
throw new IOException("planned");
}
}, new ByteArrayResource("foo:\n spam: bar".getBytes()));
assertThat(this.factory.getObject().size()).isEqualTo(1);
}
Aggregations