diff options
Diffstat (limited to 'applications/common/src/main/java')
4 files changed, 35 insertions, 127 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java index e66c9943..e12f9f71 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -40,19 +40,12 @@ import com.att.research.xacmlatt.pdp.std.StdPolicyFinder; import com.att.research.xacmlatt.pdp.util.ATTPDPProperties; import com.google.common.base.Splitter; import com.google.common.base.Strings; - import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; import java.util.UUID; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,14 +116,6 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { } } - propLocation = this.properties.getProperty(policyId + PROP_URL); - if (propLocation != null) { - PolicyDef policy = this.loadPolicyUrlDef(propLocation); - if (policy != null) { - return policy; - } - } - logger.error("No known location for Policy {}", policyId); return null; } @@ -158,38 +143,6 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { } } - protected PolicyDef loadPolicyUrlDef(String propLocation) { - InputStream is = null; - try { - URL url = new URL(propLocation); - URLConnection urlConnection = url.openConnection(); - OnapPolicyFinderFactory.logger.info("Loading policy file {}", url); - is = urlConnection.getInputStream(); - PolicyDef policyDef = DOMPolicyDef.load(is); - if (policyDef != null) { - return policyDef; - } - } catch (MalformedURLException ex) { - logger.error("Invalid URL " + propLocation + ": " + ex.getMessage(), ex); - } catch (IOException ex) { - logger.error("IOException opening URL {}: {}{}", - propLocation, ex.getMessage(), ex); - } catch (DOMStructureException ex) { - logger.error("Invalid Policy " + propLocation + ": " + ex.getMessage(), ex); - return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage()); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - logger.error("Exception closing InputStream for GET of url {}: {}", - propLocation, e.getMessage() + " (May be memory leak)", e); - } - } - } - return null; - } - /** * Finds the identifiers for all of the policies referenced by the given property name in the * <code>XACMLProperties</code> and loads them using the requested loading method. diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java index 7304dfca..4bf87779 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -28,17 +28,11 @@ import com.att.research.xacml.api.pip.PIPResponse; import com.att.research.xacml.std.pip.StdMutablePIPResponse; import com.att.research.xacml.std.pip.StdPIPResponse; import com.google.common.base.Strings; - import java.sql.Timestamp; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Arrays; -import java.util.Base64; import java.util.Collection; -import java.util.Properties; - -import javax.persistence.Persistence; - import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.onap.policy.pdp.xacml.application.common.std.StdOnapPip; import org.slf4j.Logger; @@ -51,6 +45,7 @@ public class CountRecentOperationsPip extends StdOnapPip { public CountRecentOperationsPip() { super(); + this.issuer = ISSUER_NAME; } @Override @@ -58,38 +53,6 @@ public class CountRecentOperationsPip extends StdOnapPip { return Arrays.asList(PIP_REQUEST_ACTOR, PIP_REQUEST_RECIPE, PIP_REQUEST_TARGET); } - @Override - public void configure(String id, Properties properties) throws PIPException { - super.configure(id, properties); - // - // Create our entity manager - // - em = null; - try { - // - // In case there are any overloaded properties for the JPA - // - Properties emProperties = new Properties(); - emProperties.putAll(properties); - - // - // Need to decode the password before creating the EntityManager - // - String decodedPassword = new String(Base64.getDecoder() - .decode(emProperties.getProperty("javax.persistence.jdbc.password"))); - emProperties.setProperty("javax.persistence.jdbc.password", decodedPassword); - - // - // Create the entity manager factory - // - em = Persistence.createEntityManagerFactory( - properties.getProperty(ISSUER_NAME + ".persistenceunit"), - emProperties).createEntityManager(); - } catch (Exception e) { - logger.error("Persistence failed {} operations history db {}", e.getLocalizedMessage(), e); - } - } - /** * getAttributes. * diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java index 56d68d55..0f970f7e 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java @@ -16,7 +16,6 @@ * ============LICENSE_END========================================================= */ - package org.onap.policy.pdp.xacml.application.common.operationshistory; import com.att.research.xacml.api.XACML3; @@ -27,14 +26,9 @@ import com.att.research.xacml.api.pip.PIPResponse; import com.att.research.xacml.std.pip.StdMutablePIPResponse; import com.att.research.xacml.std.pip.StdPIPResponse; import com.google.common.base.Strings; - import java.util.Arrays; -import java.util.Base64; import java.util.Collection; -import java.util.Properties; import javax.persistence.NoResultException; -import javax.persistence.Persistence; - import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.onap.policy.pdp.xacml.application.common.std.StdOnapPip; import org.slf4j.Logger; @@ -47,6 +41,7 @@ public class GetOperationOutcomePip extends StdOnapPip { public GetOperationOutcomePip() { super(); + this.issuer = ISSUER_NAME; } @Override @@ -54,38 +49,6 @@ public class GetOperationOutcomePip extends StdOnapPip { return Arrays.asList(PIP_REQUEST_TARGET); } - @Override - public void configure(String id, Properties properties) throws PIPException { - super.configure(id, properties); - // - // Create our entity manager - // - em = null; - try { - // - // In case there are any overloaded properties for the JPA - // - Properties emProperties = new Properties(); - emProperties.putAll(properties); - - // - // Need to decode the password before creating the EntityManager - // - String decodedPassword = new String(Base64.getDecoder() - .decode(emProperties.getProperty("javax.persistence.jdbc.password"))); - emProperties.setProperty("javax.persistence.jdbc.password", decodedPassword); - - // - // Create the entity manager factory - // - em = Persistence.createEntityManagerFactory( - properties.getProperty(ISSUER_NAME + ".persistenceunit"), - emProperties).createEntityManager(); - } catch (Exception e) { - logger.error("Persistence failed {} operations history db {}", e.getLocalizedMessage(), e); - } - } - /** * getAttributes. * diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java index 69838599..4ef71b3d 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -36,13 +36,14 @@ import com.att.research.xacml.std.pip.StdPIPRequest; import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; import java.math.BigInteger; +import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.Properties; import javax.persistence.EntityManager; - +import javax.persistence.Persistence; import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,6 +69,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { protected Properties properties; protected EntityManager em; + protected String issuer; public StdOnapPip() { super(); @@ -83,6 +85,33 @@ public abstract class StdOnapPip extends StdConfigurableEngine { super.configure(id, properties); logger.info("Configuring historyDb PIP {}", properties); this.properties = properties; + // + // Create our entity manager + // + em = null; + try { + // + // In case there are any overloaded properties for the JPA + // + Properties emProperties = new Properties(); + emProperties.putAll(properties); + + // + // Need to decode the password before creating the EntityManager + // + String decodedPassword = new String(Base64.getDecoder() + .decode(emProperties.getProperty("javax.persistence.jdbc.password"))); + emProperties.setProperty("javax.persistence.jdbc.password", decodedPassword); + + // + // Create the entity manager factory + // + em = Persistence.createEntityManagerFactory( + properties.getProperty(this.issuer + ".persistenceunit"), + emProperties).createEntityManager(); + } catch (Exception e) { + logger.error("Persistence failed {} operations history db {}", e.getLocalizedMessage(), e); + } } protected String getAttribute(PIPFinder pipFinder, PIPRequest pipRequest) { |