提交 | 用户 | 时间
|
e7c126
|
1 |
/* |
H |
2 |
* Copyright 1999-2018 Alibaba Group Holding Ltd. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
|
|
17 |
package com.alibaba.nacos.console.config; |
|
18 |
|
|
19 |
import com.alibaba.nacos.console.filter.XssFilter; |
|
20 |
import com.alibaba.nacos.core.code.ControllerMethodsCache; |
|
21 |
import org.springframework.beans.factory.annotation.Autowired; |
|
22 |
import org.springframework.beans.factory.annotation.Value; |
|
23 |
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; |
|
24 |
import org.springframework.context.annotation.Bean; |
|
25 |
import org.springframework.context.annotation.PropertySource; |
|
26 |
import org.springframework.scheduling.annotation.EnableScheduling; |
|
27 |
import org.springframework.stereotype.Component; |
|
28 |
import org.springframework.web.cors.CorsConfiguration; |
|
29 |
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
|
30 |
import org.springframework.web.filter.CorsFilter; |
|
31 |
|
|
32 |
import javax.annotation.PostConstruct; |
|
33 |
import java.time.ZoneId; |
|
34 |
|
|
35 |
/** |
|
36 |
* Console config. |
|
37 |
* |
|
38 |
* @author yshen |
|
39 |
* @author nkorange |
|
40 |
* @since 1.2.0 |
|
41 |
*/ |
|
42 |
@Component |
|
43 |
@EnableScheduling |
|
44 |
@PropertySource("/application.properties") |
|
45 |
public class ConsoleConfig { |
|
46 |
|
|
47 |
@Autowired |
|
48 |
private ControllerMethodsCache methodsCache; |
|
49 |
|
|
50 |
@Value("${nacos.console.ui.enabled:true}") |
|
51 |
private boolean consoleUiEnabled; |
|
52 |
|
|
53 |
/** |
|
54 |
* Init. |
|
55 |
*/ |
|
56 |
@PostConstruct |
|
57 |
public void init() { |
|
58 |
methodsCache.initClassMethod("com.alibaba.nacos.core.controller"); |
|
59 |
methodsCache.initClassMethod("com.alibaba.nacos.naming.controllers"); |
|
60 |
methodsCache.initClassMethod("com.alibaba.nacos.config.server.controller"); |
|
61 |
methodsCache.initClassMethod("com.alibaba.nacos.console.controller"); |
|
62 |
} |
|
63 |
|
|
64 |
@Bean |
|
65 |
public CorsFilter corsFilter() { |
|
66 |
CorsConfiguration config = new CorsConfiguration(); |
|
67 |
config.setAllowCredentials(true); |
|
68 |
config.addAllowedHeader("*"); |
|
69 |
config.setMaxAge(18000L); |
|
70 |
config.addAllowedMethod("*"); |
|
71 |
config.addAllowedOriginPattern("*"); |
|
72 |
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
|
73 |
source.registerCorsConfiguration("/**", config); |
|
74 |
return new CorsFilter(source); |
|
75 |
} |
|
76 |
|
|
77 |
@Bean |
|
78 |
public XssFilter xssFilter() { |
|
79 |
return new XssFilter(); |
|
80 |
} |
|
81 |
|
|
82 |
@Bean |
|
83 |
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() { |
|
84 |
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(ZoneId.systemDefault().toString()); |
|
85 |
} |
|
86 |
|
|
87 |
public boolean isConsoleUiEnabled() { |
|
88 |
return consoleUiEnabled; |
|
89 |
} |
|
90 |
} |