Search in sources :

Example 31 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project geode by apache.

the class ExportLogControllerTest method testErrorResponse.

@Test
public void testErrorResponse() throws Exception {
    String message = "No Members Found";
    CommandResult result = (CommandResult) ResultBuilder.createUserErrorResult(message);
    String responseJson = CommandResponseBuilder.createCommandResponseJson("memberName", result);
    ResponseEntity<InputStreamResource> resp = controller.getResponse(responseJson);
    HttpHeaders headers = resp.getHeaders();
    assertThat(headers.get(HttpHeaders.CONTENT_TYPE).get(0)).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
    InputStreamResource body = resp.getBody();
    assertThat(IOUtils.toString(body.getInputStream(), "utf-8")).isEqualTo(responseJson);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 32 with InputStreamResource

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

the class ResourceUtils method buildInputStreamResourceFrom.

/**
 * Build input stream resource from string value.
 *
 * @param value       the value
 * @param description the description
 * @return the input stream resource
 */
public static InputStreamResource buildInputStreamResourceFrom(final String value, final String description) {
    final StringReader reader = new StringReader(value);
    final InputStream is = new ReaderInputStream(reader, StandardCharsets.UTF_8);
    return new InputStreamResource(is, description);
}
Also used : ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) InputStream(java.io.InputStream) StringReader(java.io.StringReader) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 33 with InputStreamResource

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

the class X509RestHttpRequestCredentialFactory method fromRequestBody.

@Override
public List<Credential> fromRequestBody(final MultiValueMap<String, String> requestBody) {
    final String cert = requestBody.getFirst(CERTIFICATE);
    LOGGER.debug("Certificate in the request body: [{}]", cert);
    if (StringUtils.isBlank(cert)) {
        return new ArrayList<>(0);
    }
    final InputStream is = new ByteArrayInputStream(cert.getBytes(StandardCharsets.UTF_8));
    final InputStreamSource iso = new InputStreamResource(is);
    final X509Certificate certificate = CertUtils.readCertificate(iso);
    final X509CertificateCredential credential = new X509CertificateCredential(new X509Certificate[] { certificate });
    credential.setCertificate(certificate);
    return CollectionUtils.wrap(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) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 34 with InputStreamResource

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

the class BaseSamlRegisteredServiceMetadataResolver method buildMetadataResolverFrom.

/**
 * Build metadata resolver from document.
 *
 * @param service          the service
 * @param metadataDocument the metadata document
 * @return the metadata resolver
 */
protected AbstractMetadataResolver buildMetadataResolverFrom(final SamlRegisteredService service, final SamlMetadataDocument metadataDocument) {
    try {
        final String desc = StringUtils.defaultString(service.getDescription(), service.getName());
        final InputStreamResource metadataResource = ResourceUtils.buildInputStreamResourceFrom(metadataDocument.getValue(), desc);
        final AbstractMetadataResolver metadataResolver = new InMemoryResourceMetadataResolver(ResourceHelper.of(metadataResource));
        final List<MetadataFilter> metadataFilterList = new ArrayList<>();
        if (StringUtils.isNotBlank(metadataDocument.getSignature())) {
            final InputStreamResource signatureResource = ResourceUtils.buildInputStreamResourceFrom(metadataDocument.getSignature(), desc);
            buildSignatureValidationFilterIfNeeded(service, metadataFilterList, signatureResource);
        }
        configureAndInitializeSingleMetadataResolver(metadataResolver, service, metadataFilterList);
        return metadataResolver;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : AbstractMetadataResolver(org.opensaml.saml.metadata.resolver.impl.AbstractMetadataResolver) ArrayList(java.util.ArrayList) MetadataFilter(org.opensaml.saml.metadata.resolver.filter.MetadataFilter) InMemoryResourceMetadataResolver(org.apereo.cas.support.saml.InMemoryResourceMetadataResolver) InputStreamResource(org.springframework.core.io.InputStreamResource)

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

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