-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44170 from sberyozkin/required_claims_for_token_i…
…ntrospection Apply the required claims restriction to OIDC introspections
- Loading branch information
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ public class OidcResource { | |
private volatile boolean rotate; | ||
private volatile int jwkEndpointCallCount; | ||
private volatile int introspectionEndpointCallCount; | ||
private volatile int opaqueToken2UsageCount; | ||
private volatile int revokeEndpointCallCount; | ||
private volatile int userInfoEndpointCallCount; | ||
private volatile boolean enableDiscovery = true; | ||
|
@@ -112,6 +113,13 @@ public int resetIntrospectionEndpointCallCount() { | |
return introspectionEndpointCallCount; | ||
} | ||
|
||
@POST | ||
@Path("opaque-token-call-count") | ||
public int resetOpaqueTokenCallCount() { | ||
opaqueToken2UsageCount = 0; | ||
return opaqueToken2UsageCount; | ||
} | ||
|
||
@POST | ||
@Produces("application/json") | ||
@Path("introspect") | ||
|
@@ -120,7 +128,12 @@ public String introspect(@FormParam("client_id") String clientId, @FormParam("cl | |
introspectionEndpointCallCount++; | ||
|
||
boolean activeStatus = introspection && !token.endsWith("-invalid"); | ||
|
||
boolean requiredClaim = true; | ||
if (token.endsWith("_2") && ++opaqueToken2UsageCount == 2) { | ||
// This is to confirm that the same opaque token_2 works well when its introspection response | ||
// includes `required_claim` with value "1" but fails when the required claim is not included | ||
requiredClaim = false; | ||
} | ||
String introspectionClientId = "none"; | ||
String introspectionClientSecret = "none"; | ||
if (clientSecret != null) { | ||
|
@@ -146,6 +159,7 @@ public String introspect(@FormParam("client_id") String clientId, @FormParam("cl | |
" \"scope\": \"user\"," + | ||
" \"email\": \"[email protected]\"," + | ||
" \"username\": \"alice\"," + | ||
(requiredClaim ? "\"required_claim\": \"1\"," : "") + | ||
" \"introspection_client_id\": \"" + introspectionClientId + "\"," + | ||
" \"introspection_client_secret\": \"" + introspectionClientSecret + "\"," + | ||
" \"client_id\": \"" + clientId + "\"" + | ||
|
@@ -251,13 +265,23 @@ public String testAccessTokenWithEmptyScope(@QueryParam("kid") String kid, @Quer | |
@POST | ||
@Path("opaque-token") | ||
@Produces("application/json") | ||
public String testOpaqueToken(@QueryParam("kid") String kid) { | ||
public String testOpaqueToken() { | ||
return "{\"access_token\": \"987654321\"," + | ||
" \"token_type\": \"Bearer\"," + | ||
" \"refresh_token\": \"123456789\"," + | ||
" \"expires_in\": 300 }"; | ||
} | ||
|
||
@POST | ||
@Path("opaque-token2") | ||
@Produces("application/json") | ||
public String testOpaqueToken2() { | ||
return "{\"access_token\": \"987654321_2\"," + | ||
" \"token_type\": \"Bearer\"," + | ||
" \"refresh_token\": \"123456789\"," + | ||
" \"expires_in\": 300 }"; | ||
} | ||
|
||
@POST | ||
@Path("enable-introspection") | ||
public boolean setIntrospection() { | ||
|
22 changes: 22 additions & 0 deletions
22
...nancy/src/main/java/io/quarkus/it/keycloak/TenantIntrospectionRequiredClaimsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.quarkus.oidc.TokenIntrospection; | ||
import io.quarkus.security.Authenticated; | ||
|
||
@Path("/tenant-introspection") | ||
@Authenticated | ||
public class TenantIntrospectionRequiredClaimsResource { | ||
|
||
@Inject | ||
TokenIntrospection token; | ||
|
||
@GET | ||
@Path("tenant-introspection-required-claims") | ||
public String userPermission() { | ||
return token.getUsername() + ", required_claim:" + token.getString("required_claim"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters