Resolved Fortify System Information Leak issues
[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                         synchronized(this) {
50                                 if (pipFinder == null) {
51                                         if (LOGGER.isDebugEnabled()) {
52                                                 LOGGER.debug("Creating default configurable engine finder");
53                                         }
54                                         pipFinder = new ConfigurableEngineFinder();
55                                         Properties xacmlProperties      = null;
56                                         try {
57                                                 xacmlProperties = XACMLProperties.getProperties();
58                                         } catch (Exception ex) {
59                                                 LOGGER.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR+ "Exception getting XACML properties: " + ex.getMessage(), ex);
60                                                 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, ex, "Exception getting XACML properties");
61                                                 return null;
62                                         }
63                                         if (xacmlProperties != null) {
64                                                 ((ConfigurableEngineFinder)pipFinder).configure(xacmlProperties);
65                                         }
66                                 }
67                         }
68                 return pipFinder;
69         }
70
71         @Override
72         public PIPFinder getFinder(Properties properties) throws PIPException {
73                 synchronized(this) {
74                         if (pipFinder == null) {
75                                 if (LOGGER.isDebugEnabled()) {
76                                                 LOGGER.debug("Creating configurable engine finder using: " + properties);
77                                 }
78                                 pipFinder = new ConfigurableEngineFinder();
79                                 ((ConfigurableEngineFinder)pipFinder).configure(properties);
80                         }
81                 }
82                 return this.pipFinder;
83         }
84 }