This commit is contained in:
2022-04-11 22:38:55 +02:00
parent dd081ae82a
commit 8feb3c5f32
4 changed files with 67 additions and 6 deletions

View File

@@ -34,16 +34,14 @@ public class TokenRessource {
@Inject JWTParser parser;
private String secret = "AyM1SysPpbyDfgZld3umj1qzKObwVMko";
@GET
@Path("authentificate/{role}")
@Path("authentificate")
@Produces(MediaType.APPLICATION_JSON)
public Response getUserName(@CookieParam("jwt") String jwtCookie, @PathParam("role") String role) {
public Response getUserName(@CookieParam("jwt") String jwtCookie) {
if (jwtCookie == null) {
// Create a JWT token signed using the 'HS256' algorithm
// String newJwtCookie = Jwt.upn("Alice").groups(new HashSet<>(Arrays.asList("User", "Admin"))).signWithSecret(secret);
String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn("Alice").groups(new HashSet<>(Arrays.asList("User", role))).sign();
String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn("Alice").groups(new HashSet<>(Arrays.asList("User"))).sign();
// or create a JWT token encrypted using the 'A256KW' algorithm
// Jwt.upn("alice").encryptWithSecret(secret);
@@ -51,7 +49,6 @@ public class TokenRessource {
} else {
// All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized.
try {
// jwt = parser.verify(jwtCookie, secret);
jwt = parser.parse(jwtCookie);
}
catch(ParseException p){