Java Code Examples for org.eclipse.microprofile.jwt.JsonWebToken

The following examples show how to use org.eclipse.microprofile.jwt.JsonWebToken. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: quarkus   Source File: MpJwtValidator.java    License: Apache License 2.0 7 votes vote down vote up
@Override
public Uni<SecurityIdentity> authenticate(TokenAuthenticationRequest request,
        AuthenticationRequestContext context) {
    return Uni.createFrom().emitter(new Consumer<UniEmitter<? super SecurityIdentity>>() {
        @Override
        public void accept(UniEmitter<? super SecurityIdentity> uniEmitter) {
            try {
                JsonWebToken jwtPrincipal = parser.parse(request.getToken().getToken());
                uniEmitter.complete(QuarkusSecurityIdentity.builder().setPrincipal(jwtPrincipal)
                        .addRoles(jwtPrincipal.getGroups())
                        .addAttribute(SecurityIdentity.USER_ATTRIBUTE, jwtPrincipal).build());

            } catch (ParseException e) {
                log.debug("Authentication failed", e);
                uniEmitter.fail(new AuthenticationFailedException(e));
            }
        }
    });

}
 
Example 2
Source Project: smallrye-jwt   Source File: TestTokenRequireSub.java    License: Apache License 2.0 6 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "no sub validation")
public void noSubValidation() throws Exception {
    HashMap<String, Long> timeClaims = new HashMap<>();
    String token = TokenUtils.generateTokenString("/TokenSubPath.json", null, timeClaims);
    PublicKey publicKey = TokenUtils.readPublicKey("/publicKey.pem");
    if (publicKey == null) {
        throw new IllegalStateException("Failed to load /publicKey.pem resource");
    }

    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setRequireNamedPrincipal(false);
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    String sub = jwt.getSubject();
    Assert.assertNull(sub);
}
 
Example 3
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request,
        HttpServletResponse response,
        HttpMessageContext httpMessageContext)
        throws AuthenticationException {

    AbstractBearerTokenExtractor extractor = new BearerTokenExtractor(request, authContextInfo);
    String bearerToken = extractor.getBearerToken();

    if (bearerToken != null) {
        try {
            JsonWebToken jwtPrincipal = jwtParser.parse(bearerToken);
            producer.setJsonWebToken(jwtPrincipal);
            Set<String> groups = jwtPrincipal.getGroups();
            MechanismLogging.log.success();
            return httpMessageContext.notifyContainerAboutLogin(jwtPrincipal, groups);
        } catch (Exception e) {
            MechanismLogging.log.unableToValidateBearerToken(e);
            return httpMessageContext.responseUnauthorized();
        }
    } else {
        MechanismLogging.log.noUsableBearerTokenFound();
        return httpMessageContext.isProtected() ? httpMessageContext.responseUnauthorized()
                : httpMessageContext.doNothing();
    }
}
 
Example 4
Source Project: microprofile-jwt-auth   Source File: ServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TCKConstants.TEST_GROUP_SERVLET,
    description = "Validate a request with MP-JWT SecurityContext.getUserPrincipal() is a JsonWebToken")
public void getServletPrincipalClass() throws Exception {
    String uri = baseURL.toExternalForm() + "ServiceServlet/getPrincipalClass";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        ;
    Response response = echoEndpointTarget.request(TEXT_PLAIN).header(HttpHeaders.AUTHORIZATION, "Bearer "+token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String reply = response.readEntity(String.class);
    String[] ifaces = reply.split(",");
    boolean hasJsonWebToken = false;
    for(String iface : ifaces) {
        hasJsonWebToken |= iface.equals(JsonWebToken.class.getTypeName());
    }
    Assert.assertTrue(hasJsonWebToken, "PrincipalClass has JsonWebToken interface");
}
 
Example 5
Source Project: microprofile-jwt-auth   Source File: EjbTest.java    License: Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TCKConstants.TEST_GROUP_EJB,
    description = "Validate a request with MP-JWT SecurityContext.getUserPrincipal() is a JsonWebToken")
public void testEJBPrincipalClass() throws Exception {
    String uri = baseURL.toExternalForm() + "endp/getEJBPrincipalClass";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        ;
    Response response = echoEndpointTarget.request(TEXT_PLAIN).header(HttpHeaders.AUTHORIZATION, "Bearer "+token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String reply = response.readEntity(String.class);
    String[] ifaces = reply.split(",");
    boolean hasJsonWebToken = false;
    for(String iface : ifaces) {
        hasJsonWebToken |= iface.equals(JsonWebToken.class.getTypeName());
    }
    Assert.assertTrue(hasJsonWebToken, "EJB PrincipalClass has JsonWebToken interface");
}
 
Example 6
Source Project: trellis   Source File: WebIdPrincipal.java    License: Apache License 2.0 6 votes vote down vote up
static String getWebId(final JsonWebToken jwt) {
    if (jwt.containsClaim("webid")) {
        return jwt.getClaim("webid");
    }

    final String subject = jwt.getSubject();
    if (isUrl(subject)) {
        return subject;
    }

    final String issuer = jwt.getIssuer();
    if (isUrl(issuer)) {
        return concat(issuer, subject);
    }

    return null;
}
 
Example 7
Source Project: tomee   Source File: ValidationConstraintsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void valid() throws Exception {
    final ValidationConstraints constraints = ValidationConstraints.of(Circle.class);

    final Method red = Circle.class.getMethod("red");


    final JsonWebTokenValidator validator = JsonWebTokenValidator.builder()
            .publicKey(Tokens.getPublicKey())
            .build();

    final String claims = "{" +
            "  \"sub\":\"Jane Awesome\"," +
            "  \"iss\":\"http://foo.bar.com\"," +
            "  \"aud\":[\"bar\",\"user\"]," +
            "  \"groups\":[\"manager\",\"user\"]," +
            "  \"exp\":2552047942" +
            "}";
    final String token = Tokens.asToken(claims);

    final JsonWebToken jwt = validator.validate(token);

    assertViolations(constraints.validate(red, jwt));
}
 
Example 8
Source Project: tomee   Source File: JsonWebTokenValidatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Ignore
public void testValidate() throws Exception {

    final JsonWebTokenValidator validator = JsonWebTokenValidator.builder()
            .publicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlivFI8qB4D0y2jy0CfEqFyy46R0o7S8TKpsx5xbHKoU1VWg6QkQm+ntyIv1p4kE1sPEQO73+HY8+Bzs75XwRTYL1BmR1w8J5hmjVWjc6R2BTBGAYRPFRhor3kpM6ni2SPmNNhurEAHw7TaqszP5eUF/F9+KEBWkwVta+PZ37bwqSE4sCb1soZFrVz/UT/LF4tYpuVYt3YbqToZ3pZOZ9AX2o1GCG3xwOjkc4x0W7ezbQZdC9iftPxVHR8irOijJRRjcPDtA6vPKpzLl6CyYnsIYPd99ltwxTHjr3npfv/3Lw50bAkbT4HeLFxTx4flEoZLKO/g0bAoV2uqBhkA9xnQIDAQAB")
            .build();

    final String claims = "{" +
            "  \"sub\":\"Jane Awesome\"," +
            "  \"iss\":\"https://server.example.com\"," +
            "  \"groups\":[\"manager\",\"user\"]," +
            "  \"exp\":2552047942" +
            "}";
    final String token = Tokens.asToken(claims);

    final JsonWebToken jwt = validator.validate(token);

    assertEquals("Jane Awesome", jwt.getSubject());
    assertEquals("https://server.example.com", jwt.getIssuer());
    assertEquals(2552047942l, jwt.getExpirationTime());
}
 
Example 9
Source Project: smallrye-jwt   Source File: TestTokenClaimTypes.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the name comes from the upn claim")
public void validateNameIsPreferredName() throws Exception {
    String token2 = TokenUtils.generateTokenString("/usePreferredName.json");
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt2 = factory.parse(token2, contextInfo);
    Assert.assertEquals("jdoe", jwt2.getName());
}
 
Example 10
Source Project: smallrye-jwt   Source File: TestTokenClaimTypes.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the name comes from the sub claim")
public void validateNameIsSubject() throws Exception {
    String token2 = TokenUtils.generateTokenString("/useSubject.json");
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt2 = factory.parse(token2, contextInfo);
    Assert.assertEquals("24400320", jwt2.getName());
}
 
Example 11
Source Project: smallrye-jwt   Source File: TestTokenWithSubPath.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the custom sub claim is available on the path")
public void subClaimIsAvailableOnPath() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setSubjectPath("realm/access/sub/principal");
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    String sub = jwt.getSubject();
    Assert.assertEquals(sub, "microprofile_jwt_principal");
}
 
Example 12
Source Project: smallrye-jwt   Source File: TestTokenWithSubPath.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the custom sub claim is available on the path with namespace")
public void subClaimIsAvailableOnPathWithNamespace() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setSubjectPath("realm/\"https://idp/access\"/sub/principal");
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    String sub = jwt.getSubject();
    Assert.assertEquals(sub, "namespace_microprofile_jwt_principal");
}
 
Example 13
Source Project: smallrye-jwt   Source File: TestTokenWithSubPath.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the custom sub claim is not available if the claim is not array")
public void subClaimIsNotAvailableIfClaimIsNotString() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setRequireNamedPrincipal(false);
    contextInfo.setSubjectPath("realm/access/sub");
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    Assert.assertNull(jwt.getSubject());
}
 
Example 14
Source Project: smallrye-jwt   Source File: TestTokenWithSubPath.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the custom sub claim is not available on the wrong path")
public void subClaimIsNotAvailableOnWrongPath() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setRequireNamedPrincipal(false);
    contextInfo.setSubjectPath("realm/access/user/principal");
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    Assert.assertNull(jwt.getSubject());
}
 
Example 15
Source Project: smallrye-jwt   Source File: TestTokenWithGroupsPath.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the custom groups claim is not available if the claim is not array")
public void groupsClaimIsNotAvailableIfClaimIsNotArray() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setGroupsPath("realm/access/groups");
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    Assert.assertTrue(jwt.getGroups().isEmpty());
}
 
Example 16
Source Project: smallrye-jwt   Source File: TestTokenWithGroupsPath.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the custom groups claim is not available on the wrong path")
public void groupsClaimIsNotAvailableOnWrongPath() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setGroupsPath("realm/access/group/array");
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    Assert.assertTrue(jwt.getGroups().isEmpty());
}
 
Example 17
Source Project: smallrye-jwt   Source File: TestJsonWebToken.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testValidation() throws Exception {
    String token = TokenUtils.generateTokenString("/Token1.json");
    RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem");
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(publicKey, "https://server.example.com");
    contextInfo.setExpGracePeriodSecs(60);
    JsonWebToken jwt = validateToken(token, contextInfo);
}
 
Example 18
Source Project: smallrye-jwt   Source File: TestJsonWebToken.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { ParseException.class }, description = "Illustrate validation of issuer")
public void testFailIssuer() throws Exception {
    HashSet<TokenUtils.InvalidClaims> invalidFields = new HashSet<>();
    invalidFields.add(TokenUtils.InvalidClaims.ISSUER);
    String token = TokenUtils.generateTokenString("/Token1.json", invalidFields);
    RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem");
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(publicKey, "https://server.example.com");
    contextInfo.setExpGracePeriodSecs(60);
    JsonWebToken jwt = validateToken(token, contextInfo);
}
 
Example 19
Source Project: smallrye-jwt   Source File: TestJsonWebToken.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { ParseException.class }, description = "Illustrate validation of signer")
public void testNimbusFailSignature() throws Exception {
    HashSet<TokenUtils.InvalidClaims> invalidFields = new HashSet<>();
    invalidFields.add(TokenUtils.InvalidClaims.SIGNER);
    String token = TokenUtils.generateTokenString("/Token1.json", invalidFields);
    RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem");
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(publicKey, "https://server.example.com");
    contextInfo.setExpGracePeriodSecs(60);
    JsonWebToken jwt = validateToken(token, contextInfo);
}
 
Example 20
Source Project: smallrye-jwt   Source File: TestJsonWebToken.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { ParseException.class }, description = "Illustrate validation of exp")
public void testNimbusFailExpired() throws Exception {
    HashMap<String, Long> timeClaims = new HashMap<>();
    HashSet<TokenUtils.InvalidClaims> invalidFields = new HashSet<>();
    invalidFields.add(TokenUtils.InvalidClaims.EXP);
    String token = TokenUtils.generateTokenString("/Token1.json", invalidFields, timeClaims);
    RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem");
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(publicKey, "https://server.example.com");
    contextInfo.setExpGracePeriodSecs(60);
    JsonWebToken jwt = validateToken(token, contextInfo);
}
 
Example 21
Source Project: smallrye-jwt   Source File: TestJsonWebToken.java    License: Apache License 2.0 5 votes vote down vote up
@Test(description = "Illustrate validation of exp that is in grace period")
public void testNimbusExpGrace() throws Exception {
    HashMap<String, Long> timeClaims = new HashMap<>();
    // Set exp to 45 seconds in past
    long exp = TokenUtils.currentTimeInSecs() - 45;
    timeClaims.put(Claims.exp.name(), exp);
    String token = TokenUtils.generateTokenString("/Token1.json", null, timeClaims);
    RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem");
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(publicKey, "https://server.example.com");
    contextInfo.setExpGracePeriodSecs(60);
    JsonWebToken jwt = validateToken(token, contextInfo);
}
 
Example 22
Source Project: smallrye-jwt   Source File: TestTokenWithoutGroupsClaim.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the groups claim is not available")
public void groupsClaimIsNotAvailable() throws Exception {

    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    Assert.assertTrue(jwt.getGroups().isEmpty());
}
 
Example 23
Source Project: smallrye-jwt   Source File: TestTokenRequireSub.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate sub")
public void defaultSubAvailable() throws Exception {
    HashMap<String, Long> timeClaims = new HashMap<>();
    String token = TokenUtils.generateTokenString("/Token1.json", null, timeClaims);
    PublicKey publicKey = TokenUtils.readPublicKey("/publicKey.pem");
    if (publicKey == null) {
        throw new IllegalStateException("Failed to load /publicKey.pem resource");
    }

    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    String sub = jwt.getSubject();
    Assert.assertEquals(sub, "24400320");
}
 
Example 24
Source Project: smallrye-jwt   Source File: TestTokenWhitelistAlgorithm.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "validate the token with default algorithm")
public void tokenDefaultAlgorithm() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    String sub = jwt.getSubject();
    Assert.assertEquals(sub, "24400320");
}
 
Example 25
Source Project: smallrye-jwt   Source File: TestTokenWhitelistAlgorithm.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "ignore no valid algorithm")
public void ignoreNoValidAlgorithm() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    SmallryeJwtUtils.setWhitelistAlgorithms(contextInfo, Optional.of((HMAC_SHA256)));
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    String sub = jwt.getSubject();
    Assert.assertEquals(sub, "24400320");
}
 
Example 26
Source Project: smallrye-jwt   Source File: TestTokenWhitelistAlgorithm.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = TEST_GROUP_JWT, description = "invalid algorithm configuration")
public void invalidAlgorithmConfiguration() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    SmallryeJwtUtils.setWhitelistAlgorithms(contextInfo, Optional.of("abcqwe"));
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    String sub = jwt.getSubject();
    Assert.assertEquals(sub, "24400320");
}
 
Example 27
Source Project: boost   Source File: JwtResource.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@GET
@RolesAllowed({ "admin", "user" })
@Path("/groups")
public Response getJwtGroups(@Context SecurityContext securityContext) {
    Set<String> groups = null;
    Principal user = securityContext.getUserPrincipal();
    if (user instanceof JsonWebToken) {
        JsonWebToken jwt = (JsonWebToken) user;
        groups = jwt.getGroups();
    }
    return Response.ok(groups.toString()).build();
}
 
Example 28
Source Project: quarkus   Source File: OidcJsonWebTokenProducer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * The producer method for the current id token
 *
 * @return the id token
 */
@Produces
@IdToken
@RequestScoped
JsonWebToken currentIdToken() {
    return getTokenCredential(IdTokenCredential.class);
}
 
Example 29
Source Project: quarkus   Source File: OidcJsonWebTokenProducer.java    License: Apache License 2.0 5 votes vote down vote up
private JsonWebToken getTokenCredential(Class<? extends TokenCredential> type) {
    if (identity.isAnonymous()) {
        return new NullJsonWebToken();
    }
    if (identity.getPrincipal() instanceof OidcJwtCallerPrincipal
            && ((OidcJwtCallerPrincipal) identity.getPrincipal()).getCredential().getClass() == type) {
        return (JsonWebToken) identity.getPrincipal();
    }
    TokenCredential credential = identity.getCredential(type);
    if (credential != null) {
        if (credential instanceof AccessTokenCredential && ((AccessTokenCredential) credential).isOpaque()) {
            throw new OIDCException("Opaque access token can not be converted to JsonWebToken");
        }
        JwtClaims jwtClaims;
        try {
            jwtClaims = new JwtConsumerBuilder()
                    .setSkipSignatureVerification()
                    .setSkipAllValidators()
                    .build().processToClaims(credential.getToken());
        } catch (InvalidJwtException e) {
            throw new OIDCException(e);
        }
        jwtClaims.setClaim(Claims.raw_token.name(), credential.getToken());
        return new OidcJwtCallerPrincipal(jwtClaims, credential);
    }
    String tokenType = type == AccessTokenCredential.class ? "access" : "ID";
    throw new OIDCException("Current identity is not associated with an " + tokenType + " token");
}
 
Example 30
Source Project: quarkus   Source File: RolesEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Path("/getInjectedPrincipal")
@RolesAllowed("Tester")
public String getInjectedPrincipal(@Context SecurityContext sec) {
    boolean isJsonWebToken = this.jwtPrincipal instanceof JsonWebToken;
    return "isJsonWebToken:" + isJsonWebToken;
}