Search in sources :

Example 11 with FileSystemResource

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

the class SamlIdPConfiguration method casSamlIdPMetadataResolver.

@Bean
public MetadataResolver casSamlIdPMetadataResolver() {
    try {
        final SamlIdPProperties idp = casProperties.getAuthn().getSamlIdp();
        final ResourceBackedMetadataResolver resolver = new ResourceBackedMetadataResolver(ResourceHelper.of(new FileSystemResource(idp.getMetadata().getMetadataFile())));
        resolver.setParserPool(this.openSamlConfigBean.getParserPool());
        resolver.setFailFastInitialization(idp.getMetadata().isFailFast());
        resolver.setRequireValidMetadata(idp.getMetadata().isRequireValidMetadata());
        resolver.setId(idp.getEntityId());
        resolver.initialize();
        return resolver;
    } catch (final Exception e) {
        throw new BeanCreationException(e.getMessage(), e);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) ResourceBackedMetadataResolver(org.opensaml.saml.metadata.resolver.impl.ResourceBackedMetadataResolver) FileSystemResource(org.springframework.core.io.FileSystemResource) BeanCreationException(org.springframework.beans.factory.BeanCreationException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with FileSystemResource

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

the class BaseSamlObjectSigner method getSigningCertificate.

/**
     * Gets signing certificate.
     *
     * @return the signing certificate
     * @throws Exception the exception
     */
protected X509Certificate getSigningCertificate() throws Exception {
    final SamlIdPProperties samlIdp = casProperties.getAuthn().getSamlIdp();
    LOGGER.debug("Locating signature signing certificate file from [{}]", samlIdp.getMetadata().getSigningCertFile());
    return SamlUtils.readCertificate(new FileSystemResource(samlIdp.getMetadata().getSigningCertFile().getFile()));
}
Also used : SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 13 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project grails-core by grails.

the class AbstractGrailsPluginManager method informOfClassChange.

public void informOfClassChange(File file, @SuppressWarnings("rawtypes") Class cls) {
    if (file.getName().equals(CONFIG_FILE)) {
        ConfigSlurper configSlurper = getConfigSlurper(application);
        ConfigObject c;
        try {
            c = configSlurper.parse(file.toURI().toURL());
            application.getConfig().merge(c);
            final Map flat = c.flatten();
            application.getConfig().merge(flat);
            application.configChanged();
            informPluginsOfConfigChange();
        } catch (Exception e) {
            // ignore
            LOG.debug("Error in changing Config", e);
        }
    } else {
        if (cls != null) {
            MetaClassRegistry registry = GroovySystem.getMetaClassRegistry();
            registry.removeMetaClass(cls);
            ExpandoMetaClass newMc = new ExpandoMetaClass(cls, true, true);
            newMc.initialize();
            registry.setMetaClass(cls, newMc);
            Enhanced en = AnnotationUtils.findAnnotation(cls, Enhanced.class);
            if (en != null) {
                Class<?>[] mixinClasses = en.mixins();
                if (mixinClasses != null) {
                    DefaultGroovyMethods.mixin(newMc, mixinClasses);
                }
            }
        }
        for (GrailsPlugin grailsPlugin : pluginList) {
            if (grailsPlugin.hasInterestInChange(file.getAbsolutePath())) {
                try {
                    if (cls == null) {
                        grailsPlugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, new FileSystemResource(file));
                    } else {
                        grailsPlugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, cls);
                    }
                    Environment.setCurrentReloadError(null);
                } catch (Exception e) {
                    LOG.error("Plugin " + grailsPlugin + " could not reload changes to file [" + file + "]: " + e.getMessage(), e);
                    Environment.setCurrentReloadError(e);
                }
            }
        }
    }
}
Also used : MetaClassRegistry(groovy.lang.MetaClassRegistry) GrailsPlugin(grails.plugins.GrailsPlugin) Enhanced(grails.artefact.Enhanced) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) FileSystemResource(org.springframework.core.io.FileSystemResource) ConfigObject(groovy.util.ConfigObject) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(org.grails.config.NavigableMap) BeansException(org.springframework.beans.BeansException) PluginException(grails.plugins.exceptions.PluginException) ConfigSlurper(groovy.util.ConfigSlurper)

Example 14 with FileSystemResource

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

the class JaxbResourceConfigurationTest method testFileSystemResourceDoesNotExist.

@Test(expected = org.opennms.core.config.api.ConfigurationResourceException.class)
public void testFileSystemResourceDoesNotExist() throws ConfigurationResourceException {
    final File configFile = new File("target/test-classes/collectd-configuration.x");
    final ConfigurationResource<CollectdConfiguration> collectd = new JaxbResourceConfiguration<CollectdConfiguration>(CollectdConfiguration.class, new FileSystemResource(configFile));
    assertNotNull(collectd);
    collectd.get();
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 15 with FileSystemResource

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

the class JaxbResourceConfigurationTest method testSave.

@Test
public void testSave() throws ConfigurationResourceException, IOException {
    final File configFile = getConfigFile();
    final ConfigurationResource<CollectdConfiguration> collectd = new JaxbResourceConfiguration<CollectdConfiguration>(CollectdConfiguration.class, new FileSystemResource(configFile));
    assertNotNull(collectd);
    CollectdConfiguration config = collectd.get();
    assertNotNull(config);
    assertEquals(5, config.getPackages().size());
    config.removePackage(config.getPackages().get(0));
    assertEquals("vmware4", config.getPackages().get(0).getName());
    assertEquals(4, config.getPackages().size());
    collectd.save(config);
    config = collectd.get();
    assertNotNull(config);
    assertEquals(4, config.getPackages().size());
    assertEquals("vmware4", config.getPackages().get(0).getName());
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Aggregations

FileSystemResource (org.springframework.core.io.FileSystemResource)128 File (java.io.File)66 Test (org.junit.Test)41 Resource (org.springframework.core.io.Resource)35 Before (org.junit.Before)21 ClassPathResource (org.springframework.core.io.ClassPathResource)13 IOException (java.io.IOException)11 FileWriter (java.io.FileWriter)10 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)8 FileOutputStream (java.io.FileOutputStream)7 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 InputStreamResource (org.springframework.core.io.InputStreamResource)7 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)6 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)5 FileReader (java.io.FileReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Ehcache (net.sf.ehcache.Ehcache)4