test_class.file: core/src/test/java/org/keycloak/util/JWKSUtilsTest.java
test_class.identifier: JWKSUtilsTest
test_case.body: @Test
      public void publicRs256() throws Exception {
          Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
  
          String kidRsa1 = "key1";
          String kidRsa2 = "key2";
          String kidEC1 = "key3";
          String kidEC2 = "key4";
          String jwksJson = "{" +
                  "\"keys\": [" +
                  "  {" +
                  "   \"kty\": \"RSA\"," +
                  "   \"alg\": \"RS256\"," +
                  "   \"use\": \"sig\"," +
                  "   \"kid\": \"" + kidRsa1 + "\"," +
                  "   \"n\": \"soFDjoZ5mQ8XAA7reQAFg90inKAHk0DXMTizo4JuOsgzUbhcplIeZ7ks83hsEjm8mP8lUVaHMPMAHEIp3gu6Xxsg-s73ofx1dtt_Fo7aj8j383MFQGl8-FvixTVobNeGeC0XBBQjN8lEl-lIwOa4ZoERNAShplTej0ntDp7TQm0=\"," +
                  "   \"e\": \"AQAB\"" +
                  "  }" +
                  "  ,{" +
                  "   \"kty\": \"RSA\"," +
                  "   \"use\": \"sig\"," +
                  "   \"kid\": \"" + kidRsa2 + "\"," +
                  "   \"n\": \"soFDjoZ5mQ8XAA7reQAFg90inKAHk0DXMTizo4JuOsgzUbhcplIeZ7ks83hsEjm8mP8lUVaHMPMAHEIp3gu6Xxsg-s73ofx1dtt_Fo7aj8j383MFQGl8-FvixTVobNeGeC0XBBQjN8lEl-lIwOa4ZoERNAShplTej0ntDp7TQm0=\"," +
                  "   \"e\": \"AQAB\"" +
                  "  }," +
                  "  {" +
                  "   \"kty\": \"EC\"," +
                  "   \"use\": \"sig\"," +
                  "   \"crv\": \"P-384\"," +
                  "   \"kid\": \"" + kidEC1 + "\"," +
                  "   \"x\": \"KVZ5h_W0-8fXmUrxmyRpO_9vwwI7urXfyxGdxm1hpEuhPj2hhDxivnb2BhNvtC6O\"," +
                  "   \"y\": \"1J3JVw_zR3uB3biAE7fs3V_4tJy2M1JinzWj9a4je5GSoW6zgGV4bk85OcuyUAhj\"," +
                  "   \"alg\": \"ES384\"" +
                  "  }," +
                  "  {" +
                  "   \"kty\": \"EC\"," +
                  "   \"use\": \"sig\"," +
                  "   \"crv\": \"P-384\"," +
                  "   \"kid\": \"" + kidEC2 + "\"," +
                  "   \"x\": \"KVZ5h_W0-8fXmUrxmyRpO_9vwwI7urXfyxGdxm1hpEuhPj2hhDxivnb2BhNvtC6O\"," +
                  "   \"y\": \"1J3JVw_zR3uB3biAE7fs3V_4tJy2M1JinzWj9a4je5GSoW6zgGV4bk85OcuyUAhj\"" +
                  "  }" +
                  "] }";
          JSONWebKeySet jsonWebKeySet = JsonSerialization.readValue(jwksJson, JSONWebKeySet.class);
          Map<String, KeyWrapper> keyWrappersForUse = JWKSUtils.getKeyWrappersForUse(jsonWebKeySet, JWK.Use.SIG);
          assertEquals(4, keyWrappersForUse.size());
  
          KeyWrapper key = keyWrappersForUse.get(kidRsa1);
          assertNotNull(key);
          assertEquals("RS256", key.getAlgorithm());
          assertEquals(KeyUse.SIG, key.getUse());
          assertEquals(kidRsa1, key.getKid());
          assertEquals("RSA", key.getType());
  
           key = keyWrappersForUse.get(kidRsa2);
          assertNotNull(key);
          assertEquals("RS256", key.getAlgorithm());
          assertEquals(KeyUse.SIG, key.getUse());
          assertEquals(kidRsa2, key.getKid());
          assertEquals("RSA", key.getType());
  
          key = keyWrappersForUse.get(kidEC1);
          assertNotNull(key);
          assertEquals("ES384", key.getAlgorithm());
          assertEquals(KeyUse.SIG, key.getUse());
          assertEquals(kidEC1, key.getKid());
          assertEquals("EC", key.getType());
  
          key = keyWrappersForUse.get(kidEC2);
          assertNotNull(key);
          assertNull(key.getAlgorithm());
          assertEquals(KeyUse.SIG, key.getUse());
          assertEquals(kidEC2, key.getKid());
          assertEquals("EC", key.getType());
      }
test_case.class_method_signature: JWKSUtilsTest.publicRs256()
test_case.full_signature: @Test public void publicRs256()
test_case.identifier: publicRs256
test_case.invocations: addProvider readValue getKeyWrappersForUse assertEquals size get assertNotNull assertEquals getAlgorithm assertEquals getUse assertEquals getKid assertEquals getType get assertNotNull assertEquals getAlgorithm assertEquals getUse assertEquals getKid assertEquals getType get assertNotNull assertEquals getAlgorithm assertEquals getUse assertEquals getKid assertEquals getType get assertNotNull assertNull getAlgorithm assertEquals getUse assertEquals getKid assertEquals getType
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void publicRs256()
focal_class.file: core/src/main/java/org/keycloak/util/JWKSUtils.java
focal_class.identifier: JWKSUtils
focal_class.class_method_signature: JWKSUtils.getKeysForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.full_signature: public static Map<String, PublicKey> getKeysForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.identifier: getKeysForUse
focal_class.modifiers: public static
focal_class.parameters: (JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.return: Map<String, PublicKey>
focal_class.signature: Map<String, PublicKey> getKeysForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.class_method_signature: JWKSUtils.getKeyWrappersForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.full_signature: public static Map<String, KeyWrapper> getKeyWrappersForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.identifier: getKeyWrappersForUse
focal_class.modifiers: public static
focal_class.parameters: (JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.return: Map<String, KeyWrapper>
focal_class.signature: Map<String, KeyWrapper> getKeyWrappersForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.class_method_signature: JWKSUtils.getKeyUse(String keyUse)
focal_class.full_signature: private static KeyUse getKeyUse(String keyUse)
focal_class.identifier: getKeyUse
focal_class.modifiers: private static
focal_class.parameters: (String keyUse)
focal_class.return: KeyUse
focal_class.signature: KeyUse getKeyUse(String keyUse)
focal_class.class_method_signature: JWKSUtils.getKeyForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.full_signature: public static JWK getKeyForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.identifier: getKeyForUse
focal_class.modifiers: public static
focal_class.parameters: (JSONWebKeySet keySet, JWK.Use requestedUse)
focal_class.return: JWK
focal_class.signature: JWK getKeyForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_method.body: public static Map<String, KeyWrapper> getKeyWrappersForUse(JSONWebKeySet keySet, JWK.Use requestedUse) {
          Map<String, KeyWrapper> result = new HashMap<>();
          for (JWK jwk : keySet.getKeys()) {
              JWKParser parser = JWKParser.create(jwk);
              if (jwk.getPublicKeyUse().equals(requestedUse.asString()) && parser.isKeyTypeSupported(jwk.getKeyType())) {
                  KeyWrapper keyWrapper = new KeyWrapper();
                  keyWrapper.setKid(jwk.getKeyId());
                  if (jwk.getAlgorithm() != null) {
                      keyWrapper.setAlgorithm(jwk.getAlgorithm());
                  }
                  else if (jwk.getKeyType().equalsIgnoreCase("RSA")){
                      //backwards compatibility: RSA keys without "alg" field set are considered RS256
                      keyWrapper.setAlgorithm("RS256");
                  }
                  keyWrapper.setType(jwk.getKeyType());
                  keyWrapper.setUse(getKeyUse(jwk.getPublicKeyUse()));
                  keyWrapper.setPublicKey(parser.toPublicKey());
                  result.put(keyWrapper.getKid(), keyWrapper);
              }
          }
          return result;
      }
focal_method.class_method_signature: JWKSUtils.getKeyWrappersForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_method.full_signature: public static Map<String, KeyWrapper> getKeyWrappersForUse(JSONWebKeySet keySet, JWK.Use requestedUse)
focal_method.identifier: getKeyWrappersForUse
focal_method.invocations: getKeys create equals getPublicKeyUse asString isKeyTypeSupported getKeyType setKid getKeyId getAlgorithm setAlgorithm getAlgorithm equalsIgnoreCase getKeyType setAlgorithm setType getKeyType setUse getKeyUse getPublicKeyUse setPublicKey toPublicKey put getKid
focal_method.modifiers: public static
focal_method.parameters: (JSONWebKeySet keySet, JWK.Use requestedUse)
focal_method.return: Map<String, KeyWrapper>
focal_method.signature: Map<String, KeyWrapper> getKeyWrappersForUse(JSONWebKeySet keySet, JWK.Use requestedUse)