Java Code Examples for io.smallrye.jwt.auth.principal.JWTAuthContextInfo#setSubjectPath()

The following examples show how to use io.smallrye.jwt.auth.principal.JWTAuthContextInfo#setSubjectPath() . 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 File: TestTokenWithSubPath.java    From smallrye-jwt with 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 2
Source File: TestTokenWithSubPath.java    From smallrye-jwt with 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 3
Source File: TestTokenWithSubPath.java    From smallrye-jwt with 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 long path")
public void subClaimIsNotAvailableOnTooDeepPath() throws Exception {
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, TEST_ISSUER);
    contextInfo.setRequireNamedPrincipal(false);
    contextInfo.setSubjectPath("realm/access/sub/principal/5");
    JWTCallerPrincipalFactory factory = JWTCallerPrincipalFactory.instance();
    JsonWebToken jwt = factory.parse(token, contextInfo);
    Assert.assertNull(jwt.getSubject());
}
 
Example 4
Source File: TestTokenWithSubPath.java    From smallrye-jwt with 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 5
Source File: TestTokenWithSubPath.java    From smallrye-jwt with 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 6
Source File: SmallryeJwtUtils.java    From smallrye-jwt with Apache License 2.0 4 votes vote down vote up
public static void setContextSubPath(JWTAuthContextInfo contextInfo, Optional<String> subPath) {
    if (checkClaimPath(Claims.sub.name(), subPath)) {
        contextInfo.setSubjectPath(subPath.get());
    }
}