Search in sources :

Example 1 with InputStreamSource

use of org.springframework.core.io.InputStreamSource 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 X509Certificate (java.security.cert.X509Certificate)1 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1 InputStreamSource (org.springframework.core.io.InputStreamSource)1