-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for verifying OIDC JWT claims with custom Jose4j Validator
- Loading branch information
1 parent
eb56608
commit 9c74b2c
Showing
9 changed files
with
297 additions
and
12 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
24 changes: 24 additions & 0 deletions
24
...ts/oidc-tenancy/src/main/java/io/quarkus/it/keycloak/GlobalJwtPreferredNameValidator.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,24 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
import org.jose4j.jwt.MalformedClaimException; | ||
import org.jose4j.jwt.consumer.JwtContext; | ||
import org.jose4j.jwt.consumer.Validator; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
|
||
@Unremovable | ||
@Dependent | ||
public class GlobalJwtPreferredNameValidator implements Validator { | ||
|
||
@Override | ||
public String validate(JwtContext jwtContext) throws MalformedClaimException { | ||
if (jwtContext.getJwtClaims().hasClaim("preferred_username") | ||
&& jwtContext.getJwtClaims().isClaimValueString("preferred_username") | ||
&& jwtContext.getJwtClaims().getClaimValueAsString("preferred_username").contains("jdoe")) { | ||
return "scope validation failed, the 'fail-validation' scope is not allowed"; | ||
} | ||
return null; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
integration-tests/oidc-tenancy/src/main/java/io/quarkus/it/keycloak/IssuerValidator.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,28 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import static org.eclipse.microprofile.jwt.Claims.iss; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.jose4j.jwt.MalformedClaimException; | ||
import org.jose4j.jwt.consumer.JwtContext; | ||
import org.jose4j.jwt.consumer.Validator; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.oidc.TenantFeature; | ||
|
||
@Unremovable | ||
@ApplicationScoped | ||
@TenantFeature("tenant-public-key") | ||
public class IssuerValidator implements Validator { | ||
|
||
@Override | ||
public String validate(JwtContext jwtContext) throws MalformedClaimException { | ||
if (jwtContext.getJwtClaims().hasClaim(iss.name()) | ||
&& "unacceptable-issuer".equals(jwtContext.getJwtClaims().getClaimValueAsString(iss.name()))) { | ||
// issuer matched | ||
return "The 'unacceptable-issuer' is not allowed"; | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.