public JwtClaims mockClaims() { JwtClaims claims = JwtIssuer.getDefaultJwtClaims(); 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"); claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array return claims; } }
private JwtClaims mockCcClaims(String clientId, String scopeString, Map<String, Object> formMap) { JwtClaims claims = JwtIssuer.getDefaultJwtClaims(); claims.setClaim("client_id", clientId); List<String> scope = Arrays.asList(scopeString.split("\\s+")); claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array if(formMap != null) { for(Map.Entry<String, Object> entry : formMap.entrySet()) { claims.setClaim(entry.getKey(), entry.getValue()); } } return claims; }
private JwtClaims mockAcClaims(String clientId, String scopeString, String userId, String userType, String roleString, String csrf, Map<String, Object> formMap) { JwtClaims claims = JwtIssuer.getDefaultJwtClaims(); claims.setClaim("user_id", userId); claims.setClaim("user_type", userType); claims.setClaim("client_id", clientId); if(csrf != null) claims.setClaim("csrf", csrf); if(scopeString != null && scopeString.trim().length() > 0) { List<String> scope = Arrays.asList(scopeString.split("\\s+")); claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array } if(roleString != null && roleString.trim().length() > 0) { List<String> roles = Arrays.asList(roleString.split("\\s+")); claims.setStringListClaim("roles", roles); // multi-valued claims work too and will end up as a JSON array } if(formMap != null) { for(Map.Entry<String, Object> entry : formMap.entrySet()) { claims.setClaim(entry.getKey(), entry.getValue()); } } return claims; }
public JwtClaims mockClaims() { JwtClaims claims = JwtIssuer.getDefaultJwtClaims(); 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"); claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array return claims; } }
claims.setSubject(profile.getId()); permissionTicket.getClaims().forEach((k, v) -> claims.setStringListClaim(k, v.toString())); claims.setStringListClaim(OAuth20Constants.SCOPE, new ArrayList<>(permissionTicket.getScopes())); claims.setStringListClaim(OAuth20Constants.CLIENT_ID, service.getClientId());
public static String getJwt(Map<String, Object> userMap, Boolean rememberMe) throws JoseException { String jwt = null; JwtClaims claims = new JwtClaims(); claims.setIssuer(issuer); claims.setAudience(audience); claims.setExpirationTimeMinutesInTheFuture(rememberMe ? rememberMin : expireMin); claims.setGeneratedJwtId(); claims.setIssuedAtToNow(); claims.setNotBeforeMinutesInThePast(clockSkewMin); claims.setSubject(subject); claims.setClaim("userId", userMap.get("userId")); claims.setClaim("clientId", userMap.get("clientId")); claims.setStringListClaim("roles", (List<String>)userMap.get("roles")); if(userMap.get("host") != null) claims.setClaim("host", userMap.get("host")); JsonWebSignature jws = new JsonWebSignature(); // The payload of the JWS is JSON content of the JWT Claims jws.setPayload(claims.toJson()); // The JWT is signed using the sender's private key jws.setKey(privateKey); // Set the signature algorithm on the JWT/JWS that will integrity protect the claims jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256); // Sign the JWS and produce the compact serialization, which will be the inner JWT/JWS // representation, which is a string consisting of three dot ('.') separated // base64url-encoded parts in the form Header.Payload.Signature jwt = jws.getCompactSerialization(); //System.out.println("JWT: " + jwt); return jwt; }