Search in sources :

Example 21 with DefaultResourceLoader

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

the class DroolsTicketerServiceLayerTest method setUp.

@Before
public void setUp() throws Exception {
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    MockLogAppender.setupLogging();
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource = loader.getResource("classpath:/drools-ticketer-rules.drl");
    m_easyMockUtils = new EasyMockUtils();
    m_configDao = m_easyMockUtils.createMock(DroolsTicketerConfigDao.class);
    EasyMock.expect(m_configDao.getRulesFile()).andReturn(resource.getFile()).times(1);
    EasyMock.replay(m_configDao);
    m_alarmDao = m_easyMockUtils.createMock(AlarmDao.class);
    m_ticketerPlugin = m_easyMockUtils.createMock(Plugin.class);
    m_droolsTicketerServiceLayer = new DroolsTicketerServiceLayer(m_configDao);
    m_droolsTicketerServiceLayer.setAlarmDao(m_alarmDao);
    m_droolsTicketerServiceLayer.setTicketerPlugin(m_ticketerPlugin);
    EasyMock.reset(m_configDao);
    m_alarm = new OnmsAlarm();
    m_alarm.setId(1);
    m_alarm.setLogMsg("Test Logmsg");
    m_alarm.setDescription("Test Description");
    m_alarm.setUei("uei.opennms.org/nodes/nodeDown");
    m_ticket = new Ticket();
    m_ticket.setId("4");
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Ticket(org.opennms.api.integration.ticketing.Ticket) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Resource(org.springframework.core.io.Resource) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Plugin(org.opennms.api.integration.ticketing.Plugin) Before(org.junit.Before)

Example 22 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project chassis by Kixeye.

the class JettyConnectorRegistry method registerHttpsConnector.

/**
     * Register to listen to HTTPS.
     * 
     * @param server
     * @param address
     * @throws Exception 
     */
public static void registerHttpsConnector(Server server, InetSocketAddress address, boolean selfSigned, boolean mutualSsl, String keyStorePath, String keyStoreData, String keyStorePassword, String keyManagerPassword, String trustStorePath, String trustStoreData, String trustStorePassword, String[] excludedCipherSuites) throws Exception {
    // SSL Context Factory
    SslContextFactory sslContextFactory = new SslContextFactory();
    if (selfSigned) {
        char[] passwordChars = UUID.randomUUID().toString().toCharArray();
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(null, passwordChars);
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
        keyPairGenerator.initialize(1024);
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();
        v3CertGen.setSerialNumber(BigInteger.valueOf(new SecureRandom().nextInt()).abs());
        v3CertGen.setIssuerDN(new X509Principal("CN=" + "kixeye.com" + ", OU=None, O=None L=None, C=None"));
        v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30));
        v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365 * 10)));
        v3CertGen.setSubjectDN(new X509Principal("CN=" + "kixeye.com" + ", OU=None, O=None L=None, C=None"));
        v3CertGen.setPublicKey(keyPair.getPublic());
        v3CertGen.setSignatureAlgorithm("MD5WithRSAEncryption");
        X509Certificate privateKeyCertificate = v3CertGen.generateX509Certificate(keyPair.getPrivate());
        keyStore.setKeyEntry("selfSigned", keyPair.getPrivate(), passwordChars, new java.security.cert.Certificate[] { privateKeyCertificate });
        ByteArrayOutputStream keyStoreBaos = new ByteArrayOutputStream();
        keyStore.store(keyStoreBaos, passwordChars);
        keyStoreData = new String(Hex.encode(keyStoreBaos.toByteArray()), Charsets.UTF_8);
        keyStorePassword = new String(passwordChars);
        keyManagerPassword = keyStorePassword;
        sslContextFactory.setTrustAll(true);
    }
    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    if (StringUtils.isNotBlank(keyStoreData)) {
        keyStore.load(new ByteArrayInputStream(Hex.decode(keyStoreData)), keyStorePassword.toCharArray());
    } else if (StringUtils.isNotBlank(keyStorePath)) {
        try (InputStream inputStream = new DefaultResourceLoader().getResource(keyStorePath).getInputStream()) {
            keyStore.load(inputStream, keyStorePassword.toCharArray());
        }
    }
    sslContextFactory.setKeyStore(keyStore);
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    if (StringUtils.isBlank(keyManagerPassword)) {
        keyManagerPassword = keyStorePassword;
    }
    sslContextFactory.setKeyManagerPassword(keyManagerPassword);
    KeyStore trustStore = null;
    if (StringUtils.isNotBlank(trustStoreData)) {
        trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(new ByteArrayInputStream(Hex.decode(trustStoreData)), trustStorePassword.toCharArray());
    } else if (StringUtils.isNotBlank(trustStorePath)) {
        trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        try (InputStream inputStream = new DefaultResourceLoader().getResource(trustStorePath).getInputStream()) {
            trustStore.load(inputStream, trustStorePassword.toCharArray());
        }
    }
    if (trustStore != null) {
        sslContextFactory.setTrustStore(trustStore);
        sslContextFactory.setTrustStorePassword(trustStorePassword);
    }
    sslContextFactory.setNeedClientAuth(mutualSsl);
    sslContextFactory.setExcludeCipherSuites(excludedCipherSuites);
    // SSL Connector
    ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString()), new HttpConnectionFactory());
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.addConnector(connector);
}
Also used : KeyPair(java.security.KeyPair) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) KeyStore(java.security.KeyStore) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) X509V3CertificateGenerator(org.bouncycastle.x509.X509V3CertificateGenerator) X509Principal(org.bouncycastle.jce.X509Principal) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 23 with DefaultResourceLoader

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

the class SpringApplication method printBanner.

private Banner printBanner(ConfigurableEnvironment environment) {
    if (this.bannerMode == Banner.Mode.OFF) {
        return null;
    }
    ResourceLoader resourceLoader = this.resourceLoader != null ? this.resourceLoader : new DefaultResourceLoader(getClassLoader());
    SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(resourceLoader, this.banner);
    if (this.bannerMode == Mode.LOG) {
        return bannerPrinter.print(environment, this.mainApplicationClass, logger);
    }
    return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 24 with DefaultResourceLoader

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

the class SpringApplicationTests method customResourceLoaderFromConstructor.

@Test
public void customResourceLoaderFromConstructor() throws Exception {
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    TestSpringApplication application = new TestSpringApplication(resourceLoader, ExampleWebConfig.class);
    this.context = application.run();
    verify(application.getLoader()).setResourceLoader(resourceLoader);
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test)

Example 25 with DefaultResourceLoader

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

the class SpringApplicationTests method customResourceLoader.

@Test
public void customResourceLoader() throws Exception {
    TestSpringApplication application = new TestSpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    application.setResourceLoader(resourceLoader);
    this.context = application.run();
    verify(application.getLoader()).setResourceLoader(resourceLoader);
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test)

Aggregations

DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)39 Test (org.junit.Test)24 ResourceLoader (org.springframework.core.io.ResourceLoader)8 Before (org.junit.Before)5 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 Resource (org.springframework.core.io.Resource)4 URLClassLoader (java.net.URLClassLoader)3 DefaultNamedComponent (example.scannable.DefaultNamedComponent)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 X509Certificate (java.security.cert.X509Certificate)2 SnmpAgentAddress (org.opennms.netmgt.snmp.SnmpAgentAddress)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 Context (ch.qos.logback.core.Context)1 DevComponent (example.profilescan.DevComponent)1 ProfileAnnotatedComponent (example.profilescan.ProfileAnnotatedComponent)1 ProfileMetaAnnotatedComponent (example.profilescan.ProfileMetaAnnotatedComponent)1 CustomStereotype (example.scannable.CustomStereotype)1 FooDao (example.scannable.FooDao)1