summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dmaap/dmf/mr/beans/DMaaPNsaApiDb.java
blob: 88ae8ae4754d653e52a227f9e8e8ab346ebbea91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*******************************************************************************
 *  ============LICENSE_START=======================================================
 *  org.onap.dmaap
 *  ================================================================================
 *  Copyright © 2017 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.
 *  You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
*  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  ============LICENSE_END=========================================================
 *  
 *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
 *  
 *******************************************************************************/
package org.onap.dmaap.dmf.mr.beans;

import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.nsa.configs.ConfigDb;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.configs.confimpl.EncryptingLayer;
import com.att.nsa.drumlin.till.nv.rrNvReadable;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.security.db.BaseNsaApiDbImpl;
import com.att.nsa.security.db.EncryptingApiDbImpl;
import com.att.nsa.security.db.NsaApiDb;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
import com.att.nsa.security.db.simple.NsaSimpleApiKeyFactory;
import com.att.nsa.util.rrConvertor;
import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
import org.springframework.beans.factory.annotation.Autowired;

import java.security.Key;

/**
 * 
 * @author anowarul.islam
 *
 */
public class DMaaPNsaApiDb {
	
	
	private DMaaPZkConfigDb cdb;
	
	//private static final Logger log = Logger
		
	private static final EELFLogger log = EELFManager.getInstance().getLogger(DMaaPNsaApiDb.class);
	
/**
 * 
 * Constructor initialized
 * @param settings
 * @param cdb
 */
	@Autowired
	public DMaaPNsaApiDb(rrNvReadable settings, DMaaPZkConfigDb cdb) {
		
		this.setCdb(cdb);
	}
	/**
	 * 
	 * @param settings
	 * @param cdb
	 * @return
	 * @throws ConfigDbException
	 * @throws missingReqdSetting
	 */
	public static NsaApiDb<NsaSimpleApiKey> buildApiKeyDb(
			rrNvReadable settings, ConfigDb cdb) throws ConfigDbException,
			missingReqdSetting {
		// Cambria uses an encrypted api key db

		
		final String keyBase64 =com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,"cambria.secureConfig.key");
		
		
	
	final String initVectorBase64 =com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,"cambria.secureConfig.iv");
		// if neither value was provided, don't encrypt api key db
		if (keyBase64 == null && initVectorBase64 == null) {
			log.info("This server is configured to use an unencrypted API key database. See the settings documentation.");
			return new BaseNsaApiDbImpl<>(cdb,
					new NsaSimpleApiKeyFactory());
		} else if (keyBase64 == null) {
			// neither or both, otherwise something's goofed
			throw new missingReqdSetting("cambria.secureConfig.key");
		} else if (initVectorBase64 == null) {
			// neither or both, otherwise something's goofed
			throw new missingReqdSetting("cambria.secureConfig.iv");
		} else {
			log.info("This server is configured to use an encrypted API key database.");
			final Key key = EncryptingLayer.readSecretKey(keyBase64);
			final byte[] iv = rrConvertor.base64Decode(initVectorBase64);
			return new EncryptingApiDbImpl<>(cdb,
					new NsaSimpleApiKeyFactory(), key, iv);
		}
	}

	/**
	 * @return
	 * returns settings
	 */

		
	

	/**
	 * @param settings
	 * set settings
	 */
	
		
	

	 /**
	 * @return
	 * returns cbd
	 */
	public DMaaPZkConfigDb getCdb() {
		return cdb;
	}
	/**
	 * @param cdb
	 * set cdb
	 */
	public void setCdb(DMaaPZkConfigDb cdb) {
		this.cdb = cdb;
	}


}