Port to java 17
[ccsdk/apps.git] / ms / neng / src / main / java / org / onap / ccsdk / apps / ms / neng / core / WebConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK.apps
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
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 package org.onap.ccsdk.apps.ms.neng.core;
22
23 import org.onap.ccsdk.apps.ms.neng.core.rs.interceptors.AaiAuthorizationInterceptor;
24 import org.onap.ccsdk.apps.ms.neng.core.rs.interceptors.PolicyManagerAuthorizationInterceptor;
25 import org.springframework.boot.web.client.RestTemplateBuilder;
26 import org.springframework.context.annotation.Bean;
27 import org.springframework.context.annotation.Configuration;
28 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
29 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
30
31 /**
32  * Configuration for the API part of the micro-service.
33  */
34 @Configuration
35 public class WebConfiguration {
36     /**
37      * Creates the bean for configuring swagger.
38      */
39     @Bean
40     public WebMvcConfigurer forwardToIndex() {
41         return new WebMvcConfigurer() {
42             @Override
43             public void addViewControllers(ViewControllerRegistry registry) {
44                 registry.addViewController("/swagger").setViewName("redirect:/swagger/index.html");
45                 registry.addViewController("/swagger/").setViewName("redirect:/swagger/index.html");
46                 registry.addViewController("/docs").setViewName("redirect:/docs/html/index.html");
47                 registry.addViewController("/docs/").setViewName("redirect:/docs/html/index.html");
48             }
49         };
50     }
51
52     /**
53      * Creates the bean for configuring policy manager interceptor.
54      */
55     @Bean
56     public RestTemplateBuilder policyMgrRestTempBuilder(PolicyManagerAuthorizationInterceptor auth) {
57         RestTemplateBuilder restTemplateBuiler = new RestTemplateBuilder();
58         return restTemplateBuiler.additionalInterceptors(auth);
59     }
60
61     /**
62      * Creates the bean for configuring A&AI interceptor.
63      */
64     @Bean
65     public RestTemplateBuilder aaiRestTempBuilder(AaiAuthorizationInterceptor auth) {
66         RestTemplateBuilder restTemplateBuiler = new RestTemplateBuilder();
67         return restTemplateBuiler.additionalInterceptors(auth);
68     }
69 }