# AAI REST Client Configuration
aai.serviceName=10.12.6.118
aai.servicePort=8443
+# AAI APIs authentication mode. Valid values: [basic_auth, client_cert]
+aai.authentication=basic_auth
+aai.trustStorePath=n/a
+aai.keyStorePath=n/a
+aai.keyStorePassword=n/a
aai.username=AAI
aai.password=OBF:1gfr1ev31gg7
aai.httpProtocol=https
--- /dev/null
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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=====================================================
+ */
+package org.onap.sdnc.apps.pomba.servicedecomposition;
+
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+public class AAIBasicAuthCondition implements Condition {
+
+ @Override
+ public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata)
+ {
+ String authenticationMode = conditionContext.getEnvironment().getProperty("aai.authentication");
+ return authenticationMode.equalsIgnoreCase("basic_auth");
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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=====================================================
+ */
+package org.onap.sdnc.apps.pomba.servicedecomposition;
+
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+public class AAIClientCertCondition implements Condition {
+
+ @Override
+ public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata)
+ {
+ String authenticationMode = conditionContext.getEnvironment().getProperty("aai.authentication");
+ return authenticationMode.equalsIgnoreCase("client_cert");
+ }
+}
import org.onap.aai.restclient.client.RestClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
@Component
@Value("${aai.securityProtocol}")
private String securityProtocol;
+ @Value("${aai.authentication}")
+ private String authenticationMode;
+
+ @Value("${aai.trustStorePath}")
+ private String trustStorePath;
+
+ @Value("${aai.keyStorePath}")
+ private String keyStorePath;
+
+ @Value("${aai.keyStorePassword}")
+ private String keyStorePassword;
+
@Value("${aai.connectionTimeout}")
private Integer connectionTimeout;
return "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + Password.deobfuscate(this.password)).getBytes());
}
+ @Conditional(AAIBasicAuthCondition.class)
@Bean(name="aaiClient")
- public RestClient restClient() {
+ public RestClient restClientWithBasicAuth() {
return new RestClient()
.validateServerHostname(false)
.validateServerCertChain(false)
.readTimeoutMs(this.readTimeout);
}
+ @Conditional(AAIClientCertCondition.class)
+ @Bean(name="aaiClient")
+ public RestClient restClientWithClientCert() {
+ RestClient restClient = new RestClient();
+ System.out.println("in client cert");
+ if (httpProtocol.equals("https"))
+ restClient.validateServerHostname(false).validateServerCertChain(false).trustStore(trustStorePath).clientCertFile(keyStorePath).clientCertPassword(keyStorePassword).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout);
+ else
+ restClient.validateServerHostname(false).validateServerCertChain(false).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout);
+ return restClient;
+ }
+
@Bean(name="aaiBaseUrl")
public String getURL() {
return this.httpProtocol + "://" + this.host + ":" + this.port;