aboutsummaryrefslogtreecommitdiffstats
path: root/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization
diff options
context:
space:
mode:
Diffstat (limited to 'PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization')
-rw-r--r--PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java80
-rw-r--r--PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java232
-rw-r--r--PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java300
3 files changed, 612 insertions, 0 deletions
diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java
new file mode 100644
index 000000000..c5526d753
--- /dev/null
+++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.pypdp.authorization;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@WebFilter("/*")
+public class AuthenticationFilter implements Filter {
+
+ public static final String AUTHENTICATION_HEADER = "Authorization";
+ public static final String ENVIRONMENT_HEADER = "Environment";
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain filter) throws IOException, ServletException {
+ if (request instanceof HttpServletRequest) {
+ HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+ String authCredentials = httpServletRequest.getHeader(AUTHENTICATION_HEADER);
+ String environment = httpServletRequest.getHeader(ENVIRONMENT_HEADER);
+ String path = ((HttpServletRequest) request).getRequestURI();
+
+ // better injected
+ AuthenticationService authenticationService = new AuthenticationService();
+
+ boolean authenticationStatus = authenticationService.authenticate(authCredentials);
+
+ if (authenticationStatus && environment!=null && (environment.equalsIgnoreCase(Config.getEnvironment()))) {
+ filter.doFilter(request, response);
+ } else if(environment==null| path.contains("org.openecomp.policy.pypdp.notifications") || path.contains("swagger") || path.contains("api-docs") || path.contains("configuration") || path.contains("pdps") || path.contains("count") || path.contains("paps")){
+ filter.doFilter(request, response);
+ } else {
+ if (response instanceof HttpServletResponse) {
+ HttpServletResponse httpServletResponse = (HttpServletResponse) response;
+ httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ }
+ }
+ if (path.contains("error")){
+ HttpServletResponse httpServletResponse = (HttpServletResponse) response;
+ httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ }
+ }
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ @Override
+ public void init(FilterConfig arg0) throws ServletException {
+ Config.setProperty();
+ }
+}
diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java
new file mode 100644
index 000000000..c7deac910
--- /dev/null
+++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java
@@ -0,0 +1,232 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.pypdp.authorization;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openecomp.policy.common.logging.eelf.MessageCodes;
+import org.openecomp.policy.common.logging.eelf.PolicyLogger;
+
+import org.openecomp.policy.xacml.api.XACMLErrorConstants;
+
+public class AuthenticationService {
+ private String pyPDPID = Config.getPYPDPID();
+ private String pyPDPPass = Config.getPYPDPPass();
+ private static Path clientPath = null;
+ private static HashMap<String, ArrayList<String>> clientMap = null;
+ private static Long oldModified = null;
+ private static Long newModified = null;
+ private static final Log logger = LogFactory.getLog(AuthenticationService.class);
+
+ public boolean authenticate(String authCredentials) {
+
+ if (null == authCredentials)
+ return false;
+ // header value format will be "Basic encodedstring" for Basic authentication.
+ final String encodedUserPassword = authCredentials.replaceFirst("Basic" + " ", "");
+ String usernameAndPassword = null;
+ try {
+ byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword);
+ usernameAndPassword = new String(decodedBytes, "UTF-8");
+ } catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "");
+ return false;
+ }
+ try {
+ final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
+ final String username = tokenizer.nextToken();
+ final String password = tokenizer.nextToken();
+
+ boolean authenticationStatus = pyPDPID.equals(username) && pyPDPPass.equals(password);
+ return authenticationStatus;
+ } catch (Exception e){
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "");
+ return false;
+ }
+ }
+
+ public static boolean clientAuth(String clientCredentials) {
+ if(clientCredentials == null){
+ return false;
+ }
+ // Decode the encoded Client Credentials.
+ String usernameAndPassword = null;
+ try {
+ byte[] decodedBytes = Base64.getDecoder().decode(clientCredentials);
+ usernameAndPassword = new String(decodedBytes, "UTF-8");
+ } catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "");
+ return false;
+ }
+ try {
+ final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
+ final String username = tokenizer.nextToken();
+ final String password = tokenizer.nextToken();
+ return checkClient(username,password);
+ } catch(Exception e){
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "");
+ return false;
+ }
+ }
+
+ public static boolean checkClientScope(String clientCredentials, String scope) {
+ if(clientCredentials == null){
+ return false;
+ }
+ // Decode the encoded Client Credentials.
+ String usernameAndPassword = null;
+ try {
+ byte[] decodedBytes = Base64.getDecoder().decode(clientCredentials);
+ usernameAndPassword = new String(decodedBytes, "UTF-8");
+ } catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "");
+ return false;
+ }
+ final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
+ final String username = tokenizer.nextToken();
+ // Read the properties and compare.
+ try{
+ readFile();
+ }catch(Exception e){
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "");
+ return false;
+ }
+ // Check ID, Scope
+ if (clientMap.containsKey(username) && (clientMap.get(username).get(1).equals(scope) || clientMap.get(username).get(1).equals("MASTER"))) {
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean checkClient(String username, String password) {
+ // Read the properties and compare.
+ try{
+ readFile();
+ }catch(Exception e){
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "");
+ return false;
+ }
+ // Check ID, Key
+ if (clientMap.containsKey(username) && clientMap.get(username).get(0).equals(password)) {
+ return true;
+ }
+ return false;
+ }
+
+ private static void readFile() throws Exception {
+ String clientFile = Config.getClientFile();
+ if (clientFile == null) {
+ Config.setProperty();
+ if(clientFile == null){
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Missing CLIENT_FILE property value: " + clientFile);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "Missing CLIENT_FILE property value: " + clientFile);
+ throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Missing CLIENT_FILE property value: " + clientFile);
+ }
+ }
+ if (clientPath == null) {
+ clientPath = Paths.get(clientFile);
+ if (Files.notExists(clientPath)) {
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path : " + clientPath.toString());
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "File doesn't exist in the specified Path : " + clientPath.toString());
+ throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"File doesn't exist in the specified Path : "+ clientPath.toString());
+ }
+ if (clientPath.toString().endsWith(".properties")) {
+ readProps();
+ } else {
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + clientFile);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "Not a .properties file " + clientFile);
+ throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file " + clientFile);
+ }
+ }
+ // Check if File is updated recently
+ else {
+ newModified = clientPath.toFile().lastModified();
+ if (newModified != oldModified) {
+ // File has been updated.
+ readProps();
+ }
+ }
+ }
+
+ private static void readProps() throws Exception{
+ InputStream in;
+ Properties clientProp = new Properties();
+ try {
+ in = new FileInputStream(clientPath.toFile());
+ oldModified = clientPath.toFile().lastModified();
+ clientProp.load(in);
+ } catch (IOException e) {
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "");
+ throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Load the Properties file", e);
+
+ }
+ // Read the Properties and Load the PDPs and encoding.
+ clientMap = new HashMap<String, ArrayList<String>>();
+ //
+ for (Object propKey : clientProp.keySet()) {
+ String clientID = (String)propKey;
+ String clientValue = clientProp.getProperty(clientID);
+ if (clientValue != null) {
+ if (clientValue.contains(",")) {
+ ArrayList<String> clientValues = new ArrayList<String>(Arrays.asList(clientValue.split("\\s*,\\s*")));
+ if(clientValues.get(0)!=null || clientValues.get(1)!=null || clientValues.get(0).isEmpty() || clientValues.get(1).isEmpty()){
+ clientMap.put(clientID, clientValues);
+ }
+ }
+ }
+ }
+ if (clientMap == null || clientMap.isEmpty()) {
+ logger.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "No Clients ID , Client Key and Scopes are available. Cannot serve any Clients !!");
+ }
+ }
+}
diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java
new file mode 100644
index 000000000..388909ecf
--- /dev/null
+++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java
@@ -0,0 +1,300 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.pypdp.authorization;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openecomp.policy.common.logging.eelf.MessageCodes;
+import org.openecomp.policy.common.logging.eelf.PolicyLogger;
+
+import org.openecomp.policy.xacml.api.XACMLErrorConstants;
+
+import org.openecomp.policy.common.im.IntegrityMonitor;
+
+
+public class Config {
+ private static final String propertyFilePath = "config.properties";
+ private static Properties prop = new Properties();
+ private static List<String> pdps = null;
+ private static List<String> paps = null;
+ private static List<String> encoding = null;
+ private static List<String> encodingPAP = null;
+ private static String pyPDPPass = null;
+ private static String pyPDPID = null;
+ private static String environment = null;
+ private static final Log logger = LogFactory.getLog(Config.class);
+ private static String clientFile = null;
+ private static boolean test = false;
+
+ private static IntegrityMonitor im;
+ private static String resourceName = null;
+
+ public static String getProperty(String propertyKey) {
+ return prop.getProperty(propertyKey);
+ }
+
+ /*
+ * Set Property by reading the properties File.
+ */
+ public static void setProperty() {
+ Path file = Paths.get(propertyFilePath);
+ if (Files.notExists(file)) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+ "File doesn't exist in the specified Path "+ file.toString());
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "File doesn't exist in the specified Path "+ file.toString());
+ } else {
+ InputStream in;
+ prop = new Properties();
+ try {
+ in = new FileInputStream(file.toFile());
+ prop.load(in);
+ } catch (IOException e) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Cannot Load the Properties file" + e);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "Cannot Load the Properties file");
+ }
+ }
+ // Initializing the values.
+ pdps = new ArrayList<String>();
+ paps = new ArrayList<String>();
+ encoding = new ArrayList<String>();
+ encodingPAP = new ArrayList<String>();
+
+ // Check the Keys for PDP_URLs
+ Collection<Object> unsorted = prop.keySet();
+ List<String> sorted = new ArrayList(unsorted);
+ Collections.sort(sorted);
+ for (String propKey : sorted) {
+ if (propKey.startsWith("PDP_URL")) {
+ String check_val = prop.getProperty(propKey);
+ logger.debug("Property file value for Key : \"" + propKey + "\" Value is : \"" + check_val + "\"");
+ if (check_val == null) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have the PDP_URL parameter");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have the PDP_URL parameter");
+ }
+ if (check_val.contains(";")) {
+ List<String> pdp_default = new ArrayList<String>(Arrays.asList(check_val.split("\\s*;\\s*")));
+ int pdpCount = 0;
+ while (pdpCount < pdp_default.size()) {
+ String pdpVal = pdp_default.get(pdpCount);
+ readPDPParam(pdpVal);
+ pdpCount++;
+ }
+ } else {
+ readPDPParam(check_val);
+ }
+ } else if (propKey.startsWith("PAP_URL")) {
+ String check_val = prop.getProperty(propKey);
+ logger.debug("Property file value for Key : \"" + propKey + "\" Value is : \"" + check_val + "\"");
+ if (check_val == null) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have the PAP_URL parameter");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have the PAP_URL parameter");
+ }
+ if (check_val.contains(";")) {
+ List<String> pap_default = new ArrayList<String>(Arrays.asList(check_val.split("\\s*;\\s*")));
+ int papCount=0;
+ while (papCount < pap_default.size()) {
+ String papVal = pap_default.get(papCount);
+ readPAPParam(papVal);
+ papCount++;
+ }
+ } else {
+ readPAPParam(check_val);
+ }
+ }
+ }
+ if (pdps == null || pdps.isEmpty()) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Cannot Proceed without PDP_URLs");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Cannot Proceed without PDP_URLs");
+ }
+
+ if (prop.containsKey("PYPDP_ID")) {
+ String id = prop.getProperty("PYPDP_ID");
+ logger.debug("Property file value key: \"PYPDP_ID\" Value is : \"" + id + "\"");
+ if (id == null) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_ID parameter");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_ID parameter");
+ }
+ Config.pyPDPID = id;
+ } else {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_ID parameter");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_ID parameter");
+ }
+ if (prop.containsKey("PYPDP_PASSWORD")) {
+ String pass = prop.getProperty("PYPDP_PASSWORD");
+ logger.debug("Property file value key: \"PYPDP_PASSWORD\" Value is : \"" + pass + "\"");
+ if (pass == null) {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_PASSWORD parameter");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_PASSWORD parameter");
+ }
+ Config.pyPDPPass = pass;
+ } else {
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_PASSWORD parameter");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_PASSWORD parameter");
+ }
+ environment = prop.getProperty("ENVIRONMENT", "DEVL");
+ logger.info("Property value for Environment " + environment);
+ String value = prop.getProperty("Test");
+ if(value!= null && value.equalsIgnoreCase("true")){
+ test = true;
+ }
+ if(prop.containsKey("CLIENT_FILE")){
+ clientFile = prop.getProperty("CLIENT_FILE");
+ logger.debug("Property file value key: \"CLIENT_FILE\" Value is : \"" + clientFile + "\"");
+ if(clientFile == null){
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"CLIENT_FILE value is missing.");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "CLIENT_FILE value is missing.");
+ }
+ }else{
+ logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"CLIENT_FILE paramter is missing from the property file.");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "CLIENT_FILE paramter is missing from the property file.");
+ }
+ logger.info("Trying to set up IntegrityMonitor");
+ try {
+ logger.info("Trying to set up IntegrityMonitor");
+ resourceName = prop.getProperty("RESOURCE_NAME").replaceAll(" ", "");;
+ if(resourceName==null){
+ logger.warn("RESOURCE_NAME is missing setting default value. ");
+ resourceName = "pypdp_pdp01";
+ }
+ im = IntegrityMonitor.getInstance(resourceName, prop);
+ } catch (Exception e) {
+ logger.error("Error starting Integerity Monitor: " + e);
+ }
+ }
+
+ private static void readPDPParam(String pdpVal) {
+ if (pdpVal.contains(",")) {
+ List<String> pdpValues = new ArrayList<String>(Arrays.asList(pdpVal.split("\\s*,\\s*")));
+ if (pdpValues.size() == 3) {
+ // 0 - PDPURL
+ pdps.add(pdpValues.get(0));
+ // 1:2 will be UserID:Password
+ String userID = pdpValues.get(1);
+ String pass = pdpValues.get(2);
+ Base64.Encoder encoder = Base64.getEncoder();
+ encoding.add(encoder.encodeToString((userID + ":" + pass)
+ .getBytes(StandardCharsets.UTF_8)));
+ } else {
+ logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"No enough Credentials to send Request. "+ pdpValues);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No enough Credentials to send Request. "+ pdpValues);
+ }
+ } else {
+ logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"No enough Credentials to send Request.");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No enough Credentials to send Request.");
+ }
+ }
+
+ private static void readPAPParam(String papVal) {
+ if (papVal.contains(",")) {
+ List<String> papValues = new ArrayList<String>(Arrays.asList(papVal.split("\\s*,\\s*")));
+ if (papValues.size() == 3) {
+ // 0 - PAPURL
+ paps.add(papValues.get(0));
+ // 1:2 will be UserID:Password
+ String userID = papValues.get(1);
+ String pass = papValues.get(2);
+ Base64.Encoder encoder = Base64.getEncoder();
+ encodingPAP.add(encoder.encodeToString((userID + ":" + pass)
+ .getBytes(StandardCharsets.UTF_8)));
+ } else {
+ logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"Not enough Credentials to send Request. "+ papValues);
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS, "Not enough Credentials to send Request. "+ papValues);
+ }
+ } else {
+ logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"Not enough Credentials to send Request.");
+ // TODO:EELF Cleanup - Remove logger
+ PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS, "Not enough Credentials to send Request.");
+ }
+ }
+
+ public static List<String> getPDPs() {
+ setProperty();
+ return Config.pdps;
+ }
+
+ public static List<String> getPAPs() {
+ setProperty();
+ return Config.paps;
+ }
+
+ public static List<String> getEncoding() {
+ return Config.encoding;
+ }
+
+ public static List<String> getEncodingPAP() {
+ return Config.encodingPAP;
+ }
+
+ public static String getPYPDPID() {
+ return Config.pyPDPID;
+ }
+
+ public static String getPYPDPPass() {
+ return Config.pyPDPPass;
+ }
+
+ public static String getEnvironment(){
+ return Config.environment;
+ }
+
+ public static IntegrityMonitor getIntegrityMonitor(){
+ if(im==null){
+ setProperty();
+ }
+ return im;
+ }
+
+ public static String getClientFile() {
+ return Config.clientFile;
+ }
+
+ public static Boolean isTest() {
+ return Config.test;
+ }
+}