2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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 package org.onap.aai.sparky.security.portal.config;
24 import java.util.Properties;
26 import org.onap.aai.cl.api.Logger;
27 import org.onap.aai.cl.eelf.LoggerFactory;
28 import org.onap.aai.sparky.logging.AaiUiMsgs;
29 import org.onap.aai.sparky.security.CookieDecryptor;
30 import org.onap.aai.sparky.util.ConfigHelper;
31 import org.onap.aai.sparky.util.Encryptor;
32 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
36 * Provides Portal authentication configuration.
38 public class PortalAuthenticationConfig {
40 private String username;
41 private String password;
42 private boolean isOnapEnabled;
43 private CookieDecryptor cookieDecryptor;
44 private String cookieDecryptorClassName;
46 public static final String PROP_USERNAME = "username";
47 public static final String PROP_PASSWORD = "password"; // NOSONAR
48 public static final String PROP_IS_ONAP_ENABLED = "onap_enabled"; // NOSONAR
49 private static final String AUTHENTICATION_CONFIG_FILE = SparkyConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
50 public static final String PROP_COOKIEDECRYPTORCLASSNAME = "cookie_decryptor_classname";
51 private static final Logger LOG = LoggerFactory.getInstance().getLogger(PortalAuthenticationConfig.class);
53 private PortalAuthenticationConfig() {
54 // Prevent instantiation
57 private static class PortalAuthenticationConfigHelper {
58 private static final PortalAuthenticationConfig INSTANCE = new PortalAuthenticationConfig();
60 private PortalAuthenticationConfigHelper() {
66 * Get a singleton instance of the configuration.
70 public static PortalAuthenticationConfig getInstance() {
71 PortalAuthenticationConfigHelper.INSTANCE.load();
72 return PortalAuthenticationConfigHelper.INSTANCE;
75 public String getUsername() {
79 public String getPassword() {
80 Encryptor encryptor = new Encryptor();
81 return encryptor.decryptValue(password);
84 public boolean getIsOnapEnabled() {
87 public String getcookieDecryptorClassName() {
88 return cookieDecryptorClassName;
92 * Reload the Portal authentication properties from the classpath.
94 public void reload() {
99 * Load the Portal authentication properties from the classpath.
101 private void load() {
102 Properties props = ConfigHelper.loadConfigFromExplicitPath(AUTHENTICATION_CONFIG_FILE);
103 username = props.getProperty(PROP_USERNAME);
104 password = props.getProperty(PROP_PASSWORD);
105 isOnapEnabled = Boolean.parseBoolean(props.getProperty(PROP_IS_ONAP_ENABLED, "true"));
106 cookieDecryptorClassName= props.getProperty(PROP_COOKIEDECRYPTORCLASSNAME);
109 public CookieDecryptor getCookieDecryptor() throws ClassNotFoundException{
111 Class cookieDecrypterClass = Class.forName(cookieDecryptorClassName);
113 cookieDecryptor = (CookieDecryptor) cookieDecrypterClass.newInstance();
114 } catch (InstantiationException | IllegalAccessException e) {
115 LOG.error(AaiUiMsgs.DECRYPTION_ERROR,"Unable to instantiate Cookie Decryptor Class");
117 return cookieDecryptor;