2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2018 Nokia. All rights reserved.s
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=========================================================
22 package org.onap.dcae.restapi;
24 import java.util.HashMap;
26 import org.onap.dcae.ApplicationException;
27 import org.onap.dcae.ApplicationSettings;
28 import org.onap.dcae.common.configuration.AuthMethod;
29 import org.onap.dcae.common.configuration.AuthMethodType;
30 import org.onap.dcae.common.configuration.CertBasicAuth;
31 import org.onap.dcae.common.configuration.NoAuth;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.boot.web.server.WebServerFactoryCustomizer;
34 import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
35 import org.springframework.stereotype.Component;
38 public class ServletConfig implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
41 private ApplicationSettings properties;
44 public void customize(ConfigurableServletWebServerFactory container) {
45 provideAuthConfigurations(container).getOrDefault(properties.authMethod(),
46 notSupportedOperation()).configure();
49 private Map<String, AuthMethod> provideAuthConfigurations(ConfigurableServletWebServerFactory container) {
50 Map<String, AuthMethod> authMethods = new HashMap<>();
51 authMethods.put(AuthMethodType.CERT_BASIC_AUTH.value(), new CertBasicAuth(container, properties));
52 authMethods.put(AuthMethodType.NO_AUTH.value(), new NoAuth(container, properties));
56 private AuthMethod notSupportedOperation() {
58 throw new ApplicationException(
59 "Provided auth method not allowed: " + properties.authMethod());