Search in sources :

Example 61 with FileSystemResource

use of org.springframework.core.io.FileSystemResource 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;
}
Also used : AbstractResource(org.springframework.core.io.AbstractResource) FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 62 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project cas by apereo.

the class GoogleAccountsServiceResponseBuilder method createGoogleAppsPrivateKey.

/**
 * Create the private key.
 *
 * @throws Exception if key creation ran into an error
 */
protected void createGoogleAppsPrivateKey() throws Exception {
    if (!isValidConfiguration()) {
        LOGGER.debug("Google Apps private key bean will not be created, because it's not configured");
        return;
    }
    final PrivateKeyFactoryBean bean = new PrivateKeyFactoryBean();
    if (this.privateKeyLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
        bean.setLocation(new ClassPathResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.CLASSPATH_URL_PREFIX)));
    } else if (this.privateKeyLocation.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
        bean.setLocation(new FileSystemResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.FILE_URL_PREFIX)));
    } else {
        bean.setLocation(new FileSystemResource(this.privateKeyLocation));
    }
    bean.setAlgorithm(this.keyAlgorithm);
    LOGGER.debug("Loading Google Apps private key from [{}] with key algorithm [{}]", bean.getLocation(), bean.getAlgorithm());
    bean.afterPropertiesSet();
    LOGGER.debug("Creating Google Apps private key instance via [{}]", this.privateKeyLocation);
    this.privateKey = bean.getObject();
}
Also used : PrivateKeyFactoryBean(org.apereo.cas.util.crypto.PrivateKeyFactoryBean) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 63 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project cas by apereo.

the class FileTrustStoreSslSocketFactoryTests method verifyTrustStoreNotFound.

@Test
public void verifyTrustStoreNotFound() {
    this.thrown.expect(FileNotFoundException.class);
    sslFactory(new FileSystemResource("test.jks"), "changeit");
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

Example 64 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project cas by apereo.

the class DefaultCasConfigurationPropertiesSourceLocator method loadSettingsByApplicationProfiles.

private PropertySource<?> loadSettingsByApplicationProfiles(final Environment environment, final File config) {
    final Properties props = new Properties();
    final List<String> profiles = getApplicationProfiles(environment);
    final String regex = buildPatternForConfigurationFileDiscovery(config, profiles);
    final Collection<File> configFiles = scanForConfigurationFilesByPattern(config, regex);
    LOGGER.info("Configuration files found at [{}] are [{}]", config, configFiles);
    configFiles.forEach(Unchecked.consumer(f -> {
        LOGGER.debug("Loading configuration file [{}]", f);
        if (f.getName().toLowerCase().endsWith("yml")) {
            final Map<String, Object> pp = loadYamlProperties(new FileSystemResource(f));
            LOGGER.debug("Found settings [{}] in YAML file [{}]", pp.keySet(), f);
            props.putAll(decryptProperties(pp));
        } else {
            final Properties pp = new Properties();
            pp.load(Files.newBufferedReader(f.toPath(), StandardCharsets.UTF_8));
            LOGGER.debug("Found settings [{}] in file [{}]", pp.keySet(), f);
            props.putAll(decryptProperties(pp));
        }
    }));
    return new PropertiesPropertySource("applicationProfilesProperties", props);
}
Also used : Arrays(java.util.Arrays) IOCase(org.apache.commons.io.IOCase) PropertySource(org.springframework.core.env.PropertySource) ArrayList(java.util.ArrayList) Map(java.util.Map) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) Resource(org.springframework.core.io.Resource) Unchecked(org.jooq.lambda.Unchecked) ResourceLoader(org.springframework.core.io.ResourceLoader) Properties(java.util.Properties) Files(java.nio.file.Files) Collection(java.util.Collection) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileUtils(org.apache.commons.io.FileUtils) Reader(java.io.Reader) CipherExecutor(org.apereo.cas.CipherExecutor) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) CompositePropertySource(org.springframework.core.env.CompositePropertySource) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Environment(org.springframework.core.env.Environment) AllArgsConstructor(lombok.AllArgsConstructor) Comparator(java.util.Comparator) CasConfigurationPropertiesSourceLocator(org.apereo.cas.configuration.api.CasConfigurationPropertiesSourceLocator) YamlProcessor(org.springframework.beans.factory.config.YamlProcessor) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) FileSystemResource(org.springframework.core.io.FileSystemResource) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map)

Example 65 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class PropertiesGraphDaoIT method testLoadSnmpGraphProperties.

@Test
public void testLoadSnmpGraphProperties() throws Exception {
    PropertiesGraphDao dao = createPropertiesGraphDao(s_emptyMap, s_emptyMap);
    dao.loadProperties("foo", new FileSystemResource(ConfigurationTestUtils.getFileForConfigFile("snmp-graph.properties")));
    for (PrefabGraph graph : dao.getAllPrefabGraphs()) {
        if (!graph.getCommand().trim().equals(graph.getCommand())) {
            fail("Prefab graph contains extra whitespace: " + graph.getCommand());
        }
    }
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

Aggregations

FileSystemResource (org.springframework.core.io.FileSystemResource)148 File (java.io.File)77 Test (org.junit.Test)44 Resource (org.springframework.core.io.Resource)42 Before (org.junit.Before)27 ClassPathResource (org.springframework.core.io.ClassPathResource)16 IOException (java.io.IOException)12 FileWriter (java.io.FileWriter)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Properties (java.util.Properties)8 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)8 FileOutputStream (java.io.FileOutputStream)7 URL (java.net.URL)7 InputStreamResource (org.springframework.core.io.InputStreamResource)7 UrlResource (org.springframework.core.io.UrlResource)7 Date (java.util.Date)5 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)5 FileReader (java.io.FileReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4