Search in sources :

Example 46 with JwtClaims

use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.

the class JwtIssuerTest method GroupToRoleAccessControlRight.

/**
 * The returned token contains groups User_API_Dev_R User_API_Dev_W for controller-group-role rule
 * @throws Exception
 */
@Test
public void GroupToRoleAccessControlRight() throws Exception {
    JwtClaims claims = ClaimsUtil.getTestClaimsGroup("stevehu", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e72", Arrays.asList("portal.r", "portal.w"), "User_API_Dev_R User_API_Dev_W");
    claims.setExpirationTimeMinutesInTheFuture(5256000);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***Long lived token Authorization code customer with controller groups to roles ***: " + jwt);
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

Example 47 with JwtClaims

use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.

the class JwtIssuerTest method longlivedLightPortalConfigServer.

@Test
public void longlivedLightPortalConfigServer() throws Exception {
    JwtClaims claims = ClaimsUtil.getTestClaims("stevehu@gmail.com", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e73", Arrays.asList("portal.r", "portal.w"), "user CfgPltAdmin CfgPltRead CfgPltWrite");
    claims.setExpirationTimeMinutesInTheFuture(5256000);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***Long lived token for portal config server ***: " + jwt);
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

Example 48 with JwtClaims

use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.

the class JwtIssuerTest method longLivedAPIAJwt.

@Test
public void longLivedAPIAJwt() throws Exception {
    JwtClaims claims = ClaimsUtil.getTestClaims("Steve", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e72", Arrays.asList("api_a.w", "api_b.w", "api_c.w", "api_d.w", "server.info.r"), "user");
    claims.setExpirationTimeMinutesInTheFuture(5256000);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***LongLived APIA JWT***: " + jwt);
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

Example 49 with JwtClaims

use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.

the class JwtIssuerTest method normalPetStoreJwt.

@Test
public void normalPetStoreJwt() throws Exception {
    JwtClaims claims = ClaimsUtil.getTestClaims("steve", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e72", Arrays.asList("write:pets", "read:pets"), "user");
    claims.setExpirationTimeMinutesInTheFuture(10);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***JWT***: " + jwt);
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

Example 50 with JwtClaims

use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.

the class JwtIssuer method getJwtClaimsWithExpiresIn.

/**
 * Construct a default JwtClaims
 * @param expiresIn expires in
 * @return JwtClaims
 */
public static JwtClaims getJwtClaimsWithExpiresIn(int expiresIn) {
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(jwtConfig.getIssuer());
    claims.setAudience(jwtConfig.getAudience());
    claims.setExpirationTimeMinutesInTheFuture(expiresIn / 60);
    // a unique identifier for the token
    claims.setGeneratedJwtId();
    // when the token was issued/created (now)
    claims.setIssuedAtToNow();
    // time before which the token is not yet valid (2 minutes ago)
    claims.setNotBeforeMinutesInThePast(2);
    claims.setClaim("version", jwtConfig.getVersion());
    return claims;
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims)

Aggregations

JwtClaims (org.jose4j.jwt.JwtClaims)130 Test (org.junit.Test)47 JwtConsumer (org.jose4j.jwt.consumer.JwtConsumer)23 JwtConsumerBuilder (org.jose4j.jwt.consumer.JwtConsumerBuilder)23 InvalidJwtException (org.jose4j.jwt.consumer.InvalidJwtException)21 MalformedClaimException (org.jose4j.jwt.MalformedClaimException)19 JoseException (org.jose4j.lang.JoseException)17 lombok.val (lombok.val)15 JsonWebSignature (org.jose4j.jws.JsonWebSignature)15 Map (java.util.Map)14 JwtContext (org.jose4j.jwt.consumer.JwtContext)11 NumericDate (org.jose4j.jwt.NumericDate)9 JsonWebStructure (org.jose4j.jwx.JsonWebStructure)9 HashMap (java.util.HashMap)7 KeyStoreException (java.security.KeyStoreException)6 ArrayList (java.util.ArrayList)5 OidcRegisteredService (org.apereo.cas.services.OidcRegisteredService)5 ExpiredTokenException (com.networknt.exception.ExpiredTokenException)4 JwksVerificationKeyResolver (org.jose4j.keys.resolvers.JwksVerificationKeyResolver)4 Test (org.junit.jupiter.api.Test)4