Java Code Examples for org.springframework.core.io.DefaultResourceLoader#getResource()

The following examples show how to use org.springframework.core.io.DefaultResourceLoader#getResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallbacksSecurityTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	final ProtectionDomain empty = new ProtectionDomain(null,
			new Permissions());

	provider = new SecurityContextProvider() {
		private final AccessControlContext acc = new AccessControlContext(
				new ProtectionDomain[] { empty });

		@Override
		public AccessControlContext getAccessControlContext() {
			return acc;
		}
	};

	DefaultResourceLoader drl = new DefaultResourceLoader();
	Resource config = drl
			.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
	beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
	beanFactory.setSecurityContextProvider(provider);
}
 
Example 2
Source File: CallbacksSecurityTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	final ProtectionDomain empty = new ProtectionDomain(null,
			new Permissions());

	provider = new SecurityContextProvider() {
		private final AccessControlContext acc = new AccessControlContext(
				new ProtectionDomain[] { empty });

		@Override
		public AccessControlContext getAccessControlContext() {
			return acc;
		}
	};

	DefaultResourceLoader drl = new DefaultResourceLoader();
	Resource config = drl
			.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
	beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
	beanFactory.setSecurityContextProvider(provider);
}
 
Example 3
Source File: CallbacksSecurityTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	final ProtectionDomain empty = new ProtectionDomain(null,
			new Permissions());

	provider = new SecurityContextProvider() {
		private final AccessControlContext acc = new AccessControlContext(
				new ProtectionDomain[] { empty });

		@Override
		public AccessControlContext getAccessControlContext() {
			return acc;
		}
	};

	DefaultResourceLoader drl = new DefaultResourceLoader();
	Resource config = drl
			.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
	beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
	beanFactory.setSecurityContextProvider(provider);
}
 
Example 4
Source File: DummyFallbackContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
protected Resource getDummyFileResource(final String mimetype)
{
    final String extension = this.mimetypeService.getExtension(mimetype);
    Resource resource = null;
    final List<String> pathsToSearch = new ArrayList<>(this.dummyFilePaths);
    Collections.reverse(pathsToSearch);

    final DefaultResourceLoader resourceLoader = new DefaultResourceLoader();

    for (final String path : pathsToSearch)
    {
        resource = resourceLoader.getResource(path + "/dummy." + extension);
        if (resource != null)
        {
            if (resource.exists())
            {
                break;
            }
            // nope'd
            resource = null;
        }
    }
    LOGGER.trace("Found dummy file resource {} for extension {}", resource, extension);
    return resource;
}
 
Example 5
Source File: SimpleStorageProtocolResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void testGetResourceWithExistingResource() {

	AmazonS3 amazonS3 = mock(AmazonS3.class);

	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(new SimpleStorageProtocolResolver(amazonS3));

	ObjectMetadata metadata = new ObjectMetadata();
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(metadata);

	String resourceName = "s3://bucket/object/";
	Resource resource = resourceLoader.getResource(resourceName);
	assertThat(resource).isNotNull();
}
 
Example 6
Source File: SmooksGenerator.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
public SmooksGenerator() {
    complexTypes = new HashMap<String, XmlSchemaComplexType>();
    simpleTypes = new HashMap<String, XmlSchemaSimpleType>();
    complexTypesData = new HashMap<String, ComplexTypeData>();

    resourceLoader = new DefaultResourceLoader();
    Resource xsdResource = resourceLoader.getResource(xsdLocation);
    Resource extensionXsdResource = resourceLoader.getResource(extensionXsdLocation);

    // extract complex types from base schema
    cacheTypesFromResource(xsdResource, xsdParentLocation);
    // extract complex types from extension schema
    cacheTypesFromResource(extensionXsdResource, extensionXsdParentLocation);

    // extract data from complex data including hierarchy
    cacheComplexTypeData();
}
 
Example 7
Source File: WebSecurityConfig.java    From spring-tsers-auth with Apache License 2.0 5 votes vote down vote up
@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader
            .getResource("classpath:/saml/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}
 
Example 8
Source File: WebSecurityConfig.java    From spring-tsers-auth with Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("idp-ssocircle")
public ExtendedMetadataDelegate ssoCircleExtendedMetadataProvider()
        throws MetadataProviderException {


    AbstractMetadataProvider provider = new AbstractMetadataProvider() {
        @Override
        protected XMLObject doGetMetadata() throws MetadataProviderException {
            DefaultResourceLoader loader = new DefaultResourceLoader();
            Resource storeFile = loader.getResource("classPath:/saml/idp-metadata.xml");

            ParserPool parser = parserPool();
            try {
                Document mdDocument = parser.parse(storeFile.getInputStream());
                Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(mdDocument.getDocumentElement());
                return unmarshaller.unmarshall(mdDocument.getDocumentElement());
            } catch (Exception e) {
                e.printStackTrace();
                throw new MetadataProviderException();
            }


        }
    };
    ExtendedMetadataDelegate extendedMetadataDelegate =
            new ExtendedMetadataDelegate(provider, extendedMetadata());
    extendedMetadataDelegate.setMetadataTrustCheck(false);
    extendedMetadataDelegate.setMetadataRequireSignature(false);
    return extendedMetadataDelegate;
}
 
Example 9
Source File: WebSecurityConfig.java    From spring-boot-security-saml-sample with Apache License 2.0 5 votes vote down vote up
@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader
            .getResource("classpath:/saml/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}
 
Example 10
Source File: SimpleStorageProtocolResolverTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testGetResourceWithNonExistingResource() {

	AmazonS3 amazonS3 = mock(AmazonS3.class);

	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(new SimpleStorageProtocolResolver(amazonS3));

	String resourceName = "s3://bucket/object/";
	Resource resource = resourceLoader.getResource(resourceName);
	assertThat(resource).isNotNull();
}
 
Example 11
Source File: SimpleStorageProtocolResolverTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testValidS3Pattern() {
	AmazonS3 amazonS3 = mock(AmazonS3.class);

	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(new SimpleStorageProtocolResolver(amazonS3));

	// None of the patterns below should throw an exception
	resourceLoader.getResource("s3://bucket/key");
	resourceLoader.getResource("S3://BuCket/key");
	resourceLoader.getResource("s3://bucket/folder1/folder2/key");
	resourceLoader.getResource("s3://bucket/folder1/folder2/key^versionIdValue");
}
 
Example 12
Source File: PropertyLoader.java    From cougar with Apache License 2.0 5 votes vote down vote up
/**
 * @return returns an array of validated Resources for use with overlaid property files
 */
public Resource[] constructResourceList() {
    String configHost = System.getProperties().getProperty(DEFAULT_CONFIG_HOST_PROPERTY);
    if (configHost == null) {
        log("No config Host defined - assuming " + DEFAULT_CONFIG_HOST_PROPERTY_VALUE);
        configHost = DEFAULT_CONFIG_HOST_PROPERTY_VALUE;
    }
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource configOverrideResource = loader.getResource(configHost + configOverride);

    return handleConfig(defaultConfig, appProperties, configOverrideResource);

}
 
Example 13
Source File: TestHelper.java    From tutorials with MIT License 5 votes vote down vote up
private void runScript(String scriptName, DataSource dataSouorce) throws SQLException {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource script = resourceLoader.getResource(scriptName);
    try (Connection con = dataSouorce.getConnection()) {
        ScriptUtils.executeSqlScript(con, script);
    }
}
 
Example 14
Source File: AbstractWebAppContextLoader.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void loadPropertiesFromConfig(ServletContext sc, Properties properties, String propsConfigName) {
    SpringProfileSpecificNameResolver nameResolver = new SpringProfileSpecificNameResolver(sc);
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    StringTokenizer tokenizer = new StringTokenizer(propsConfigName);
    tokenizer.setQuoteChar('"');
    for (String str : tokenizer.getTokenArray()) {
        log.trace("Processing properties location: {}", str);
        String baseName = StringSubstitutor.replaceSystemProperties(str);
        for (String name : nameResolver.getDerivedNames(baseName)) {
            InputStream stream = null;
            try {
                if (ResourceUtils.isUrl(name) || name.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
                    Resource resource = resourceLoader.getResource(name);
                    if (resource.exists())
                        stream = resource.getInputStream();
                } else {
                    stream = sc.getResourceAsStream(name);
                }

                if (stream != null) {
                    log.info("Loading app properties from {}", name);
                    BOMInputStream bomInputStream = new BOMInputStream(stream);
                    try (Reader reader = new InputStreamReader(bomInputStream, StandardCharsets.UTF_8)) {
                        properties.load(reader);
                    }
                } else {
                    log.trace("Resource {} not found, ignore it", name);
                }
            } catch (IOException e) {
                throw new RuntimeException("Unable to read properties from stream", e);
            } finally {
                try {
                    if (stream != null) {
                        stream.close();
                    }
                } catch (final IOException ioe) {
                    // ignore
                }
            }
        }
    }
}
 
Example 15
Source File: DataDictionary.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Resource getFileResource(String sourceName) {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
    return resourceLoader.getResource(sourceName);
}
 
Example 16
Source File: DataDictionary.java    From rice with Educational Community License v2.0 4 votes vote down vote up
protected Resource getFileResource(String sourceName) {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());

    return resourceLoader.getResource(sourceName);
}