55import java .security .cert .Certificate ;
66import java .security .cert .X509Certificate ;
77import java .util .List ;
8+ import java .util .Map ;
89import java .util .function .Function ;
910
1011import javax .net .ssl .SSLPeerUnverifiedException ;
@@ -35,8 +36,8 @@ public Uni<SecurityIdentity> authenticate(RoutingContext context,
3536 // if a bearer token is provided try to authenticate
3637 if (token != null ) {
3738 try {
38- setCertificateThumbprint (context , oidcTenantConfig );
39- setDPopProof (context , oidcTenantConfig );
39+ setCertificateThumbprint (context , oidcTenantConfig , token );
40+ setDPopProof (context , oidcTenantConfig , token );
4041 } catch (AuthenticationFailedException ex ) {
4142 return Uni .createFrom ().failure (ex );
4243 }
@@ -46,29 +47,29 @@ public Uni<SecurityIdentity> authenticate(RoutingContext context,
4647 return Uni .createFrom ().nullItem ();
4748 }
4849
49- private static void setCertificateThumbprint (RoutingContext context , OidcTenantConfig oidcTenantConfig ) {
50+ private static void setCertificateThumbprint (RoutingContext context , OidcTenantConfig oidcTenantConfig , String token ) {
5051 if (oidcTenantConfig .token ().binding ().certificate ()) {
51- Certificate cert = getCertificate (context );
52+ Certificate cert = getCertificate (context , token );
5253 if (!(cert instanceof X509Certificate )) {
5354 LOG .warn ("Access token must be bound to X509 client certiifcate" );
54- throw new AuthenticationFailedException ();
55+ throw new AuthenticationFailedException (tokenMap ( token ) );
5556 }
5657 context .put (OidcConstants .X509_SHA256_THUMBPRINT ,
5758 TrustStoreUtils .calculateThumprint ((X509Certificate ) cert ));
5859 }
5960 }
6061
61- private static void setDPopProof (RoutingContext context , OidcTenantConfig oidcTenantConfig ) {
62+ private static void setDPopProof (RoutingContext context , OidcTenantConfig oidcTenantConfig , String token ) {
6263 if (OidcConstants .DPOP_SCHEME .equals (oidcTenantConfig .token ().authorizationScheme ())) {
6364
6465 List <String > proofs = context .request ().headers ().getAll (OidcConstants .DPOP_SCHEME );
6566 if (proofs == null || proofs .isEmpty ()) {
6667 LOG .warn ("DPOP proof header must be present to verify the DPOP access token binding" );
67- throw new AuthenticationFailedException ();
68+ throw new AuthenticationFailedException (tokenMap ( token ) );
6869 }
6970 if (proofs .size () != 1 ) {
7071 LOG .warn ("Only a single DPOP proof header is accepted" );
71- throw new AuthenticationFailedException ();
72+ throw new AuthenticationFailedException (tokenMap ( token ) );
7273 }
7374 String proof = proofs .get (0 );
7475
@@ -78,28 +79,28 @@ private static void setDPopProof(RoutingContext context, OidcTenantConfig oidcTe
7879
7980 if (!OidcConstants .DPOP_TOKEN_TYPE .equals (proofJwtHeaders .getString (OidcConstants .TOKEN_TYPE_HEADER ))) {
8081 LOG .warn ("Invalid DPOP proof token type ('typ') header" );
81- throw new AuthenticationFailedException ();
82+ throw new AuthenticationFailedException (tokenMap ( token ) );
8283 }
8384
8485 // Check HTTP method and request URI
8586 String proofHttpMethod = proofJwtClaims .getString (OidcConstants .DPOP_HTTP_METHOD );
8687 if (proofHttpMethod == null ) {
8788 LOG .warn ("DPOP proof HTTP method claim is missing" );
88- throw new AuthenticationFailedException ();
89+ throw new AuthenticationFailedException (tokenMap ( token ) );
8990 }
9091
9192 String httpMethod = context .request ().method ().name ();
9293 if (!httpMethod .equals (proofHttpMethod )) {
9394 LOG .warnf ("DPOP proof HTTP method claim %s does not match the request HTTP method %s" , proofHttpMethod ,
9495 httpMethod );
95- throw new AuthenticationFailedException ();
96+ throw new AuthenticationFailedException (tokenMap ( token ) );
9697 }
9798
9899 // Check HTTP request URI
99100 String proofHttpRequestUri = proofJwtClaims .getString (OidcConstants .DPOP_HTTP_REQUEST_URI );
100101 if (proofHttpRequestUri == null ) {
101102 LOG .warn ("DPOP proof HTTP request uri claim is missing" );
102- throw new AuthenticationFailedException ();
103+ throw new AuthenticationFailedException (tokenMap ( token ) );
103104 }
104105
105106 String httpRequestUri = context .request ().absoluteURI ();
@@ -110,7 +111,7 @@ private static void setDPopProof(RoutingContext context, OidcTenantConfig oidcTe
110111 if (!httpRequestUri .equals (proofHttpRequestUri )) {
111112 LOG .warnf ("DPOP proof HTTP request uri claim %s does not match the request HTTP uri %s" , proofHttpRequestUri ,
112113 httpRequestUri );
113- throw new AuthenticationFailedException ();
114+ throw new AuthenticationFailedException (tokenMap ( token ) );
114115 }
115116
116117 context .put (OidcUtils .DPOP_PROOF , proof );
@@ -119,15 +120,19 @@ private static void setDPopProof(RoutingContext context, OidcTenantConfig oidcTe
119120 }
120121 }
121122
122- private static Certificate getCertificate (RoutingContext context ) {
123+ private static Certificate getCertificate (RoutingContext context , String token ) {
123124 try {
124125 return context .request ().sslSession ().getPeerCertificates ()[0 ];
125126 } catch (SSLPeerUnverifiedException e ) {
126127 LOG .warn ("Access token must be certificate bound but no client certificate is available" );
127- throw new AuthenticationFailedException ();
128+ throw new AuthenticationFailedException (tokenMap ( token ) );
128129 }
129130 }
130131
132+ private static Map <String , Object > tokenMap (String token ) {
133+ return Map .of (OidcConstants .ACCESS_TOKEN_VALUE , token );
134+ }
135+
131136 public Uni <ChallengeData > getChallenge (RoutingContext context ) {
132137 Uni <TenantConfigContext > tenantContext = resolver .resolveContext (context );
133138 return tenantContext .onItem ().transformToUni (new Function <TenantConfigContext , Uni <? extends ChallengeData >>() {
0 commit comments