@Test public void testKeycloakRealmAndResourceAccessTokenNullClient() throws Exception { OidcTenantConfig.Roles rolesCfg = OidcTenantConfig.Roles.fromClaimPath(null); List<String> roles = OidcUtils.findRoles(null, rolesCfg, read(getClass().getResourceAsStream("/tokenKeycloakResourceAccess.json"))); assertEquals(1, roles.size()); assertTrue(roles.contains("realm1")); }
public static List<String> findRoles(String clientId, OidcTenantConfig.Roles rolesConfig, JsonObject json) { if (rolesConfig.getRoleClaimPath().isPresent()) { return findClaimWithRoles(rolesConfig, rolesConfig.getRoleClaimPath().get(), json, true); } List<String> groups = findClaimWithRoles(rolesConfig, Claims.groups.name(), json, false); if (!groups.isEmpty()) { return groups; } else { List<String> allRoles = new LinkedList<>(); allRoles.addAll(findClaimWithRoles(rolesConfig, "realm_access/roles", json, false)); if (clientId != null) { allRoles.addAll(findClaimWithRoles(rolesConfig, "resource_access/" + clientId + "/roles", json, false)); } return allRoles; } }
OidcUtils { public static List<String> findRoles(String clientId, OidcTenantConfig.Roles rolesConfig, JsonObject json) { if (rolesConfig.getRoleClaimPath().isPresent()) { return findClaimWithRoles(rolesConfig, rolesConfig.getRoleClaimPath().get(), json, true); } List<String> groups = findClaimWithRoles(rolesConfig, Claims.groups.name(), json, false); if (!groups.isEmpty()) { return groups; } else { List<String> allRoles = new LinkedList<>(); allRoles.addAll(findClaimWithRoles(rolesConfig, "realm_access/roles", json, false)); if (clientId != null) { allRoles.addAll(findClaimWithRoles(rolesConfig, "resource_access/" + clientId + "/roles", json, false)); } return allRoles; } } }
OidcUtils { public static List<String> findRoles(String clientId, OidcTenantConfig.Roles rolesConfig, JsonObject json) { if (rolesConfig.getRoleClaimPath().isPresent()) { return findClaimWithRoles(rolesConfig, rolesConfig.getRoleClaimPath().get(), json, true); } List<String> groups = findClaimWithRoles(rolesConfig, Claims.groups.name(), json, false); if (!groups.isEmpty()) { return groups; } else { List<String> allRoles = new LinkedList<>(); allRoles.addAll(findClaimWithRoles(rolesConfig, "realm_access/roles", json, false)); if (clientId != null) { allRoles.addAll(findClaimWithRoles(rolesConfig, "resource_access/" + clientId + "/roles", json, false)); } return allRoles; } } private  OidcUtils(); }
OidcUtils { public static List<String> findRoles(String clientId, OidcTenantConfig.Roles rolesConfig, JsonObject json) { if (rolesConfig.getRoleClaimPath().isPresent()) { return findClaimWithRoles(rolesConfig, rolesConfig.getRoleClaimPath().get(), json, true); } List<String> groups = findClaimWithRoles(rolesConfig, Claims.groups.name(), json, false); if (!groups.isEmpty()) { return groups; } else { List<String> allRoles = new LinkedList<>(); allRoles.addAll(findClaimWithRoles(rolesConfig, "realm_access/roles", json, false)); if (clientId != null) { allRoles.addAll(findClaimWithRoles(rolesConfig, "resource_access/" + clientId + "/roles", json, false)); } return allRoles; } } private  OidcUtils(); static boolean isOpaqueToken(String token); static JsonObject decodeJwtContent(String jwt); static boolean validateClaims(OidcTenantConfig.Token tokenConfig, JsonObject json); static List<String> findRoles(String clientId, OidcTenantConfig.Roles rolesConfig, JsonObject json); static void setSecurityIdentityRoles(QuarkusSecurityIdentity.Builder builder, OidcTenantConfig config,
            JsonObject rolesJson); static void setBlockinApiAttribute(QuarkusSecurityIdentity.Builder builder, RoutingContext vertxContext); static void setTenantIdAttribute(QuarkusSecurityIdentity.Builder builder, OidcTenantConfig config); static void setSecurityIdentityUserInfo(QuarkusSecurityIdentity.Builder builder, JsonObject userInfo); static void validatePrimaryJwtTokenType(OidcTenantConfig.Token tokenConfig, JsonObject tokenJson); }
OidcUtils { public static List<String> findRoles(String clientId, OidcTenantConfig.Roles rolesConfig, JsonObject json) { if (rolesConfig.getRoleClaimPath().isPresent()) { return findClaimWithRoles(rolesConfig, rolesConfig.getRoleClaimPath().get(), json, true); } List<String> groups = findClaimWithRoles(rolesConfig, Claims.groups.name(), json, false); if (!groups.isEmpty()) { return groups; } else { List<String> allRoles = new LinkedList<>(); allRoles.addAll(findClaimWithRoles(rolesConfig, "realm_access/roles", json, false)); if (clientId != null) { allRoles.addAll(findClaimWithRoles(rolesConfig, "resource_access/" + clientId + "/roles", json, false)); } return allRoles; } } private  OidcUtils(); static boolean isOpaqueToken(String token); static JsonObject decodeJwtContent(String jwt); static boolean validateClaims(OidcTenantConfig.Token tokenConfig, JsonObject json); static List<String> findRoles(String clientId, OidcTenantConfig.Roles rolesConfig, JsonObject json); static void setSecurityIdentityRoles(QuarkusSecurityIdentity.Builder builder, OidcTenantConfig config,
            JsonObject rolesJson); static void setBlockinApiAttribute(QuarkusSecurityIdentity.Builder builder, RoutingContext vertxContext); static void setTenantIdAttribute(QuarkusSecurityIdentity.Builder builder, OidcTenantConfig config); static void setSecurityIdentityUserInfo(QuarkusSecurityIdentity.Builder builder, JsonObject userInfo); static void validatePrimaryJwtTokenType(OidcTenantConfig.Token tokenConfig, JsonObject tokenJson);  }