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'sjwkSetUrl), whose provider isdefaultProvider.
invalid_client.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringType of the certification path.private final org.springframework.security.authentication.AuthenticationProviderA default-configured provider of the framework, asked about a self-signed certificate with no registered key.private static final StringAlgorithm of the path validation.private final MtlsTrustAnchorsThe trusted certificate authorities. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(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.OAuth2AuthenticationExceptionBuilds the refusal.private booleanisAnchor(X509Certificate certificate) Tells whether a certificate is itself a trust anchor, which a certification path must not contain.private booleanmatchesRegisteredKey(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 voidverifyCaIssued(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext context, X509Certificate[] chain) Verifies a certificate issued by a trusted authority.private voidverifySelfSigned(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.
-
Field Details
-
CERTIFICATE_TYPE
Type of the certification path.- See Also:
-
PKIX
Algorithm of the path validation.- See Also:
-
trustAnchors
The trusted certificate authorities. -
defaultProvider
private final org.springframework.security.authentication.AuthenticationProvider defaultProviderA 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:
acceptin interfaceConsumer<org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationContext>- Parameters:
context- the client and its authentication.- Throws:
org.springframework.security.oauth2.core.OAuth2AuthenticationException-invalid_clientif 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:
truewhen a registered key equals it.
-
isAnchor
Tells whether a certificate is itself a trust anchor, which a certification path must not contain.- Parameters:
certificate- the certificate.- Returns:
truewhen 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_clientexception.
-