use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class OauthHelperTest method getTestClaims.
private static JwtClaims getTestClaims() {
JwtClaims claims = new JwtClaims();
claims.setIssuer("urn:com:networknt:oauth2:v1");
claims.setAudience("urn:com.networknt");
claims.setExpirationTimeMinutesInTheFuture(10);
// 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", "1.0");
claims.setClaim("user_id", "steve");
claims.setClaim("user_type", "EMPLOYEE");
claims.setClaim("client_id", "aaaaaaaa-1234-1234-1234-bbbbbbbb");
List<String> scope = Arrays.asList("api.r", "api.w");
// multi-valued claims work too and will end up as a JSON array
claims.setStringListClaim("scope", scope);
return claims;
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class Http2ClientIT method isTokenExpired.
private static boolean isTokenExpired(String authorization) {
boolean expired = false;
String jwt = getJwtFromAuthorization(authorization);
if (jwt != null) {
try {
JwtConsumer consumer = new JwtConsumerBuilder().setSkipAllValidators().setDisableRequireSignature().setSkipSignatureVerification().build();
JwtContext jwtContext = consumer.process(jwt);
JwtClaims jwtClaims = jwtContext.getJwtClaims();
try {
if ((NumericDate.now().getValue() - 60) >= jwtClaims.getExpirationTime().getValue()) {
expired = true;
}
} catch (MalformedClaimException e) {
logger.error("MalformedClaimException:", e);
}
} catch (InvalidJwtException e) {
e.printStackTrace();
}
}
return expired;
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class Http2ClientPoolIT method getTestClaims.
private static JwtClaims getTestClaims() {
JwtClaims claims = new JwtClaims();
claims.setIssuer("urn:com:networknt:oauth2:v1");
claims.setAudience("urn:com.networknt");
claims.setExpirationTimeMinutesInTheFuture(10);
// 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", "1.0");
claims.setClaim("user_id", "steve");
claims.setClaim("user_type", "EMPLOYEE");
claims.setClaim("client_id", "aaaaaaaa-1234-1234-1234-bbbbbbbb");
List<String> scope = Arrays.asList("api.r", "api.w");
// multi-valued claims work too and will end up as a JSON array
claims.setStringListClaim("scope", scope);
return claims;
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class JwtIssuerTest method GroupToRoleAccessControlWrong.
/**
* The returned token contains groups User_API_Wrong for controller-group-role rule
* @throws Exception
*/
@Test
public void GroupToRoleAccessControlWrong() throws Exception {
JwtClaims claims = ClaimsUtil.getTestClaimsGroup("stevehu", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e72", Arrays.asList("portal.r", "portal.w"), "User_API_Wrong");
claims.setExpirationTimeMinutesInTheFuture(5256000);
String jwt = JwtIssuer.getJwt(claims);
System.out.println("***Long lived token Authorization code customer with a wrong controller groups that cannot be converted to roles ***: " + jwt);
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class JwtIssuerTest method sidecarReferenceBootstrapWithServiceId.
/**
* 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 sidecarReferenceBootstrapWithServiceId() throws Exception {
JwtClaims claims = ClaimsUtil.getTestCcClaimsScopeService("f7d42348-c647-4efb-a52d-4c5787421e72", "A8E73740C0041C03D67C3A951AA1D7533C8F9F2FB57D7BA107210B9BC9E06DA2", "com.networknt.petstore-1.0.0");
claims.setExpirationTimeMinutesInTheFuture(5256000);
String jwt = JwtIssuer.getJwt(claims);
System.out.println("***Reference Long lived Bootstrap token for config server and controller: " + jwt);
}
Aggregations