- private static final String PACKAGE_ERROR = "mismatched input '{' expecting one of the following tokens: '[package";
- private static final String SUCCESS = "success";
-
- private PolicyUtils(){
- // Private Constructor
- }
- public static String objectToJsonString(Object o) throws JsonProcessingException{
- ObjectMapper mapper = new ObjectMapper();
- return mapper.writeValueAsString(o);
- }
-
- public static <T> T jsonStringToObject(String jsonString, Class<T> className) throws IOException{
- ObjectMapper mapper = new ObjectMapper();
- return mapper.readValue(jsonString, className);
- }
-
- public static String decode(String encodedString) throws UnsupportedEncodingException {
- if(encodedString!=null && !encodedString.isEmpty()){
- return new String(Base64.getDecoder().decode(encodedString) ,"UTF-8");
- }else{
- return null;
- }
- }
-
- public static String[] decodeBasicEncoding(String encodedValue) throws UnsupportedEncodingException {
- if(encodedValue!=null && encodedValue.contains("Basic ")){
- String encodedUserPassword = encodedValue.replaceFirst("Basic" + " ", "");
- String usernameAndPassword = null;
- byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword);
- usernameAndPassword = new String(decodedBytes, "UTF-8");
- StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
- String username = tokenizer.nextToken();
- String password = tokenizer.nextToken();
- return new String[]{username, password};
- }else{
- return new String[]{};
- }
- }
-
- public static String emptyPolicyValidator(String field){
+ private static final String PACKAGE_ERROR = "mismatched input '{' expecting one of the following tokens: '[package";
+ private static final String SUCCESS = "success";
+
+ private PolicyUtils(){
+ // Private Constructor
+ }
+
+ /**
+ * Converts an Object to JSON String
+ *
+ * @param o Object
+ * @return String format of Object JSON.
+ * @throws JsonProcessingException
+ */
+ public static String objectToJsonString(Object o) throws JsonProcessingException{
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.writeValueAsString(o);
+ }
+
+ /**
+ * Converts JSON string into Object
+ *
+ * @param jsonString
+ * @param className equivalent Class of the given JSON string
+ * @return T instance of the class given.
+ * @throws IOException
+ */
+ public static <T> T jsonStringToObject(String jsonString, Class<T> className) throws IOException{
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.readValue(jsonString, className);
+ }
+
+ /**
+ * Decode a base64 string
+ *
+ * @param encodedString
+ * @return String
+ * @throws UnsupportedEncodingException
+ */
+ public static String decode(String encodedString) throws UnsupportedEncodingException {
+ if(encodedString!=null && !encodedString.isEmpty()){
+ return new String(Base64.getDecoder().decode(encodedString) ,"UTF-8");
+ }else{
+ return null;
+ }
+ }
+
+ /**
+ * Decodes Basic Authentication
+ *
+ * @param encodedValue
+ * @return
+ * @throws UnsupportedEncodingException
+ */
+ public static String[] decodeBasicEncoding(String encodedValue) throws UnsupportedEncodingException {
+ if(encodedValue!=null && encodedValue.contains("Basic ")){
+ String encodedUserPassword = encodedValue.replaceFirst("Basic" + " ", "");
+ String usernameAndPassword = null;
+ byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword);
+ usernameAndPassword = new String(decodedBytes, "UTF-8");
+ StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
+ String username = tokenizer.nextToken();
+ String password = tokenizer.nextToken();
+ return new String[]{username, password};
+ }else{
+ return new String[]{};
+ }
+ }
+
+ /**
+ * Validate a field if contains space or unacceptable policy input and return "success" if good.
+ *
+ * @param field
+ * @return
+ */
+ public static String policySpecialCharValidator(String field){