Class ClientCertificateVerifier

java.lang.Object
com.irurueta.authserver.authorization.api.web.clientauth.ClientCertificateVerifier
All Implemented Interfaces:
Consumer<org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext>

public class ClientCertificateVerifier extends Object implements Consumer<org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext>
Verifies the certificate a client presented on the TLS port (RFC 8705), replacing the framework's verifier, which has no trust anchors of its own.
  • tls_client_auth: the chain must validate (PKIX path validation) against the configured trust anchors, and the subject DN of the leaf must equal the one registered for the client. Revocation checking is disabled: it needs a CRL or OCSP endpoint reachable from the server, which this example does not assume. No configured anchor means no client is accepted.
  • self_signed_tls_client_auth: the certificate must be self-signed and its public key one of the keys of the client's registered JWK set; otherwise the decision is the framework's own (which compares it with the keys of the client's jwkSetUrl), whose provider is defaultProvider.
Every refusal is invalid_client.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    Type of the certification path.
    private final org.springframework.security.authentication.AuthenticationProvider
    A default-configured provider of the framework, asked about a self-signed certificate with no registered key.
    private static final String
    Algorithm of the path validation.
    private final MtlsTrustAnchors
    The trusted certificate authorities.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context)
    Verifies the certificate of the client.
    private static X509Certificate[]
    chainOf(org.springframework.security.core.Authentication authentication)
    Reads the presented chain.
    private static org.springframework.security.oauth2.core.OAuth2AuthenticationException
    Builds the refusal.
    private boolean
    Tells whether a certificate is itself a trust anchor, which a certification path must not contain.
    private boolean
    matchesRegisteredKey(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context, PublicKey key)
    Tells whether a key is one of the registered JWK set of the client.
    private void
    verifyCaIssued(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context, X509Certificate[] chain)
    Verifies a certificate issued by a trusted authority.
    private void
    verifySelfSigned(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context, org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken authentication, X509Certificate[] chain)
    Verifies a self-signed certificate.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Consumer

    andThen
  • Field Details

    • CERTIFICATE_TYPE

      private static final String CERTIFICATE_TYPE
      Type of the certification path.
      See Also:
    • PKIX

      private static final String PKIX
      Algorithm of the path validation.
      See Also:
    • trustAnchors

      private final MtlsTrustAnchors trustAnchors
      The trusted certificate authorities.
    • defaultProvider

      private final org.springframework.security.authentication.AuthenticationProvider defaultProvider
      A default-configured provider of the framework, asked about a self-signed certificate with no registered key.
  • Constructor Details

    • ClientCertificateVerifier

      public ClientCertificateVerifier()
  • Method Details

    • accept

      public void accept(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context)
      Verifies the certificate of the client.
      Specified by:
      accept in interface Consumer<org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext>
      Parameters:
      context - the client and its authentication.
      Throws:
      org.springframework.security.oauth2.core.OAuth2AuthenticationException - invalid_client if the certificate is not accepted.
    • verifyCaIssued

      private void verifyCaIssued(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context, X509Certificate[] chain)
      Verifies a certificate issued by a trusted authority.
      Parameters:
      context - the client and its authentication.
      chain - the presented chain, the leaf first.
    • verifySelfSigned

      private void verifySelfSigned(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context, org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken authentication, X509Certificate[] chain)
      Verifies a self-signed certificate.
      Parameters:
      context - the client and its authentication.
      authentication - the client authentication.
      chain - the presented chain, the leaf first.
    • matchesRegisteredKey

      private boolean matchesRegisteredKey(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context, PublicKey key)
      Tells whether a key is one of the registered JWK set of the client.
      Parameters:
      context - the client and its authentication.
      key - the public key of the certificate.
      Returns:
      true when a registered key equals it.
    • isAnchor

      private boolean isAnchor(X509Certificate certificate)
      Tells whether a certificate is itself a trust anchor, which a certification path must not contain.
      Parameters:
      certificate - the certificate.
      Returns:
      true when an anchor holds exactly that certificate.
    • chainOf

      private static X509Certificate[] chainOf(org.springframework.security.core.Authentication authentication)
      Reads the presented chain.
      Parameters:
      authentication - the client authentication.
      Returns:
      the chain, the leaf first.
    • invalidClient

      private static org.springframework.security.oauth2.core.OAuth2AuthenticationException invalidClient()
      Builds the refusal.
      Returns:
      the invalid_client exception.