Interface AuthUtils


public interface AuthUtils
Utility methods.
  • Field Details

    • BCRYPT_PASSWORD_ENCODER

      static final PasswordEncoder BCRYPT_PASSWORD_ENCODER
  • Method Details

    • requireNonNullOrBlank

      static String requireNonNullOrBlank(String str, String message)
      Checks that the specified string is not null and throws a customized NullPointerException if it is, or blank and throws a customized IllegalArgumentException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:
       public Credentials(String username, String password) {
           this.username = Utils.requireNonNullOrBlank(username, "id must not be null or blank");
           this.password = Utils.requireNonNullOrBlank(password, "password must not be null or blank");
       }
       
      Parameters:
      str - the string to check for nullity
      message - detail message to be used in the event that a NullPointerException is thrown
      Returns:
      str if not null or not blank
      Throws:
      NullPointerException - if str is null
      IllegalArgumentException - if str is blank
    • jsonToQuery

      static String jsonToQuery(org.json.JSONObject json)
      Converts a JSON object to a query string.
      Parameters:
      json - a JSON object
      Returns:
      a query string
    • queryToJson

      static org.json.JSONObject queryToJson(String query)
      Converts a query string to a JSON object.
      Parameters:
      query - a query string
      Returns:
      a JSON object
    • findValueByKey

      static Object findValueByKey(org.json.JSONObject json, String key)
      Find the value of a key in a JSON object.
      Parameters:
      json - the JSON object
      key - the key to search for
      Returns:
      the value of the key
    • containsValue

      static boolean containsValue(HttpHeaders headers, String value)
      Checks if the specified headers contain the specified value.
      Parameters:
      headers - the HTTP headers
      value - the value to check
      Returns:
      true if the specified headers contain the specified value
    • processNonStandardHeaders

      static void processNonStandardHeaders(org.json.JSONObject json, HttpResponse<String> response, String scopeSeparator)
      Processes the non-standard headers.
      Parameters:
      json - the JSON object
      response - the HTTP response
      scopeSeparator - the scope separator
    • extractErrorDescription

      static String extractErrorDescription(org.json.JSONObject json)
      Extracts the error description from the specified JSON object.
      Parameters:
      json - the JSON object
      Returns:
      the error description
    • decodePercent

      static String decodePercent(String str)
      Decode percent encoded String values.
      Parameters:
      str - the percent encoded String
      Returns:
      expanded form of the input, for example, "foo%20bar" becomes "foo bar"