Package io.jans.ca.plugin.adminui.utils
Class CommonUtils
java.lang.Object
io.jans.ca.plugin.adminui.utils.CommonUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DateaddMinutes(Date date, int minutesToAdd) Return a new Date representing the given date plus the specified number of minutes.static StringconvertIsoToDateString(String isoDateTime) static Stringstatic LocalDateconvertStringToLocalDate(String dateString) static GenericResponsecreateGenericResponse(boolean result, int responseCode, String responseMessage) static GenericResponsecreateGenericResponse(boolean result, int responseCode, String responseMessage, com.fasterxml.jackson.databind.JsonNode node) Create a GenericResponse populated with the provided status, code, message, and JSON response object.static GenericResponsecreateResponseWithByteArray(boolean result, int responseCode, String responseMessage, byte[] byteArray) Creates a GenericResponse populated with the provided success flag, response code, message, and byte array.static Stringstatic StringgetClaims(io.jans.as.model.jwt.Jwt jwtObj) Extracts claims from a Jwt into a Map keyed by claim name.static Stringstatic booleanhasShortCode(String input) static booleanhasShortCode(Map<String, ?> map) Checks whether any value in the provided map contains a placeholder of the form `${name}`.static booleanisValidJson(String json) static StringjoinAndUrlEncode(Collection<String> list) jsonStringToMap(String jsonString) static RSAPrivateKeyloadPrivateKey(String privateKeyPEM) static StringmapToJsonString(Map<String, Object> mapObj) static StringreplacePlaceholders(String url, Map<String, Object> placeholderValues) static com.fasterxml.jackson.databind.JsonNodetoJsonNode(Object object) Converts any Java object into a JsonNode representation.static booleantoPrimitiveOrDefaultFalse(Boolean booleanObject) Convert a Boolean reference to its primitive form, using a default value when the input is null.static StringtoUrlEncodedString(Map<String, String> params) Builds a UTF-8 URL-encoded query string from the provided parameters.
-
Field Details
-
LS_DATE_FORMAT
-
-
Constructor Details
-
CommonUtils
public CommonUtils()
-
-
Method Details
-
joinAndUrlEncode
- Throws:
UnsupportedEncodingException
-
encode
- Throws:
UnsupportedEncodingException
-
getFormattedDate
-
loadPrivateKey
- Throws:
Exception
-
decode
- Throws:
UnsupportedEncodingException
-
createGenericResponse
public static GenericResponse createGenericResponse(boolean result, int responseCode, String responseMessage) -
createGenericResponse
public static GenericResponse createGenericResponse(boolean result, int responseCode, String responseMessage, com.fasterxml.jackson.databind.JsonNode node) Create a GenericResponse populated with the provided status, code, message, and JSON response object.- Parameters:
result- whether the operation was successfulresponseCode- numeric response coderesponseMessage- human-readable response messagenode- JSON node to use as the response object, may be null- Returns:
- a GenericResponse instance populated with the given values
-
createResponseWithByteArray
public static GenericResponse createResponseWithByteArray(boolean result, int responseCode, String responseMessage, byte[] byteArray) Creates a GenericResponse populated with the provided success flag, response code, message, and byte array.- Parameters:
result- whether the response indicates successresponseCode- numeric response coderesponseMessage- human-readable response messagebyteArray- payload bytes to attach to the response- Returns:
- the populated GenericResponse with `responseCode`, `responseMessage`, `success`, and `responseBytes` set
-
hasShortCode
Checks whether any value in the provided map contains a placeholder of the form `${name}`.- Parameters:
map- the map whose values (converted to strings) will be scanned for placeholders- Returns:
- `true` if at least one value contains a placeholder matching `${name}`, `false` otherwise
-
hasShortCode
-
replacePlaceholders
-
replacePlaceholders
-
jsonStringToMap
public static Map<String,Object> jsonStringToMap(String jsonString) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
mapToJsonString
public static String mapToJsonString(Map<String, Object> mapObj) throws com.fasterxml.jackson.core.JsonProcessingException- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
isValidJson
-
convertIsoToDateString
-
convertStringToLocalDate
-
convertLocalDateToString
-
toJsonNode
public static com.fasterxml.jackson.databind.JsonNode toJsonNode(Object object) throws com.fasterxml.jackson.core.JsonProcessingException Converts any Java object into a JsonNode representation.- Parameters:
object- the Java object to convert- Returns:
- JSON representation of the object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
toPrimitiveOrDefaultFalse
Convert a Boolean reference to its primitive form, using a default value when the input is null.- Returns:
- `true` if the input is `Boolean.TRUE`, `false` if the input is `Boolean.FALSE` or `null`.
-
addMinutes
Return a new Date representing the given date plus the specified number of minutes.- Parameters:
date- the base date to adjustminutesToAdd- the number of minutes to add; may be negative to subtract minutes- Returns:
- the adjusted Date shifted by
minutesToAddminutes fromdate
-
getClaims
Extracts claims from a Jwt into a Map keyed by claim name.The returned map contains claim values using appropriate Java types: Strings, Integer, Long, Boolean, List
for JSON arrays, or JSONObject for JSON objects. - Parameters:
jwtObj- the Jwt to extract claims from; may be null- Returns:
- a map of claim names to claim values, empty if
jwtObjis null
-
toUrlEncodedString
Builds a UTF-8 URL-encoded query string from the provided parameters.- Parameters:
params- a map of parameter names to values; entries with a null value are omitted- Returns:
- a URL-encoded string of `key=value` pairs joined with `&`, encoded using UTF-8
-