-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make JwtParser and JwtRolesMapper injectable
- Loading branch information
1 parent
d2fea75
commit db2501d
Showing
9 changed files
with
102 additions
and
13 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
21 changes: 21 additions & 0 deletions
21
...lrye-jwt/runtime/src/main/java/io/quarkus/smallrye/jwt/runtime/auth/DefaultJwtParser.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,21 @@ | ||
package io.quarkus.smallrye.jwt.runtime.auth; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.jose4j.jwt.consumer.JwtContext; | ||
|
||
import io.quarkus.arc.DefaultBean; | ||
import io.smallrye.jwt.auth.principal.DefaultJWTTokenParser; | ||
import io.smallrye.jwt.auth.principal.JWTAuthContextInfo; | ||
import io.smallrye.jwt.auth.principal.ParseException; | ||
|
||
@DefaultBean | ||
@ApplicationScoped | ||
public class DefaultJwtParser implements JwtParser { | ||
private final DefaultJWTTokenParser parser = new DefaultJWTTokenParser(); | ||
|
||
@Override | ||
public JwtContext parse(String token, JWTAuthContextInfo authContextInfo) throws ParseException { | ||
return parser.parse(token, authContextInfo); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...jwt/runtime/src/main/java/io/quarkus/smallrye/jwt/runtime/auth/DefaultJwtRolesMapper.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,20 @@ | ||
package io.quarkus.smallrye.jwt.runtime.auth; | ||
|
||
import java.util.HashSet; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.jose4j.jwt.JwtClaims; | ||
import org.jose4j.jwt.MalformedClaimException; | ||
|
||
import io.quarkus.arc.DefaultBean; | ||
|
||
@DefaultBean | ||
@ApplicationScoped | ||
public class DefaultJwtRolesMapper implements JwtRolesMapper { | ||
|
||
@Override | ||
public HashSet<String> mapGroupsAndRoles(JwtClaims claims) throws MalformedClaimException { | ||
return new HashSet<>(claims.getStringListClaimValue("groups")); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...ns/smallrye-jwt/runtime/src/main/java/io/quarkus/smallrye/jwt/runtime/auth/JwtParser.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,10 @@ | ||
package io.quarkus.smallrye.jwt.runtime.auth; | ||
|
||
import org.jose4j.jwt.consumer.JwtContext; | ||
|
||
import io.smallrye.jwt.auth.principal.JWTAuthContextInfo; | ||
import io.smallrye.jwt.auth.principal.ParseException; | ||
|
||
public interface JwtParser { | ||
JwtContext parse(String token, JWTAuthContextInfo authContextInfo) throws ParseException; | ||
} |
10 changes: 10 additions & 0 deletions
10
...allrye-jwt/runtime/src/main/java/io/quarkus/smallrye/jwt/runtime/auth/JwtRolesMapper.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,10 @@ | ||
package io.quarkus.smallrye.jwt.runtime.auth; | ||
|
||
import java.util.HashSet; | ||
|
||
import org.jose4j.jwt.JwtClaims; | ||
import org.jose4j.jwt.MalformedClaimException; | ||
|
||
public interface JwtRolesMapper { | ||
HashSet<String> mapGroupsAndRoles(JwtClaims claims) throws MalformedClaimException; | ||
} |
20 changes: 20 additions & 0 deletions
20
...mallrye-jwt/runtime/src/main/java/io/quarkus/smallrye/jwt/runtime/auth/JwtTokenUtils.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,20 @@ | ||
package io.quarkus.smallrye.jwt.runtime.auth; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.jose4j.jwt.JwtClaims; | ||
import org.jose4j.jwt.consumer.InvalidJwtException; | ||
import org.jose4j.jwt.consumer.JwtConsumer; | ||
import org.jose4j.jwt.consumer.JwtConsumerBuilder; | ||
|
||
@ApplicationScoped | ||
public class JwtTokenUtils { | ||
public JwtClaims decodeTokenUnverified(String tokenString) throws InvalidJwtException { | ||
JwtConsumer consumer = new JwtConsumerBuilder() | ||
.setSkipAllValidators() | ||
.setDisableRequireSignature() | ||
.setSkipSignatureVerification() | ||
.build(); | ||
return consumer.processToClaims(tokenString); | ||
} | ||
} |
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