summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dmaap/dmf/mr/utils/ConfigurationReader.java
blob: 5688dccbde9a51ab3a51a97db115c5715e8e0019 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/*******************************************************************************
 *  ============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.utils;

import javax.servlet.ServletException;

import org.I0Itec.zkclient.ZkClient;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import org.onap.dmaap.dmf.mr.backends.ConsumerFactory;
import org.onap.dmaap.dmf.mr.backends.MetricsSet;
import org.onap.dmaap.dmf.mr.backends.Publisher;
import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache.KafkaConsumerCacheException;
import org.onap.dmaap.dmf.mr.backends.memory.MemoryConsumerFactory;
import org.onap.dmaap.dmf.mr.backends.memory.MemoryMetaBroker;
import org.onap.dmaap.dmf.mr.backends.memory.MemoryQueue;
import org.onap.dmaap.dmf.mr.backends.memory.MemoryQueuePublisher;
import org.onap.dmaap.dmf.mr.beans.DMaaPCambriaLimiter;
import org.onap.dmaap.dmf.mr.beans.DMaaPZkConfigDb;
import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
import org.onap.dmaap.dmf.mr.metabroker.Broker;

import org.onap.dmaap.dmf.mr.metabroker.Broker1;
import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
import org.onap.dmaap.dmf.mr.security.impl.DMaaPOriginalUebAuthenticator;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.configs.confimpl.MemConfigDb;
import com.att.nsa.drumlin.till.nv.rrNvReadable;
import com.att.nsa.drumlin.till.nv.rrNvReadable.invalidSettingValue;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.limits.Blacklist;
import com.att.nsa.security.NsaAuthenticatorService;

import com.att.nsa.security.db.BaseNsaApiDbImpl;
import com.att.nsa.security.db.NsaApiDb;
import com.att.nsa.security.db.NsaApiDb.KeyExistsException;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
import com.att.nsa.security.db.simple.NsaSimpleApiKeyFactory;

/**
 * Class is created for all the configuration for rest and service layer
 * integration.
 *
 */
@Component
public class ConfigurationReader {


	private Broker1 fMetaBroker;
	private ConsumerFactory fConsumerFactory;
	private Publisher fPublisher;
	private MetricsSet fMetrics;
	@Autowired
	private DMaaPCambriaLimiter fRateLimiter;
	private NsaApiDb<NsaSimpleApiKey> fApiKeyDb;
	
	private DMaaPAuthenticator<NsaSimpleApiKey> fSecurityManager;
	private NsaAuthenticatorService<NsaSimpleApiKey> nsaSecurityManager;
	private static CuratorFramework curator;
	private ZkClient zk;
	private DMaaPZkConfigDb fConfigDb;
	private MemoryQueue q;
	private MemoryMetaBroker mmb;
	private Blacklist fIpBlackList;
	private Emailer fEmailer;

	private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigurationReader.class);
	

	/**
	 * constructor to initialize all the values
	 * 
	 * @param settings
	 * @param fMetrics
	 * @param zk
	 * @param fConfigDb
	 * @param fPublisher
	 * @param curator
	 * @param fConsumerFactory
	 * @param fMetaBroker
	 * @param q
	 * @param mmb
	 * @param fApiKeyDb
	 * @param fSecurityManager
	 * @throws missingReqdSetting
	 * @throws invalidSettingValue
	 * @throws ServletException
	 * @throws KafkaConsumerCacheException
	 * @throws ConfigDbException 
	 * @throws KeyExistsException 
	 */
	@Autowired
	public ConfigurationReader(@Qualifier("propertyReader") rrNvReadable settings,
			@Qualifier("dMaaPMetricsSet") MetricsSet fMetrics, @Qualifier("dMaaPZkClient") ZkClient zk,
			@Qualifier("dMaaPZkConfigDb") DMaaPZkConfigDb fConfigDb, @Qualifier("kafkaPublisher") Publisher fPublisher,
			@Qualifier("curator") CuratorFramework curator,
			@Qualifier("dMaaPKafkaConsumerFactory") ConsumerFactory fConsumerFactory,
			@Qualifier("dMaaPKafkaMetaBroker") Broker1 fMetaBroker,
			@Qualifier("q") MemoryQueue q,
			@Qualifier("mmb") MemoryMetaBroker mmb, @Qualifier("dMaaPNsaApiDb") NsaApiDb<NsaSimpleApiKey> fApiKeyDb,
			/*
			 * @Qualifier("dMaaPTranDb")
			 * DMaaPTransactionObjDB<DMaaPTransactionObj> fTranDb,
			 */
			@Qualifier("dMaaPAuthenticatorImpl") DMaaPAuthenticator<NsaSimpleApiKey> fSecurityManager
			)
					throws missingReqdSetting, invalidSettingValue, ServletException, KafkaConsumerCacheException, ConfigDbException, KeyExistsException {
		
		this.fMetrics = fMetrics;
		this.zk = zk;
		this.fConfigDb = fConfigDb;
		this.fPublisher = fPublisher;
		ConfigurationReader.curator = curator;
		this.fConsumerFactory = fConsumerFactory;
		this.fMetaBroker = fMetaBroker;
		
		this.q = q;
		this.mmb = mmb;
		this.fApiKeyDb = fApiKeyDb;
		
		this.fSecurityManager = fSecurityManager;
		
		long allowedtimeSkewMs=600000L;
		String strallowedTimeSkewM= com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,"authentication.allowedTimeSkewMs");
		if(null!=strallowedTimeSkewM)
		{
			allowedtimeSkewMs= Long.parseLong(strallowedTimeSkewM);
		}	
	
		//String strrequireSecureChannel= com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,"aauthentication.requireSecureChannel");
		//if(strrequireSecureChannel!=null)requireSecureChannel=Boolean.parseBoolean(strrequireSecureChannel);
		//this.nsaSecurityManager = new NsaAuthenticatorService<NsaSimpleApiKey>(this.fApiKeyDb, settings.getLong("authentication.allowedTimeSkewMs", 600000L), settings.getBoolean("authentication.requireSecureChannel", true));
		//this.nsaSecurityManager = new NsaAuthenticatorService<NsaSimpleApiKey>(this.fApiKeyDb, allowedtimeSkewMs, requireSecureChannel);
		
		servletSetup();
	}

	protected void servletSetup()
			throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, ServletException, ConfigDbException, KeyExistsException {
		try {

			fMetrics.toJson();
			fMetrics.setupCambriaSender();
			// add the admin authenticator
			
						final String adminSecret = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,CambriaConstants.kSetting_AdminSecret);
						
						if ( adminSecret != null && adminSecret.length () > 0 )
						{
								
								final NsaApiDb<NsaSimpleApiKey> adminDb = new BaseNsaApiDbImpl<NsaSimpleApiKey> ( new MemConfigDb(), new NsaSimpleApiKeyFactory() );
								adminDb.createApiKey ( "admin", adminSecret );
							
						        fSecurityManager.addAuthenticator ( new DMaaPOriginalUebAuthenticator<NsaSimpleApiKey> ( adminDb, 10*60*1000 ) );
						
						}
					
			// setup a backend
			
			 String type = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,CambriaConstants.kBrokerType);
			if (type==null){
				type = CambriaConstants.kBrokerType_Kafka;
			}
			if (CambriaConstants.kBrokerType_Kafka.equalsIgnoreCase(type)) {
				log.info("Broker Type is:" + CambriaConstants.kBrokerType_Kafka);
			} else if (CambriaConstants.kBrokerType_Memory.equalsIgnoreCase(type)) {
				log.info("Broker Type is:" + CambriaConstants.kBrokerType_Memory);
				fPublisher = new MemoryQueuePublisher(q, mmb);
				//Ramkumar remove below
			
				fConsumerFactory = new MemoryConsumerFactory(q);
			} else {
				throw new IllegalArgumentException(
						"Unrecognized type for " + CambriaConstants.kBrokerType + ": " + type + ".");
			}
			fIpBlackList = new Blacklist ( getfConfigDb(), getfConfigDb().parse ( "/ipBlacklist" ) );
			this.fEmailer = new Emailer();
			log.info("Broker Type is:" + type);

		} catch (SecurityException e) {
			throw new ServletException(e);
		}
	}

	/**
	 * method returns metaBroker
	 * 
	 * @return
	 */
	public Broker1 getfMetaBroker() {
		return fMetaBroker;
	}

	/**
	 * method to set the metaBroker
	 * 
	 * @param fMetaBroker
	 */
	public void setfMetaBroker(Broker1 fMetaBroker) {
		this.fMetaBroker = fMetaBroker;
	}

	/**
	 * method to get ConsumerFactory Object
	 * 
	 * @return
	 */
	public ConsumerFactory getfConsumerFactory() {
		return fConsumerFactory;
	}

	/**
	 * method to set the consumerfactory object
	 * 
	 * @param fConsumerFactory
	 */
	public void setfConsumerFactory(ConsumerFactory fConsumerFactory) {
		this.fConsumerFactory = fConsumerFactory;
	}

	/**
	 * method to get Publisher object
	 * 
	 * @return
	 */
	public Publisher getfPublisher() {
		return fPublisher;
	}

	/**
	 * method to set Publisher object
	 * 
	 * @param fPublisher
	 */
	public void setfPublisher(Publisher fPublisher) {
		this.fPublisher = fPublisher;
	}

	/**
	 * method to get MetricsSet Object
	 * 
	 * @return
	 */
	public MetricsSet getfMetrics() {
		return fMetrics;
	}

	/**
	 * method to set MetricsSet Object
	 * 
	 * @param fMetrics
	 */
	public void setfMetrics(MetricsSet fMetrics) {
		this.fMetrics = fMetrics;
	}

	/**
	 * method to get DMaaPCambriaLimiter object
	 * 
	 * @return
	 */
	public DMaaPCambriaLimiter getfRateLimiter() {
		return fRateLimiter;
	}

	/**
	 * method to set DMaaPCambriaLimiter object
	 * 
	 * @param fRateLimiter
	 */
	public void setfRateLimiter(DMaaPCambriaLimiter fRateLimiter) {
		this.fRateLimiter = fRateLimiter;
	}

	/**
	 * Method to get DMaaPAuthenticator object
	 * 
	 * @return
	 */
	public DMaaPAuthenticator<NsaSimpleApiKey> getfSecurityManager() {
		return fSecurityManager;
	}

	/**
	 * method to set DMaaPAuthenticator object
	 * 
	 * @param fSecurityManager
	 */
	public void setfSecurityManager(DMaaPAuthenticator<NsaSimpleApiKey> fSecurityManager) {
		this.fSecurityManager = fSecurityManager;
	}

	/**
	 * method to get rrNvReadable object
	 * 
	 * @return
	 */
	
		
	

	/**
	 * method to set rrNvReadable object
	 * 
	 * @param settings
	 */
	
	
	

	/**
	 * method to get CuratorFramework object
	 * 
	 * @return
	 */
	public static CuratorFramework getCurator() {
		return curator;
	}

	/**
	 * method to set CuratorFramework object
	 * 
	 * @param curator
	 */
	public static void setCurator(CuratorFramework curator) {
		ConfigurationReader.curator = curator;
	}

	/**
	 * method to get ZkClient object
	 * 
	 * @return
	 */
	public ZkClient getZk() {
		return zk;
	}

	/**
	 * method to set ZkClient object
	 * 
	 * @param zk
	 */
	public void setZk(ZkClient zk) {
		this.zk = zk;
	}

	/**
	 * method to get DMaaPZkConfigDb object
	 * 
	 * @return
	 */
	public DMaaPZkConfigDb getfConfigDb() {
		return fConfigDb;
	}

	/**
	 * method to set DMaaPZkConfigDb object
	 * 
	 * @param fConfigDb
	 */
	public void setfConfigDb(DMaaPZkConfigDb fConfigDb) {
		this.fConfigDb = fConfigDb;
	}

	/**
	 * method to get MemoryQueue object
	 * 
	 * @return
	 */
	public MemoryQueue getQ() {
		return q;
	}

	/**
	 * method to set MemoryQueue object
	 * 
	 * @param q
	 */
	public void setQ(MemoryQueue q) {
		this.q = q;
	}

	/**
	 * method to get MemoryMetaBroker object
	 * 
	 * @return
	 */
	public MemoryMetaBroker getMmb() {
		return mmb;
	}

	/**
	 * method to set MemoryMetaBroker object
	 * 
	 * @param mmb
	 */
	public void setMmb(MemoryMetaBroker mmb) {
		this.mmb = mmb;
	}

	/**
	 * method to get NsaApiDb object
	 * 
	 * @return
	 */
	public NsaApiDb<NsaSimpleApiKey> getfApiKeyDb() {
		return fApiKeyDb;
	}

	/**
	 * method to set NsaApiDb object
	 * 
	 * @param fApiKeyDb
	 */
	public void setfApiKeyDb(NsaApiDb<NsaSimpleApiKey> fApiKeyDb) {
		this.fApiKeyDb = fApiKeyDb;
	}

	/*
	 * public DMaaPTransactionObjDB<DMaaPTransactionObj> getfTranDb() { return
	 * fTranDb; }
	 * 
	 * public void setfTranDb(DMaaPTransactionObjDB<DMaaPTransactionObj>
	 * fTranDb) { this.fTranDb = fTranDb; }
	 */
	/**
	 * method to get the zookeeper connection String
	 * 
	 * @param settings
	 * @return
	 */
	public static String getMainZookeeperConnectionString() {
		
		
		 String zkServername = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,CambriaConstants.kSetting_ZkConfigDbServers);
		 if (zkServername==null){
			 zkServername=CambriaConstants.kDefault_ZkConfigDbServers;
		 }
		 return zkServername;
	}

	public static String getMainZookeeperConnectionSRoot(){
		String strVal=com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,CambriaConstants.kSetting_ZkConfigDbRoot);
	
		if (null==strVal)
			strVal=CambriaConstants.kDefault_ZkConfigDbRoot;
	
		return strVal;
	}
	
	public Blacklist getfIpBlackList() {
		return fIpBlackList;
	}

	public void setfIpBlackList(Blacklist fIpBlackList) {
		this.fIpBlackList = fIpBlackList;
	}

	public NsaAuthenticatorService<NsaSimpleApiKey> getNsaSecurityManager() {
		return nsaSecurityManager;
	}

	public void setNsaSecurityManager(NsaAuthenticatorService<NsaSimpleApiKey> nsaSecurityManager) {
		this.nsaSecurityManager = nsaSecurityManager;
	}
	
	public Emailer getSystemEmailer()
	  {
	    return this.fEmailer;
	  }


}