public interface AuthUtils
Utility methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Base64.Decoderstatic final Base64.Encoderstatic final PasswordEncoder -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic booleancontainsValue(HttpHeaders headers, String value) Checks if the specified headers contain the specified value.static StringdecodePercent(String str) Decode percent encodedStringvalues.static StringextractErrorDescription(org.json.JSONObject json) Extracts the error description from the specified JSON object.static ObjectfindValueByKey(org.json.JSONObject json, String key) Find the value of a key in a JSON object.static StringjsonToQuery(org.json.JSONObject json) Converts a JSON object to a query string.static voidprocessNonStandardHeaders(org.json.JSONObject json, HttpResponse<String> response, String scopeSeparator) Processes the non-standard headers.static org.json.JSONObjectqueryToJson(String query) Converts a query string to a JSON object.static StringrequireNonNullOrBlank(String str, String message) Checks that the specified string is notnulland throws a customizedNullPointerExceptionif it is, or blank and throws a customizedIllegalArgumentExceptionif it is.
-
Field Details
-
BASE64_ENCODER
-
BASE64_DECODER
-
BCRYPT_PASSWORD_ENCODER
-
-
Method Details
-
requireNonNullOrBlank
Checks that the specified string is notnulland throws a customizedNullPointerExceptionif it is, or blank and throws a customizedIllegalArgumentExceptionif 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 nullitymessage- detail message to be used in the event that aNullPointerExceptionis thrown- Returns:
strif notnullor not blank- Throws:
NullPointerException- ifstrisnullIllegalArgumentException- ifstris blank
-
jsonToQuery
Converts a JSON object to a query string.- Parameters:
json- a JSON object- Returns:
- a query string
-
queryToJson
Converts a query string to a JSON object.- Parameters:
query- a query string- Returns:
- a JSON object
-
findValueByKey
Find the value of a key in a JSON object.- Parameters:
json- the JSON objectkey- the key to search for- Returns:
- the value of the key
-
containsValue
Checks if the specified headers contain the specified value.- Parameters:
headers- the HTTP headersvalue- the value to check- Returns:
trueif 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 objectresponse- the HTTP responsescopeSeparator- the scope separator
-
extractErrorDescription
Extracts the error description from the specified JSON object.- Parameters:
json- the JSON object- Returns:
- the error description
-
decodePercent
Decode percent encodedStringvalues.- Parameters:
str- the percent encodedString- Returns:
- expanded form of the input, for example, "foo%20bar" becomes "foo bar"
-