Search in sources :

Example 21 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 22 with InputStreamResource

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

the class X509CertificateCredentialJsonDeserializer method deserialize.

@Override
public X509CertificateCredential deserialize(final JsonParser jp, final DeserializationContext deserializationContext) throws IOException {
    final ObjectCodec oc = jp.getCodec();
    final JsonNode node = oc.readTree(jp);
    final List<X509Certificate> certs = new ArrayList<>();
    node.findValues("certificates").forEach(n -> {
        final String cert = n.get(0).textValue();
        final byte[] data = EncodingUtils.decodeBase64(cert);
        certs.add(CertUtils.readCertificate(new InputStreamResource(new ByteArrayInputStream(data))));
    });
    final X509CertificateCredential c = new X509CertificateCredential(certs.toArray(new X509Certificate[] {}));
    return c;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) X509CertificateCredential(org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) X509Certificate(java.security.cert.X509Certificate) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 23 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 24 with InputStreamResource

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

the class PropertiesGraphDao method loadProperties.

/**
     * <p>
     * loadProperties
     * </p>
     * Used exclusively by test code. Will ignore an "include.directory"
     * because we don't have a resource/path to do any useful "relative"
     * pathing to. Also anything loaded in this fashion will *not* have auto
     * reloading on changes, because there's no underlying Resource/File to
     * check against. Like, duh!
     * 
     * @param type
     *            a {@link java.lang.String} object.
     * @param in
     *            a {@link java.io.InputStream} object.
     * @throws java.io.IOException
     *             if any.
     */
public void loadProperties(String type, InputStream in) throws IOException {
    Resource resource = new InputStreamResource(in);
    // Not reloadable; we don't have a file to check for modifications
    PrefabGraphTypeDao t = createPrefabGraphType(type, resource, false);
    if (t != null) {
        m_types.put(t.getName(), new FileReloadContainer<PrefabGraphTypeDao>(t));
    }
}
Also used : InputStreamResource(org.springframework.core.io.InputStreamResource) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 25 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)

Aggregations

InputStreamResource (org.springframework.core.io.InputStreamResource)32 Test (org.junit.Test)12 InputStream (java.io.InputStream)11 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 FileInputStream (java.io.FileInputStream)4 ClassPathResource (org.springframework.core.io.ClassPathResource)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 X509Certificate (java.security.cert.X509Certificate)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)2 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)2 DefaultStatisticsDaemonConfigDao (org.opennms.netmgt.dao.jaxb.DefaultStatisticsDaemonConfigDao)2 BeansException (org.springframework.beans.BeansException)2 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)2