Search in sources :

Example 26 with InputStreamResource

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

the class X509CredentialFactory method fromRequestBody.

@Override
public Credential fromRequestBody(final MultiValueMap<String, String> requestBody) {
    final String cert = requestBody.getFirst(CERTIFICATE);
    LOGGER.trace("cert: {}", cert);
    if (cert == null) {
        LOGGER.debug("cert is null fallback to username/passwd");
        return super.fromRequestBody(requestBody);
    }
    final InputStream is = new ByteArrayInputStream(cert.getBytes());
    final InputStreamSource iso = new InputStreamResource(is);
    final X509Certificate certificate = CertUtils.readCertificate(iso);
    final X509CertificateCredential credential = new X509CertificateCredential(new X509Certificate[] { certificate });
    credential.setCertificate(certificate);
    return credential;
}
Also used : InputStreamSource(org.springframework.core.io.InputStreamSource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) X509CertificateCredential(org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential) X509Certificate(java.security.cert.X509Certificate) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 27 with InputStreamResource

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

the class HttpRangeTests method toResourceRegionInputStreamResource.

@Test(expected = IllegalArgumentException.class)
public void toResourceRegionInputStreamResource() {
    InputStreamResource resource = mock(InputStreamResource.class);
    HttpRange range = HttpRange.createByteRange(0, 9);
    range.toResourceRegion(resource);
}
Also used : InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 28 with InputStreamResource

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

the class DefaultStatisticsDaemonConfigDaoTest method testGetReports.

public void testGetReports() throws Exception {
    DefaultStatisticsDaemonConfigDao dao = new DefaultStatisticsDaemonConfigDao();
    InputStream in = ConfigurationTestUtils.getInputStreamForConfigFile("statsd-configuration.xml");
    dao.setConfigResource(new InputStreamResource(in));
    dao.afterPropertiesSet();
    List<Report> reports = dao.getReports();
    assertNotNull("reports list should not be null", reports);
    assertTrue("at least two reports should be present but found " + reports.size(), reports.size() > 1);
    assertNotNull("first report should non-null", reports.get(0));
}
Also used : Report(org.opennms.netmgt.config.statsd.model.Report) InputStream(java.io.InputStream) DefaultStatisticsDaemonConfigDao(org.opennms.netmgt.dao.jaxb.DefaultStatisticsDaemonConfigDao) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 29 with InputStreamResource

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

the class CollectorConfigDaoImplIT method initialize.

private void initialize() throws IOException, Exception {
    System.setProperty("opennms.home", ConfigurationTestUtils.getDaemonEtcDirectory().getParentFile().getAbsolutePath());
    InputStream stream = null;
    stream = getInputStreamForFile("/org/opennms/netmgt/config/test-database-schema.xml");
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(stream));
    stream.close();
    stream = getInputStreamForFile("/org/opennms/netmgt/config/snmp-config.xml");
    SnmpPeerFactory.setInstance(new SnmpPeerFactory(new InputStreamResource(stream)));
    stream.close();
    stream = getInputStreamForFile("/org/opennms/netmgt/config/datacollection-config.xml");
    DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao();
    dataCollectionDao.setConfigResource(new InputStreamResource(stream));
    dataCollectionDao.afterPropertiesSet();
    DataCollectionConfigFactory.setInstance(dataCollectionDao);
    stream.close();
    stream = getInputStreamForFile("/org/opennms/netmgt/config/collectd-testdata.xml");
    try {
        new CollectdConfigFactory(stream, "localhost", false);
    } finally {
        stream.close();
    }
}
Also used : InputStream(java.io.InputStream) SnmpPeerFactory(org.opennms.netmgt.config.SnmpPeerFactory) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 30 with InputStreamResource

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

the class DataCollectionConfigParserTest method testPrecedence.

@Test
public void testPrecedence() throws Exception {
    // Create DatacollectionConfig
    Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-hybrid-precedence.xml"));
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
    // Validate default datacollection content
    SnmpCollection collection = config.getSnmpCollections().get(0);
    Assert.assertEquals(1, collection.getIncludeCollections().size());
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertEquals(1, collection.getSystems().getSystemDefs().size());
    Assert.assertEquals(1, collection.getGroups().getGroups().size());
    // Execute Parser
    executeParser(collection);
    // Validate SNMP Collection
    // Resource Types should live on a special collection
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertEquals(71, collection.getSystems().getSystemDefs().size());
    Assert.assertEquals(14, collection.getGroups().getGroups().size());
    // This is a way to "override" the content of a specific datacollection-group.
    for (Group group : collection.getGroups().getGroups()) {
        if (group.getName().equals("cisco-frame-relay")) {
            Assert.assertEquals(4, group.getMibObjs().size());
        }
    }
    for (SystemDef systemDef : collection.getSystems().getSystemDefs()) {
        if (systemDef.getName().equals("Cisco Routers")) {
            Assert.assertEquals(3, systemDef.getCollect().getIncludeGroups().size());
        }
    }
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Aggregations

InputStreamResource (org.springframework.core.io.InputStreamResource)40 InputStream (java.io.InputStream)18 Test (org.junit.Test)12 Resource (org.springframework.core.io.Resource)10 FileSystemResource (org.springframework.core.io.FileSystemResource)8 File (java.io.File)6 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)6 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)6 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 X509Certificate (java.security.cert.X509Certificate)3 ArrayList (java.util.ArrayList)3 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ApiOperation (io.swagger.annotations.ApiOperation)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2