Class CommonUtils

java.lang.Object
io.jans.ca.plugin.adminui.utils.CommonUtils

public class CommonUtils extends Object
  • Field Details

  • Constructor Details

    • CommonUtils

      public CommonUtils()
  • Method Details

    • joinAndUrlEncode

      public static String joinAndUrlEncode(Collection<String> list) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • encode

      public static String encode(String str) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • getFormattedDate

      public static String getFormattedDate()
    • loadPrivateKey

      public static RSAPrivateKey loadPrivateKey(String privateKeyPEM) throws Exception
      Throws:
      Exception
    • decode

      public static String decode(String toDecode) throws UnsupportedEncodingException
      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 successful
      responseCode - numeric response code
      responseMessage - human-readable response message
      node - 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 success
      responseCode - numeric response code
      responseMessage - human-readable response message
      byteArray - payload bytes to attach to the response
      Returns:
      the populated GenericResponse with `responseCode`, `responseMessage`, `success`, and `responseBytes` set
    • hasShortCode

      public static boolean hasShortCode(Map<String,?> map)
      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

      public static boolean hasShortCode(String input)
    • replacePlaceholders

      public static Map<String,Object> replacePlaceholders(Map<String,Object> map, Map<String,Object> placeholderValues)
    • replacePlaceholders

      public static String replacePlaceholders(String url, Map<String,Object> placeholderValues)
    • 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

      public static boolean isValidJson(String json)
    • convertIsoToDateString

      public static String convertIsoToDateString(String isoDateTime)
    • convertStringToLocalDate

      public static LocalDate convertStringToLocalDate(String dateString)
    • convertLocalDateToString

      public static String convertLocalDateToString(LocalDate date)
    • 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

      public static boolean toPrimitiveOrDefaultFalse(Boolean booleanObject)
      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

      public static Date addMinutes(Date date, int minutesToAdd)
      Return a new Date representing the given date plus the specified number of minutes.
      Parameters:
      date - the base date to adjust
      minutesToAdd - the number of minutes to add; may be negative to subtract minutes
      Returns:
      the adjusted Date shifted by minutesToAdd minutes from date
    • getClaims

      public static Map<String,Object> getClaims(io.jans.as.model.jwt.Jwt jwtObj)
      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 jwtObj is null
    • toUrlEncodedString

      public static String toUrlEncodedString(Map<String,String> params)
      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