Class AuthorizationUtils

java.lang.Object
net.solarnetwork.security.AuthorizationUtils

public class AuthorizationUtils extends Object
Utilities for authorization.
Since:
1.78
Version:
1.0
Author:
matt
  • Field Details

    • SN_DATE_HEADER

      public static final String SN_DATE_HEADER
      The X-SN-Date header name.
      See Also:
    • EMPTY_STRING_SHA256_HEX

      public static final String EMPTY_STRING_SHA256_HEX
      The hex-encoded SHA256 value of an empty string.
    • AUTHORIZATION_DATE_FORMATTER

      public static final DateTimeFormatter AUTHORIZATION_DATE_FORMATTER
      Date formatter that formats or parses a date without an offset, such as 20111203, in the GMT time zone.
    • AUTHORIZATION_DATE_HEADER_FORMATTER

      public static final DateTimeFormatter AUTHORIZATION_DATE_HEADER_FORMATTER
      Date formatter that formats or parses timestamp values in the HTTP Date header format, similar to RFC 1123 but with 2-digit day values used always.

      An example of this date format is Fri, 13 Aug 2021 13:55:12 GMT.

    • AUTHORIZATION_TIMESTAMP_FORMATTER

      public static final DateTimeFormatter AUTHORIZATION_TIMESTAMP_FORMATTER
      Date formatter that formats or parses timestamp values in the ISO 8601 condensed timestamp form with second resolution, in the GMT time zone.

      An example of this date format is 20210813T135512Z.

  • Method Details

    • computeHmacSha256

      public static byte[] computeHmacSha256(String key, String msg)
      Compute a HMAC-SHA256 digest from UTF-8 string values.
      Parameters:
      key - the key to sign the digest with, which is assumed to be a UTF-8 encoded string.
      msg - the message content to sign, which is assumed to be a UTF-8 encoded string.
      Returns:
      the computed digest
      Throws:
      SecurityException - if the strings cannot be interpreted as UTF-8 or HmacSHA256 is not supported by the runtime security provider
    • computeHmacSha256

      public static byte[] computeHmacSha256(byte[] key, String msg)
      Compute a HMAC-SHA256 digest from a byte array password.
      Parameters:
      key - The key to sign the digest with.
      msg - the message content to sign, which is assumed to be a UTF-8 encoded string
      Returns:
      the computed digest
      Throws:
      SecurityException - if the strings cannot be interpreted as UTF-8 or HmacSHA256 is not supported by the runtime security provider
    • computeMacDigest

      public static byte[] computeMacDigest(String secret, String msg, String alg)
      Compute a MAC digest from UTF-8 string values.
      Parameters:
      secret - the secret to sign the digest with, which is assumed to be a UTF-8 encoded string.
      msg - the message content to sign, which is assumed to be a UTF-8 encoded string
      alg - the MAC algorithm to use, which must be supported by the runtime security provider
      Returns:
      the computed digest
      Throws:
      SecurityException - if the strings cannot be interpreted as UTF-8 or alg is not supported by the runtime security provider
    • computeMacDigest

      public static byte[] computeMacDigest(byte[] key, byte[] msg, String alg)
      Compute a MAC digest.
      Parameters:
      key - the key to sign the digest with
      msg - the message content to sign
      alg - the MAC algorithm to use, which must be supported by the runtime security provider
      Returns:
      the computed digest
      Throws:
      SecurityException - if the strings cannot be interpreted as UTF-8 or alg is not supported by the runtime security provider
    • computeHmacSha256Hex

      public static String computeHmacSha256Hex(byte[] signingKey, String signatureData)
      Compute an HMAC SHA256 hex-encoded signature value from a signing key and signature data.
      Parameters:
      signingKey - the signing key
      signatureData - the signature data
      Returns:
      the hex-encoded signature value
    • uriEncode

      public static String uriEncode(CharSequence input)
      Formal implementation of "uri encoding" using UTF-8 encoding for SolarNetwork authentication.
      Parameters:
      input - the text input to encode
      Returns:
      the URI escaped string
    • semiColonDelimitedList

      public static String semiColonDelimitedList(String[] list)
      Format a string array into a semicolon delimited string.
      Parameters:
      list - the list for format
      Returns:
      the delimited list