Class X509AuthenticationFetcher

java.lang.Object
io.micronaut.security.x509.X509AuthenticationFetcher
All Implemented Interfaces:
io.micronaut.core.order.Ordered, AuthenticationFetcher<io.micronaut.http.HttpRequest<?>>

@Requires(classes=io.micronaut.http.HttpRequest.class) @Singleton public class X509AuthenticationFetcher extends Object implements AuthenticationFetcher<io.micronaut.http.HttpRequest<?>>
Creates an Authentication if an X.509 client certificate is present and a name (CN) can be extracted.
Since:
3.3
Author:
Burt Beckwith
  • Field Details

    • ORDER

      public static final int ORDER
      The order of the fetcher.
  • Constructor Details

    • X509AuthenticationFetcher

      public X509AuthenticationFetcher(X509Configuration x509Configuration)
      Parameters:
      x509Configuration - x509 configuration
  • Method Details

    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface io.micronaut.core.order.Ordered
    • fetchAuthentication

      public org.reactivestreams.Publisher<Authentication> fetchAuthentication(io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: AuthenticationFetcher
      Attempts to read an Authentication from an HTTP Request being executed.
      Specified by:
      fetchAuthentication in interface AuthenticationFetcher<io.micronaut.http.HttpRequest<?>>
      Parameters:
      request - an HTTP Request being executed.
      Returns:
      Authentication if found
    • createAuthentication

      @NonNull protected @NonNull Optional<Authentication> createAuthentication(io.micronaut.http.HttpRequest<?> request)
      Creates an X509Authentication from information in an X509Certificate if one is present in the request.
      Parameters:
      request - the request
      Returns:
      the authentication if the certificate exists and contains a valid name
    • createX509Authentication

      @NonNull protected @NonNull Optional<Authentication> createX509Authentication(@NonNull @NonNull X509Certificate certificate)
      Creates an X509Authentication from information in an X509Certificate.
      Parameters:
      certificate - the certificate
      Returns:
      the authentication if the certificate contains a valid name
    • extractName

      @NonNull protected @NonNull Optional<String> extractName(@NonNull @NonNull X509Certificate certificate)
      Extracts the name from the certificate using the subject DN regex.
      Parameters:
      certificate - the client certificate
      Returns:
      the name if found