From 663f3ef46cad94efc67095081a65808768648671 Mon Sep 17 00:00:00 2001
From: Diana Krepinska Vilkolakova <skyllarr@gmail.com>
Date: Tue, 9 Mar 2021 15:51:56 +0100
Subject: [PATCH] [ELY-2104] two calls to introspection endpoint for one
 request with JWT

---
 .../auth/realm/token/TokenSecurityRealm.java         | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/auth/realm/token/src/main/java/org/wildfly/security/auth/realm/token/TokenSecurityRealm.java b/auth/realm/token/src/main/java/org/wildfly/security/auth/realm/token/TokenSecurityRealm.java
index 9827f15f8dc..64cfb6b8382 100644
--- a/auth/realm/token/src/main/java/org/wildfly/security/auth/realm/token/TokenSecurityRealm.java
+++ b/auth/realm/token/src/main/java/org/wildfly/security/auth/realm/token/TokenSecurityRealm.java
@@ -183,18 +183,21 @@ public <C extends Credential> C getCredential(Class<C> credentialType) throws Re
 
         @Override
         public SupportLevel getEvidenceVerifySupport(Class<? extends Evidence> evidenceType, String algorithmName) throws RealmUnavailableException {
-            if (exists() && isBearerTokenEvidence(evidenceType)) {
+            if (isBearerTokenEvidence(evidenceType)) {
                 return SupportLevel.SUPPORTED;
             }
 
             return SupportLevel.UNSUPPORTED;
         }
 
+        private void setClaims(Attributes claims) throws RealmUnavailableException {
+            this.claims = claims;
+        }
+
         private Attributes getClaims() throws RealmUnavailableException {
             if (this.claims == null) {
-                this.claims = validateToken(this.evidence);
+                validateToken(this.evidence);
             }
-
             return this.claims;
         }
 
@@ -204,7 +207,8 @@ private Attributes validateToken(Evidence evidence) throws RealmUnavailableExcep
             }
             BearerTokenEvidence tokenEvidence = BearerTokenEvidence.class.cast(evidence);
             try {
-                return strategy.validate(tokenEvidence);
+                setClaims(strategy.validate(tokenEvidence));
+                return this.claims;
             } catch (RealmUnavailableException rue) {
                 throw rue;
             } catch (Exception unknown) {