2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.security.portal.config;
28 import java.util.Properties;
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
32 import org.onap.aai.sparky.logging.AaiUiMsgs;
33 import org.onap.aai.sparky.security.CookieDecryptor;
34 import org.onap.aai.sparky.util.ConfigHelper;
35 import org.onap.aai.sparky.util.Encryptor;
36 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
40 * Provides Portal authentication configuration.
42 public class PortalAuthenticationConfig {
44 private String username;
45 private String password;
46 private boolean isOnapEnabled;
47 private CookieDecryptor cookieDecryptor;
48 private String cookieDecryptorClassName;
50 public static final String PROP_USERNAME = "username";
51 public static final String PROP_PASSWORD = "password"; // NOSONAR
52 public static final String PROP_IS_ONAP_ENABLED = "onap_enabled"; // NOSONAR
53 private static final String AUTHENTICATION_CONFIG_FILE = SparkyConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
54 public static final String PROP_COOKIEDECRYPTORCLASSNAME = "cookie_decryptor_classname";
55 private static final Logger LOG = LoggerFactory.getInstance().getLogger(PortalAuthenticationConfig.class);
57 private PortalAuthenticationConfig() {
58 // Prevent instantiation
61 private static class PortalAuthenticationConfigHelper {
62 private static final PortalAuthenticationConfig INSTANCE = new PortalAuthenticationConfig();
64 private PortalAuthenticationConfigHelper() {
70 * Get a singleton instance of the configuration.
74 public static PortalAuthenticationConfig getInstance() {
75 PortalAuthenticationConfigHelper.INSTANCE.load();
76 return PortalAuthenticationConfigHelper.INSTANCE;
79 public String getUsername() {
83 public String getPassword() {
84 Encryptor encryptor = new Encryptor();
85 return encryptor.decryptValue(password);
88 public boolean getIsOnapEnabled() {
91 public String getcookieDecryptorClassName() {
92 return cookieDecryptorClassName;
96 * Reload the Portal authentication properties from the classpath.
98 public void reload() {
103 * Load the Portal authentication properties from the classpath.
105 private void load() {
106 Properties props = ConfigHelper.loadConfigFromExplicitPath(AUTHENTICATION_CONFIG_FILE);
107 username = props.getProperty(PROP_USERNAME);
108 password = props.getProperty(PROP_PASSWORD);
109 isOnapEnabled = Boolean.parseBoolean(props.getProperty(PROP_IS_ONAP_ENABLED, "true"));
110 cookieDecryptorClassName= props.getProperty(PROP_COOKIEDECRYPTORCLASSNAME);
113 public CookieDecryptor getCookieDecryptor() throws ClassNotFoundException{
115 Class cookieDecrypterClass = Class.forName(cookieDecryptorClassName);
117 cookieDecryptor = (CookieDecryptor) cookieDecrypterClass.newInstance();
118 } catch (InstantiationException | IllegalAccessException e) {
119 LOG.error(AaiUiMsgs.DECRYPTION_ERROR,"Unable to instantiate Cookie Decryptor Class");
121 return cookieDecryptor;