@Test public void testCreateUser_withClaimsMapper() { List<Map<String, String>> claimsMapper = new ArrayList<>(); Map<String, String> claimMapper1 = new HashMap<>(); claimMapper1.put("assertion_claim", "username"); claimMapper1.put("token_claim", "username"); Map<String, String> claimMapper2 = new HashMap<>(); claimMapper2.put("assertion_claim", "email"); claimMapper2.put("token_claim", "email"); claimsMapper.add(claimMapper1); claimsMapper.add(claimMapper2); when(jwtBearerTokenGranterConfiguration.getClaimsMapper()).thenReturn(claimsMapper); Map<String, Object> assertionClaims = new HashMap<>(); assertionClaims.put("username", "test_username"); assertionClaims.put("email", "test_email"); User user = jwtBearerExtensionGrantProvider.createUser(new JWT(assertionClaims)); assertEquals(3, user.getAdditionalInformation().values().size()); assertEquals("test_username", user.getAdditionalInformation().get("username")); assertEquals("test_email", user.getAdditionalInformation().get("email")); }
public User createUser(JWT jwt) { final String sub = jwt.getSub(); final String username = jwt.containsKey(StandardClaims.PREFERRED_USERNAME) ? jwt.get(StandardClaims.PREFERRED_USERNAME).toString() : sub; User user = new DefaultUser(username); ((DefaultUser) user).setId(sub); Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put(io.gravitee.am.common.jwt.Claims.sub, sub); List<Map<String, String>> claimsMapper = jwtBearerTokenGranterConfiguration.getClaimsMapper(); if (claimsMapper != null && !claimsMapper.isEmpty()) { claimsMapper.forEach(claimMapper -> { String assertionClaim = claimMapper.get("assertion_claim"); String tokenClaim = claimMapper.get("token_claim"); if (jwt.containsKey(assertionClaim)) { additionalInformation.put(tokenClaim, jwt.get(assertionClaim)); } }); } ((DefaultUser) user).setAdditionalInformation(additionalInformation); return user; }
JWTBearerExtensionGrantProvider implements ExtensionGrantProvider, InitializingBean { public User createUser(JWT jwt) { final String sub = jwt.getSub(); final String username = jwt.containsKey(StandardClaims.PREFERRED_USERNAME) ? jwt.get(StandardClaims.PREFERRED_USERNAME).toString() : sub; User user = new DefaultUser(username); ((DefaultUser) user).setId(sub); Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put(io.gravitee.am.common.jwt.Claims.sub, sub); List<Map<String, String>> claimsMapper = jwtBearerTokenGranterConfiguration.getClaimsMapper(); if (claimsMapper != null && !claimsMapper.isEmpty()) { claimsMapper.forEach(claimMapper -> { String assertionClaim = claimMapper.get("assertion_claim"); String tokenClaim = claimMapper.get("token_claim"); if (jwt.containsKey(assertionClaim)) { additionalInformation.put(tokenClaim, jwt.get(assertionClaim)); } }); } ((DefaultUser) user).setAdditionalInformation(additionalInformation); return user; } }
JWTBearerExtensionGrantProvider implements ExtensionGrantProvider, InitializingBean { public User createUser(JWT jwt) { final String sub = jwt.getSub(); final String username = jwt.containsKey(StandardClaims.PREFERRED_USERNAME) ? jwt.get(StandardClaims.PREFERRED_USERNAME).toString() : sub; User user = new DefaultUser(username); ((DefaultUser) user).setId(sub); Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put(io.gravitee.am.common.jwt.Claims.sub, sub); List<Map<String, String>> claimsMapper = jwtBearerTokenGranterConfiguration.getClaimsMapper(); if (claimsMapper != null && !claimsMapper.isEmpty()) { claimsMapper.forEach(claimMapper -> { String assertionClaim = claimMapper.get("assertion_claim"); String tokenClaim = claimMapper.get("token_claim"); if (jwt.containsKey(assertionClaim)) { additionalInformation.put(tokenClaim, jwt.get(assertionClaim)); } }); } ((DefaultUser) user).setAdditionalInformation(additionalInformation); return user; }  }
JWTBearerExtensionGrantProvider implements ExtensionGrantProvider, InitializingBean { public User createUser(JWT jwt) { final String sub = jwt.getSub(); final String username = jwt.containsKey(StandardClaims.PREFERRED_USERNAME) ? jwt.get(StandardClaims.PREFERRED_USERNAME).toString() : sub; User user = new DefaultUser(username); ((DefaultUser) user).setId(sub); Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put(io.gravitee.am.common.jwt.Claims.sub, sub); List<Map<String, String>> claimsMapper = jwtBearerTokenGranterConfiguration.getClaimsMapper(); if (claimsMapper != null && !claimsMapper.isEmpty()) { claimsMapper.forEach(claimMapper -> { String assertionClaim = claimMapper.get("assertion_claim"); String tokenClaim = claimMapper.get("token_claim"); if (jwt.containsKey(assertionClaim)) { additionalInformation.put(tokenClaim, jwt.get(assertionClaim)); } }); } ((DefaultUser) user).setAdditionalInformation(additionalInformation); return user; }  @Override void afterPropertiesSet(); @Override Maybe<User> grant(TokenRequest tokenRequest); User createUser(JWT jwt); }
JWTBearerExtensionGrantProvider implements ExtensionGrantProvider, InitializingBean { public User createUser(JWT jwt) { final String sub = jwt.getSub(); final String username = jwt.containsKey(StandardClaims.PREFERRED_USERNAME) ? jwt.get(StandardClaims.PREFERRED_USERNAME).toString() : sub; User user = new DefaultUser(username); ((DefaultUser) user).setId(sub); Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put(io.gravitee.am.common.jwt.Claims.sub, sub); List<Map<String, String>> claimsMapper = jwtBearerTokenGranterConfiguration.getClaimsMapper(); if (claimsMapper != null && !claimsMapper.isEmpty()) { claimsMapper.forEach(claimMapper -> { String assertionClaim = claimMapper.get("assertion_claim"); String tokenClaim = claimMapper.get("token_claim"); if (jwt.containsKey(assertionClaim)) { additionalInformation.put(tokenClaim, jwt.get(assertionClaim)); } }); } ((DefaultUser) user).setAdditionalInformation(additionalInformation); return user; }  @Override void afterPropertiesSet(); @Override Maybe<User> grant(TokenRequest tokenRequest); User createUser(JWT jwt);  }