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