[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / ONAP-PDP-REST / src / main / java / org / onap / policy / pdp / rest / impl / XACMLPdpPIPFinderFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.policy.pdp.rest.impl;
21
22 import java.util.Properties;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.onap.policy.common.logging.eelf.MessageCodes;
27 import org.onap.policy.common.logging.eelf.PolicyLogger;
28
29 import org.onap.policy.xacml.api.XACMLErrorConstants;
30 import com.att.research.xacml.api.pip.PIPException;
31 import com.att.research.xacml.api.pip.PIPFinder;
32 import com.att.research.xacml.api.pip.PIPFinderFactory;
33 import com.att.research.xacml.std.pip.finders.ConfigurableEngineFinder;
34 import com.att.research.xacml.util.XACMLProperties;
35
36 public class XACMLPdpPIPFinderFactory extends PIPFinderFactory {
37         private ConfigurableEngineFinder pipFinder;
38         
39         private static Log LOGGER       = LogFactory.getLog(XACMLPdpPIPFinderFactory.class);
40         
41         public XACMLPdpPIPFinderFactory() {
42         }
43
44         public XACMLPdpPIPFinderFactory(Properties properties) {
45         }
46
47         @Override
48         public PIPFinder getFinder() throws PIPException {
49                 if (pipFinder == null) {
50                         synchronized(this) {
51                                 if (pipFinder == null) {
52                                         if (LOGGER.isDebugEnabled()) {
53                                                 LOGGER.debug("Creating default configurable engine finder");
54                                         }
55                                         pipFinder                                       = new ConfigurableEngineFinder();
56                                         Properties xacmlProperties      = null;
57                                         try {
58                                                 xacmlProperties = XACMLProperties.getProperties();
59                                         } catch (Exception ex) {
60                                                 LOGGER.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR+ "Exception getting XACML properties: " + ex.getMessage(), ex);
61                                                 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, ex, "Exception getting XACML properties");
62                                                 return null;
63                                         }
64                                         if (xacmlProperties != null) {
65                                                 ((ConfigurableEngineFinder)pipFinder).configure(xacmlProperties);
66                                         }
67                                 }
68                         }
69                 }
70                 return pipFinder;
71         }
72
73         @Override
74         public PIPFinder getFinder(Properties properties) throws PIPException {
75                 if (pipFinder == null) {
76                         synchronized(this) {
77                                 if (pipFinder == null) {
78                                         if (LOGGER.isDebugEnabled()) {
79                                                 LOGGER.debug("Creating configurable engine finder using: " + properties);
80                                         }
81                                         pipFinder                                       = new ConfigurableEngineFinder();
82                                         ((ConfigurableEngineFinder)pipFinder).configure(properties);
83                                 }
84                         }
85                 }
86                 return this.pipFinder;
87         }
88 }