Example usage for org.springframework.http.server.reactive SslInfo getPeerCertificates

List of usage examples for org.springframework.http.server.reactive SslInfo getPeerCertificates

Introduction

In this page you can find the example usage for org.springframework.http.server.reactive SslInfo getPeerCertificates.

Prototype

@Nullable
X509Certificate[] getPeerCertificates();

Source Link

Document

Return SSL certificates associated with the request, if any.

Usage

From source file:org.springframework.security.web.server.authentication.ServerX509AuthenticationConverter.java

@Override
public Mono<Authentication> convert(ServerWebExchange exchange) {
    SslInfo sslInfo = exchange.getRequest().getSslInfo();
    if (sslInfo == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("No SslInfo provided with a request, skipping x509 authentication");
        }/*from www .j  a  va2 s  .  co  m*/

        return Mono.empty();
    }

    if (sslInfo.getPeerCertificates() == null || sslInfo.getPeerCertificates().length == 0) {
        if (logger.isDebugEnabled()) {
            logger.debug("No peer certificates found in SslInfo, skipping x509 authentication");
        }

        return Mono.empty();
    }

    X509Certificate clientCertificate = sslInfo.getPeerCertificates()[0];
    Object principal = this.principalExtractor.extractPrincipal(clientCertificate);

    PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(principal,
            clientCertificate);

    return Mono.just(authRequest);
}