use of org.springframework.core.io.AbstractResource in project cas by apereo.
the class FileSystemResourceMetadataResolver method supports.
@Override
public boolean supports(final SamlRegisteredService service) {
try {
final String metadataLocation = service.getMetadataLocation();
final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
return metadataResource instanceof FileSystemResource;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
use of org.springframework.core.io.AbstractResource in project cas by apereo.
the class FileSystemResourceMetadataResolver 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 metadataFile = metadataResource.getFile();
final AbstractMetadataResolver metadataResolver;
if (metadataFile.isDirectory()) {
metadataResolver = new LocalDynamicMetadataResolver(new FilesystemLoadSaveManager<>(metadataFile, configBean.getParserPool()));
} else {
metadataResolver = new ResourceBackedMetadataResolver(ResourceHelper.of(metadataResource));
}
configureAndInitializeSingleMetadataResolver(metadataResolver, service);
return CollectionUtils.wrap(metadataResolver);
} 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 GroovyResourceMetadataResolver method resolve.
@Override
public Collection<MetadataResolver> resolve(final SamlRegisteredService service) {
try {
final String metadataLocation = service.getMetadataLocation();
LOGGER.info("Loading SAML metadata via [{}]", metadataLocation);
final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
final Object[] args = { service, this.configBean, this.samlIdPProperties, LOGGER };
final MetadataResolver metadataResolver = ScriptingUtils.executeGroovyScript(metadataResource, args, MetadataResolver.class);
if (metadataResolver != null) {
return CollectionUtils.wrap(metadataResolver);
}
} 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 ChainingMetadataResolverCacheLoader method resolveMetadataFromResource.
/**
* Resolve metadata from resource.
*
* @param service the service
* @param metadataResolvers the metadata resolvers
* @throws Exception the io exception
*/
protected void resolveMetadataFromResource(final SamlRegisteredService service, final List<MetadataResolver> metadataResolvers) throws Exception {
final String metadataLocation = service.getMetadataLocation();
LOGGER.info("Loading SAML metadata from [{}]", metadataLocation);
final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
if (metadataResource instanceof FileSystemResource) {
resolveFileSystemBasedMetadataResource(service, metadataResolvers, metadataResource);
}
if (metadataResource instanceof UrlResource) {
resolveUrlBasedMetadataResource(service, metadataResolvers, metadataResource);
}
if (metadataResource instanceof ClassPathResource) {
resolveClasspathBasedMetadataResource(service, metadataResolvers, metadataLocation, metadataResource);
}
}
use of org.springframework.core.io.AbstractResource in project cas by apereo.
the class ScriptingUtils method executeGroovyScriptEngine.
/**
* Execute groovy script engine t.
*
* @param <T> the type parameter
* @param scriptFile the script file
* @param args the args
* @param clazz the clazz
* @return the t
*/
public static <T> T executeGroovyScriptEngine(final String scriptFile, final Object[] args, final Class<T> clazz) {
try {
final String engineName = getScriptEngineName(scriptFile);
final ScriptEngine engine = new ScriptEngineManager().getEngineByName(engineName);
if (engine == null || StringUtils.isBlank(engineName)) {
LOGGER.warn("Script engine is not available for [{}]", engineName);
return null;
}
final AbstractResource resourceFrom = ResourceUtils.getResourceFrom(scriptFile);
final File theScriptFile = resourceFrom.getFile();
if (theScriptFile.exists()) {
LOGGER.debug("Created object instance from class [{}]", theScriptFile.getCanonicalPath());
engine.eval(Files.newBufferedReader(theScriptFile.toPath(), StandardCharsets.UTF_8));
final Invocable invocable = (Invocable) engine;
LOGGER.debug("Executing script's run method, with parameters [{}]", args);
final Object result = invocable.invokeFunction("run", args);
LOGGER.debug("Groovy script result is [{}]", result);
if (result != null && !clazz.isAssignableFrom(result.getClass())) {
throw new ClassCastException("Result [" + result + " is of type " + result.getClass() + " when we were expecting " + clazz);
}
return (T) result;
}
LOGGER.warn("[{}] script [{}] does not exist, or cannot be loaded", StringUtils.capitalize(engineName), scriptFile);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
Aggregations