Class X509AuthenticationFetcher

  • All Implemented Interfaces:
    io.micronaut.core.order.Ordered, AuthenticationFetcher

    @Singleton
    public class X509AuthenticationFetcher
    extends java.lang.Object
    implements AuthenticationFetcher
    Creates an Authentication if an X.509 client certificate is present and a name (CN) can be extracted.
    Since:
    3.3
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ORDER
      The order of the fetcher.
      • Fields inherited from interface io.micronaut.core.order.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Field Detail

      • ORDER

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

      • X509AuthenticationFetcher

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

      • getOrder

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

        @NonNull
        protected java.util.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 java.util.Optional<Authentication> createX509Authentication​(@NonNull
                                                                              java.security.cert.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 java.util.Optional<java.lang.String> extractName​(@NonNull
                                                                   java.security.cert.X509Certificate certificate)
        Extracts the name from the certificate using the subject DN regex.
        Parameters:
        certificate - the client certificate
        Returns:
        the name if found