2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.aaf.filters;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.Properties;
29 import javax.annotation.PostConstruct;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.context.annotation.Profile;
36 import org.springframework.stereotype.Component;
38 // This component will be created if and only if any of the following profiles are active
40 @Profile({AafProfiles.AAF_CERT_AUTHENTICATION, AafProfiles.AAF_AUTHENTICATION, AafProfiles.TWO_WAY_SSL})
41 public class CadiProps {
43 private static final Logger LOGGER = LoggerFactory.getLogger(CadiProps.class);
45 private String cadiFileName;
47 private Properties cadiProperties;
50 public CadiProps(@Value("${aaf.cadi.file:./resources/cadi.properties}") String filename) {
51 cadiFileName = filename;
52 cadiProperties = new Properties();
56 public void init() throws IOException {
58 File cadiFile = new File(cadiFileName);
60 if (!cadiFile.exists()) {
61 LOGGER.warn("Unable to find the cadi file in the given path {} so loading cadi.properties from classloader",
63 InputStream is = this.getClass().getClassLoader().getResourceAsStream("cadi.properties");
64 cadiProperties.load(is);
66 LOGGER.info("Successfully found the file {} and started loading the properties from it", cadiFileName);
67 cadiFileName = cadiFile.getAbsolutePath();
68 try (InputStream inputStream = new FileInputStream(cadiFile)) {
69 cadiProperties.load(inputStream);
75 public String getCadiFileName() {
79 public Properties getCadiProperties() {
80 return cadiProperties;