Search in sources :

Example 41 with JwtClaims

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

the class JwtIssuerTest method AcGroupAccessControlWrong.

/**
 * The returned token contains scopes for access-control example
 * @throws Exception
 */
@Test
public void AcGroupAccessControlWrong() throws Exception {
    JwtClaims claims = ClaimsUtil.getTestClaimsGroup("stevehu", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e72", Arrays.asList("account.r", "account.w"), "backOffice");
    claims.setExpirationTimeMinutesInTheFuture(5256000);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***Long lived token Authorization code customer with  roles***: " + jwt);
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

Example 42 with JwtClaims

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

the class JwtIssuerTest method longlivedLightPortalController.

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

Example 43 with JwtClaims

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

the class JwtIssuerTest method sidecarReferenceBootstrap.

/**
 * This token is used to connect to the light-config-server with serviceId 0100 for testing with a service specific for a client.
 * @throws Exception
 */
@Test
public void sidecarReferenceBootstrap() throws Exception {
    JwtClaims claims = ClaimsUtil.getTestCcClaimsScopeService("f7d42348-c647-4efb-a52d-4c5787421e72", "portal.r portal.w", "0100");
    claims.setExpirationTimeMinutesInTheFuture(5256000);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***Reference Long lived Bootstrap token for config server and controller: " + jwt);
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

Example 44 with JwtClaims

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

the class JwtIssuerTest method longlivedCcLocalProxyWithScp.

/**
 * The returned token contains scp as the key for the scope. Some OAuth 2.0 provider like Okta use this claim. All scopes are separated by comma.
 * The token will have proxy.r and proxy.w as scopes for testing with proxy configuration in light-config-test proxy folder.
 * @throws Exception
 */
@Test
public void longlivedCcLocalProxyWithScp() throws Exception {
    JwtClaims claims = ClaimsUtil.getTestCcClaimsWithScp("f7d42348-c647-4efb-a52d-4c5787421e73", Arrays.asList("proxy.r", "proxy.w"));
    claims.setExpirationTimeMinutesInTheFuture(5256000);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***Long lived token for proxy***: " + jwt);
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

Example 45 with JwtClaims

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

the class JwtIssuerTest method longLivedProductSubjectJwt.

@Test
public void longLivedProductSubjectJwt() throws Exception {
    Map<String, String> custom = new HashMap<>();
    custom.put("consumer_application_id", "361");
    custom.put("request_transit", "67");
    JwtClaims claims = ClaimsUtil.getCustomClaims("steve", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e72", null, custom, "user");
    claims.setExpirationTimeMinutesInTheFuture(5256000);
    String jwt = JwtIssuer.getJwt(claims);
    System.out.println("***LongLived product subject JWT***: " + jwt);
}
Also used : HashMap(java.util.HashMap) JwtClaims(org.jose4j.jwt.JwtClaims) Test(org.junit.Test)

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