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