Search in sources :

Example 56 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project spring-framework by spring-projects.

the class WebFluxConfigurationSupport method resourceHandlerMapping.

/**
 * Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped
 * resource handlers. To configure resource handling, override
 * {@link #addResourceHandlers}.
 */
@Bean
public HandlerMapping resourceHandlerMapping(ResourceUrlProvider resourceUrlProvider) {
    ResourceLoader resourceLoader = this.applicationContext;
    if (resourceLoader == null) {
        resourceLoader = new DefaultResourceLoader();
    }
    ResourceHandlerRegistry registry = new ResourceHandlerRegistry(resourceLoader);
    registry.setResourceUrlProvider(resourceUrlProvider);
    addResourceHandlers(registry);
    AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
    if (handlerMapping != null) {
        configureAbstractHandlerMapping(handlerMapping, getPathMatchConfigurer());
    } else {
        handlerMapping = new EmptyHandlerMapping();
    }
    return handlerMapping;
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) AbstractHandlerMapping(org.springframework.web.reactive.handler.AbstractHandlerMapping) Bean(org.springframework.context.annotation.Bean)

Example 57 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project dhis2-core by dhis2.

the class HelpAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    List<Locale> locales = localeManager.getLocalesOrderedByPriority();
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    for (Locale locale : locales) {
        String helpPage = helpPagePreLocale + locale.toString() + helpPagePostLocale;
        if (resourceLoader.getResource(helpPage) != null) {
            this.helpPage = helpPage;
            return SUCCESS;
        }
    }
    return SUCCESS;
}
Also used : Locale(java.util.Locale) ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 58 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project OpenClinica by OpenClinica.

the class LoggerStartupListener method start.

@Override
public void start() {
    if (started)
        return;
    Context context = getContext();
    if (resourceLoader == null)
        resourceLoader = new DefaultResourceLoader();
    try {
        webapp = getWebAppName(resourceLoader.getResource("/").getURI().getPath());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        DATAINFO = loadProperties("datainfo.properties");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    getPropertiesSource();
    context.putProperty("log.dir", getField("log.dir"));
    context.putProperty("logLocation", getField("logLocation"));
    context.putProperty("logLevel", getField("logLevel"));
    context.putProperty("syslog.host", getField("syslog.host"));
    context.putProperty("syslog.port", getField("syslog.port"));
    context.putProperty("collectStats", getField("collectStats"));
    context.putProperty("usage.stats.host", getField("usage.stats.host"));
    context.putProperty("usage.stats.port", getField("usage.stats.port"));
    context.putProperty("OpenClinica.version", getField("OpenClinica.version"));
    started = true;
}
Also used : Context(ch.qos.logback.core.Context) LoggerContext(ch.qos.logback.classic.LoggerContext) IOException(java.io.IOException) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 59 with DefaultResourceLoader

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

the class ResourceUtilsTests method verifyResourceExists.

@Test
public void verifyResourceExists() {
    assertThrows(IllegalArgumentException.class, () -> ResourceUtils.getRawResourceFrom(null));
    assertFalse(ResourceUtils.doesResourceExist(new FileSystemResource("invalid.json")));
    val resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource(anyString())).thenThrow(new RuntimeException());
    assertFalse(ResourceUtils.doesResourceExist("bad-resource", resourceLoader));
    assertFalse(ResourceUtils.doesResourceExist(null, resourceLoader));
    assertFalse(ResourceUtils.doesResourceExist("invalid.json"));
    assertTrue(ResourceUtils.doesResourceExist("classpath:valid.json", new DefaultResourceLoader(ResourceUtilsTests.class.getClassLoader())));
}
Also used : lombok.val(lombok.val) FileSystemResource(org.springframework.core.io.FileSystemResource) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.jupiter.api.Test)

Example 60 with DefaultResourceLoader

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

the class CoreAuthenticationUtils method newCredentialSelectionPredicate.

/**
 * Gets credential selection predicate.
 *
 * @param selectionCriteria the selection criteria
 * @return the credential selection predicate
 */
public static Predicate<Credential> newCredentialSelectionPredicate(final String selectionCriteria) {
    try {
        if (StringUtils.isBlank(selectionCriteria)) {
            return credential -> true;
        }
        if (selectionCriteria.endsWith(".groovy")) {
            val loader = new DefaultResourceLoader();
            val resource = loader.getResource(selectionCriteria);
            val script = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
            val classLoader = new GroovyClassLoader(Beans.class.getClassLoader(), new CompilerConfiguration(), true);
            val clz = classLoader.parseClass(script);
            return (Predicate<Credential>) clz.getDeclaredConstructor().newInstance();
        }
        val predicateClazz = ClassUtils.getClass(selectionCriteria);
        return (Predicate<Credential>) predicateClazz.getDeclaredConstructor().newInstance();
    } catch (final Exception e) {
        val predicate = Pattern.compile(selectionCriteria).asPredicate();
        return credential -> predicate.test(credential.getId());
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Arrays(java.util.Arrays) ReplacingAttributeAdder(org.apereo.services.persondir.support.merger.ReplacingAttributeAdder) GroovyPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.GroovyPasswordPolicyHandlingStrategy) Assertion(org.apereo.cas.validation.Assertion) GroovyIPAddressIntelligenceService(org.apereo.cas.authentication.adaptive.intel.GroovyIPAddressIntelligenceService) Beans(org.apereo.cas.configuration.support.Beans) StringUtils(org.apache.commons.lang3.StringUtils) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ClassUtils(org.apache.commons.lang3.ClassUtils) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Splitter(com.google.common.base.Splitter) DefaultIPAddressIntelligenceService(org.apereo.cas.authentication.adaptive.intel.DefaultIPAddressIntelligenceService) Unchecked(org.jooq.lambda.Unchecked) Predicate(java.util.function.Predicate) Collection(java.util.Collection) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) IAttributeMerger(org.apereo.services.persondir.support.merger.IAttributeMerger) Set(java.util.Set) MultivaluedAttributeMerger(org.apereo.services.persondir.support.merger.MultivaluedAttributeMerger) AuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.AuthenticationPolicyProperties) Collectors(java.util.stream.Collectors) PasswordPolicyProperties(org.apereo.cas.configuration.model.core.authentication.PasswordPolicyProperties) IPersonAttributeDaoFilter(org.apereo.services.persondir.IPersonAttributeDaoFilter) StandardCharsets(java.nio.charset.StandardCharsets) RejectResultCodePasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.RejectResultCodePasswordPolicyHandlingStrategy) IOUtils(org.apache.commons.io.IOUtils) AllCredentialsValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AllCredentialsValidatedAuthenticationPolicy) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) IPAddressIntelligenceService(org.apereo.cas.authentication.adaptive.intel.IPAddressIntelligenceService) Optional(java.util.Optional) Principal(org.apereo.cas.authentication.principal.Principal) PrincipalResolutionContext(org.apereo.cas.authentication.principal.resolvers.PrincipalResolutionContext) Pattern(java.util.regex.Pattern) GroovyClassLoader(groovy.lang.GroovyClassLoader) AtLeastOneCredentialValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy) RequiredAuthenticationHandlerAuthenticationPolicy(org.apereo.cas.authentication.policy.RequiredAuthenticationHandlerAuthenticationPolicy) AllAuthenticationHandlersSucceededAuthenticationPolicy(org.apereo.cas.authentication.policy.AllAuthenticationHandlersSucceededAuthenticationPolicy) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) RestfulIPAddressIntelligenceService(org.apereo.cas.authentication.adaptive.intel.RestfulIPAddressIntelligenceService) Multimap(com.google.common.collect.Multimap) PersonDirectoryPrincipalResolverProperties(org.apereo.cas.configuration.model.core.authentication.PersonDirectoryPrincipalResolverProperties) NoncollidingAttributeAdder(org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder) ArrayList(java.util.ArrayList) UtilityClass(lombok.experimental.UtilityClass) LinkedHashMap(java.util.LinkedHashMap) NotPreventedAuthenticationPolicy(org.apereo.cas.authentication.policy.NotPreventedAuthenticationPolicy) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) CollectionUtils(org.apereo.cas.util.CollectionUtils) ChainingPrincipalNameTransformer(org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) BaseAdditiveAttributeMerger(org.apereo.services.persondir.support.merger.BaseAdditiveAttributeMerger) lombok.val(lombok.val) GroovyScriptAuthenticationPolicy(org.apereo.cas.authentication.policy.GroovyScriptAuthenticationPolicy) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ApplicationContext(org.springframework.context.ApplicationContext) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) TriStateBoolean(org.apereo.cas.util.model.TriStateBoolean) PrincipalNameTransformerUtils(org.apereo.cas.authentication.principal.PrincipalNameTransformerUtils) DefaultPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.DefaultPasswordPolicyHandlingStrategy) PrincipalAttributesCoreProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesCoreProperties) RestfulAuthenticationPolicy(org.apereo.cas.authentication.policy.RestfulAuthenticationPolicy) Collections(java.util.Collections) lombok.val(lombok.val) GroovyClassLoader(groovy.lang.GroovyClassLoader) Beans(org.apereo.cas.configuration.support.Beans) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Predicate(java.util.function.Predicate)

Aggregations

DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)68 Test (org.junit.jupiter.api.Test)28 ResourceLoader (org.springframework.core.io.ResourceLoader)20 Resource (org.springframework.core.io.Resource)10 Before (org.junit.Before)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 IOException (java.io.IOException)6 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)6 URLClassLoader (java.net.URLClassLoader)4 Test (org.junit.Test)4 Environment (org.springframework.core.env.Environment)4 InputStream (java.io.InputStream)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)3 LRUCacheManager (io.syndesis.common.util.cache.LRUCacheManager)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)2 File (java.io.File)2