Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 AT&T
|
| 6 | * ================================================================================
|
| 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 | * you may not use this file except in compliance with the License.
|
| 9 | * You may obtain a copy of the License at
|
| 10 | *
|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 12 | *
|
| 13 | * Unless required by applicable law or agreed to in writing, software
|
| 14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 | * See the License for the specific language governing permissions and
|
| 17 | * limitations under the License.
|
| 18 | * ============LICENSE_END=========================================================
|
| 19 | */
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 | package org.onap.osam.aai.util;
|
| 24 |
|
| 25 | import org.eclipse.jetty.util.security.Password;
|
| 26 | import org.onap.portalsdk.core.util.SystemProperties;
|
| 27 | import org.onap.osam.aai.exceptions.InvalidPropertyException;
|
| 28 |
|
| 29 | import java.io.UnsupportedEncodingException;
|
| 30 | import java.util.Base64;
|
| 31 | import java.util.Optional;
|
| 32 |
|
| 33 | public class SystemPropertyHelper {
|
| 34 |
|
| 35 | public Optional<String> getAAIUseClientCert(){
|
| 36 | return getSystemProperty(AAIProperties.AAI_USE_CLIENT_CERT);
|
| 37 | }
|
| 38 |
|
| 39 | public Optional<String> getAAIServerUrl(){
|
| 40 | return getSystemProperty(AAIProperties.AAI_SERVER_URL);
|
| 41 | }
|
| 42 |
|
| 43 | public Optional<String> getAAIServerBaseUrl(){
|
| 44 | return getSystemProperty(AAIProperties.AAI_SERVER_URL_BASE);
|
| 45 | }
|
| 46 |
|
| 47 | public Optional<String> getAAIVIDUsername(){
|
| 48 | return getSystemProperty(AAIProperties.AAI_VID_USERNAME);
|
| 49 | }
|
| 50 |
|
| 51 | public Optional<String> getAAIVIDPasswd(){
|
| 52 | return getSystemProperty(AAIProperties.AAI_VID_PASSWD_X);
|
| 53 | }
|
| 54 |
|
| 55 | public Optional<String> getAAITruststorePasswd(){
|
| 56 | return getSystemProperty(AAIProperties.AAI_TRUSTSTORE_PASSWD_X);
|
| 57 | }
|
| 58 |
|
| 59 | public Optional<String> getAAITruststoreFilename(){
|
| 60 | return getSystemProperty(AAIProperties.AAI_TRUSTSTORE_FILENAME);
|
| 61 | }
|
| 62 |
|
| 63 | public Optional<String> getAAIKeystoreFilename(){
|
| 64 | return getSystemProperty(AAIProperties.AAI_KEYSTORE_FILENAME);
|
| 65 | }
|
| 66 |
|
| 67 | public Optional<String> getAAIKeystorePasswd(){
|
| 68 | return getSystemProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X);
|
| 69 | }
|
| 70 |
|
| 71 | public boolean isClientCertEnabled() {
|
| 72 | return getAAIUseClientCert().orElse("false").equalsIgnoreCase("true");
|
| 73 | }
|
| 74 |
|
| 75 | public String getFullServicePath(String path) {
|
| 76 | return getAAIServerUrl().orElse("") + path;
|
| 77 | }
|
| 78 |
|
| 79 | public String getServiceBasePath(String path) {
|
| 80 | return getAAIServerBaseUrl().orElse("") + path;
|
| 81 | }
|
| 82 |
|
| 83 | public String getEncodedCredentials() throws InvalidPropertyException, UnsupportedEncodingException {
|
| 84 | String vidUsername = getAAIVIDUsername().orElseThrow(InvalidPropertyException::new);
|
| 85 | String vidPassword = Password.deobfuscate(getAAIVIDPasswd().orElseThrow(InvalidPropertyException::new));
|
| 86 | return Base64.getEncoder().encodeToString((vidUsername + ":" + vidPassword).getBytes("utf-8"));
|
| 87 | }
|
| 88 |
|
| 89 | public String getDecryptedTruststorePassword(){
|
| 90 | return Password.deobfuscate(getAAITruststorePasswd().orElse(""));
|
| 91 | }
|
| 92 |
|
| 93 | public String getDecryptedKeystorePassword(){
|
| 94 | return Password.deobfuscate(getAAIKeystorePasswd().orElse(""));
|
| 95 | }
|
| 96 |
|
| 97 | private Optional<String> getSystemProperty(String propertyKey){
|
| 98 | return Optional.ofNullable(SystemProperties.getProperty(propertyKey));
|
| 99 | }
|
| 100 | }
|