2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.security.portal.config;
26 import java.util.Properties;
28 import org.onap.aai.sparky.security.CookieDecryptor;
29 import org.onap.aai.sparky.util.ConfigHelper;
30 import org.onap.aai.sparky.util.Encryptor;
31 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
35 * Provides Portal authentication configuration.
37 public class PortalAuthenticationConfig {
39 private String username;
40 private String password;
41 private boolean isOnapEnabled;
42 private CookieDecryptor cookieDecryptor;
43 private String cookieDecryptorClassName;
45 public static final String PROP_USERNAME = "username";
46 public static final String PROP_PASSWORD = "password"; // NOSONAR
47 public static final String PROP_IS_ONAP_ENABLED = "onap_enabled"; // NOSONAR
48 private static final String AUTHENTICATION_CONFIG_FILE = SparkyConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
49 public static final String PROP_COOKIEDECRYPTORCLASSNAME = "cookie_decryptor_classname";
51 private PortalAuthenticationConfig() {
52 // Prevent instantiation
55 private static class PortalAuthenticationConfigHelper {
56 private static final PortalAuthenticationConfig INSTANCE = new PortalAuthenticationConfig();
58 private PortalAuthenticationConfigHelper() {
64 * Get a singleton instance of the configuration.
68 public static PortalAuthenticationConfig getInstance() {
69 PortalAuthenticationConfigHelper.INSTANCE.load();
70 return PortalAuthenticationConfigHelper.INSTANCE;
73 public String getUsername() {
77 public String getPassword() {
78 Encryptor encryptor = new Encryptor();
79 return encryptor.decryptValue(password);
82 public boolean getIsOnapEnabled() {
85 public String getcookieDecryptorClassName() {
86 return cookieDecryptorClassName;
90 * Reload the Portal authentication properties from the classpath.
92 public void reload() {
97 * Load the Portal authentication properties from the classpath.
100 Properties props = ConfigHelper.loadConfigFromExplicitPath(AUTHENTICATION_CONFIG_FILE);
101 username = props.getProperty(PROP_USERNAME);
102 password = props.getProperty(PROP_PASSWORD);
103 isOnapEnabled = Boolean.parseBoolean(props.getProperty(PROP_IS_ONAP_ENABLED, "true"));
104 cookieDecryptorClassName= props.getProperty(PROP_COOKIEDECRYPTORCLASSNAME);
107 public CookieDecryptor getCookieDecryptor() throws ClassNotFoundException{
109 Class cookieDecrypterClass = Class.forName(cookieDecryptorClassName);
111 cookieDecryptor = (CookieDecryptor) cookieDecrypterClass.newInstance();
112 } catch (InstantiationException | IllegalAccessException e) {
115 return cookieDecryptor;