* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.xml.XMLConstants;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class PolicyUtils {
private static final Logger LOGGER = FlexLogger.getLogger(PolicyUtils.class);
-
+ public static final String CATCH_EXCEPTION = "PE500: An exception was caught.";
public static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private static final String PACKAGE_ERROR = "mismatched input '{' expecting one of the following tokens: '[package";
- private static final String SUCCESS = "success";
+ public static final String SUCCESS = "success";
private PolicyUtils(){
// Private Constructor
public static String[] decodeBasicEncoding(String encodedValue) throws UnsupportedEncodingException {
if(encodedValue!=null && encodedValue.contains("Basic ")){
String encodedUserPassword = encodedValue.replaceFirst("Basic" + " ", "");
- String usernameAndPassword = null;
+ String usernameAndPassword;
byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword);
usernameAndPassword = new String(decodedBytes, "UTF-8");
StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
return SUCCESS;
}
+ /**
+ * Validate a field (accepts Dash) if it contains unacceptable policy input and return "success" if good.
+ *
+ * @param field
+ * @return
+ */
+ public static String policySpecialCharWithDashValidator(String field){
+ String error;
+ if ("".equals(field) || !field.matches("^[a-zA-Z0-9_-]*$")) {
+ error = "The Value in Required Field will allow only '{0-9}, {a-z}, {A-Z}, _, -' following set of Combinations";
+ return error;
+ }
+ return SUCCESS;
+ }
+
/**
* Validate the XACML description tag and return "success" if good.
*
return false;
}
for (char c : number.toCharArray()){
- if (!Character.isDigit(c)) return false;
+ if (!Character.isDigit(c)) {
+ return false;
+ }
}
return true;
}
* @return
*/
public static boolean isXMLValid(String data) {
+ if(data == null || data.isEmpty()){
+ return false;
+ }
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
- try {
+
+ try {
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setErrorHandler(new XMLErrorHandler());