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;
}
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;
}
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);
}
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));
}
}
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));
}
Aggregations