java.lang.Object
it.pagopa.swclient.mil.azureservices.keyvault.keys.util.KeyUtils

public class KeyUtils extends Object

Provides utilities to handle keys in different formats.

Author:
Antonio Tarricone
  • Field Details

    • DOMAIN_KEY

      public static final String DOMAIN_KEY

      Key of tag to mark the domain (who uses it) of a Key handled by Azure Key Vault.

      See Also:
  • Constructor Details

    • KeyUtils

      private KeyUtils()

      This class has static methods only.

  • Method Details

    • getKeyName

      public static String getKeyName(KeyItem keyItem)

      Returns the name of an Azure Key Vault key.

      Parameters:
      keyItem - KeyItem
      Returns:
      The name of the key.
    • getKeyNameVersion

      public static String[] getKeyNameVersion(KeyItem keyItem)

      Returns the name and the version of an Azure Key Vault key.

      Parameters:
      keyItem - KeyItem
      Returns:
      An array which contains in first position the name of the key and in second the version.
    • doesDomainMatch

      public static boolean doesDomainMatch(KeyItem keyItem, String domain)

      Verifies if an Azure Key Vault key has the wanted domain (who use it).

      Parameters:
      keyItem - KeyItem
      domain - The wanted domain.
      Returns:
      true if the domain matches, otherwise false.
    • isValid

      public static boolean isValid(String kid, KeyAttributes keyAttributes)

      Verifies if a key:

      • is enabled;
      • is not expired;
      • has coherent creation date;
      • has coherent not-before-date.
      Parameters:
      kid - The ID of the key.
      keyAttributes - KeyAttributes
      Returns:
      true if the key is valid, otherwise false.
    • isValid

      public static boolean isValid(KeyItem keyItem)

      Verifies if a key:

      • is enabled;
      • is not expired;
      • has coherent creation date;
      • has coherent not-before-date.
      Parameters:
      keyItem - KeyItem
      Returns:
      true if the key is valid, otherwise false.
      See Also:
    • doOpsMatch

      public static boolean doOpsMatch(KeyBundle keyBundle, List<String> expectedOps)

      Verifies if a key is suitable for given operations.

      Parameters:
      keyBundle - KeyBundle
      expectedOps - JsonWebKeyOperation
      Returns:
      true if the key is suitable, otherwise false.
    • doesTypeMatch

      public static boolean doesTypeMatch(KeyBundle keyBundle, List<String> expectedKtys)

      Verifies if a key has a given type.

      Parameters:
      keyBundle - KeyBundle
      expectedKtys - JsonWebKeyType
      Returns:
      true if the key has the given type, otherwise false.
    • getQueryParameters

      public static Map<String,String> getQueryParameters(String url)

      Extracts query parameters from link to handle paged results from Azure Key Vault.

      Parameters:
      url - The URL to be process.
      Returns:
      The query parameters.
    • isExpired

      public static boolean isExpired(KeyItem keyItem)

      Verifies if a key is expired.

      Parameters:
      keyItem - KeyItem
      Returns:
      true if the key is expired, otherwise false.