-
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.
Support for verifying OIDC JWT claims with custom Jose4j Validator
- Loading branch information
1 parent
eb56608
commit d952eda
Showing
10 changed files
with
308 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
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; | ||
} | ||
} |
Oops, something went wrong.