正在显示
5 个修改的文件
包含
189 行增加
和
1 行删除
@@ -9,6 +9,12 @@ spring: | @@ -9,6 +9,12 @@ spring: | ||
9 | profiles: | 9 | profiles: |
10 | active: dev | 10 | active: dev |
11 | 11 | ||
12 | + rabbitmq: | ||
13 | + host: 192.168.1.63 | ||
14 | + port: 5672 | ||
15 | + username: mrz | ||
16 | + password: vmvnv1v2 | ||
17 | + | ||
12 | #security基本配置 | 18 | #security基本配置 |
13 | security: | 19 | security: |
14 | user: | 20 | user: |
@@ -46,7 +52,10 @@ eureka: | @@ -46,7 +52,10 @@ eureka: | ||
46 | prefer-ip-address: true | 52 | prefer-ip-address: true |
47 | instance-id: ${spring.cloud.client.ip-address}:${server.port} | 53 | instance-id: ${spring.cloud.client.ip-address}:${server.port} |
48 | hostname: ${spring.cloud.client.ip-address} | 54 | hostname: ${spring.cloud.client.ip-address} |
49 | - | 55 | + metadata-map: |
56 | + user: | ||
57 | + name: "admin" | ||
58 | + password: "123456" | ||
50 | client: | 59 | client: |
51 | healthcheck: | 60 | healthcheck: |
52 | enabled: true | 61 | enabled: true |
@@ -75,6 +75,14 @@ | @@ -75,6 +75,14 @@ | ||
75 | <version>2.2.0</version> | 75 | <version>2.2.0</version> |
76 | </dependency> | 76 | </dependency> |
77 | <dependency> | 77 | <dependency> |
78 | + <groupId>org.springframework.cloud</groupId> | ||
79 | + <artifactId>spring-cloud-bus</artifactId> | ||
80 | + </dependency> | ||
81 | + <dependency> | ||
82 | + <groupId>org.springframework.cloud</groupId> | ||
83 | + <artifactId>spring-cloud-stream-binder-rabbit</artifactId> | ||
84 | + </dependency> | ||
85 | + <dependency> | ||
78 | <groupId>org.springframework.boot</groupId> | 86 | <groupId>org.springframework.boot</groupId> |
79 | <artifactId>spring-boot-starter-actuator</artifactId> | 87 | <artifactId>spring-boot-starter-actuator</artifactId> |
80 | </dependency> | 88 | </dependency> |
1 | +package com.sunyo.wlpt.cloud.config.server.config; | ||
2 | + | ||
3 | +import org.springframework.context.annotation.Configuration; | ||
4 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
5 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
6 | +import org.springframework.security.config.http.SessionCreationPolicy; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author 子诚 | ||
10 | + * Description: | ||
11 | + * 时间:2020/6/22 19:56 | ||
12 | + */ | ||
13 | +@Configuration | ||
14 | +public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
15 | + @Override | ||
16 | + protected void configure(HttpSecurity http) throws Exception { | ||
17 | + http.authorizeRequests() | ||
18 | + .antMatchers("/**","/actuator/**","/refresh/**") | ||
19 | + .permitAll() | ||
20 | + .and() | ||
21 | + .csrf().disable(); | ||
22 | + } | ||
23 | +} |
1 | +package com.sunyo.wlpt.cloud.config.server.config; | ||
2 | + | ||
3 | +import org.springframework.stereotype.Component; | ||
4 | + | ||
5 | +import javax.servlet.*; | ||
6 | +import javax.servlet.http.HttpServletRequest; | ||
7 | +import javax.servlet.http.HttpServletRequestWrapper; | ||
8 | +import javax.servlet.http.HttpServletResponse; | ||
9 | +import java.io.BufferedReader; | ||
10 | +import java.io.ByteArrayInputStream; | ||
11 | +import java.io.IOException; | ||
12 | + | ||
13 | +/** | ||
14 | + * @author 子诚 | ||
15 | + * Description:解决GitLab的web钩子报错400问题。是因为gitlab自己添加一堆东西导致JSON解析异常 | ||
16 | + * 时间:2020/6/23 17:10 | ||
17 | + */ | ||
18 | +@Component | ||
19 | +public class UrlFilter implements Filter { | ||
20 | + @Override | ||
21 | + public void init(FilterConfig filterConfig) throws ServletException { | ||
22 | + | ||
23 | + } | ||
24 | + | ||
25 | + @Override | ||
26 | + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
27 | + HttpServletRequest httpServletRequest = (HttpServletRequest)request; | ||
28 | + HttpServletResponse httpServletResponse = (HttpServletResponse)response; | ||
29 | + | ||
30 | + String url = new String(httpServletRequest.getRequestURI()); | ||
31 | + | ||
32 | + //只过滤/actuator/bus-refresh请求 | ||
33 | + if (!url.endsWith("/bus-refresh")) { | ||
34 | + chain.doFilter(request, response); | ||
35 | + return; | ||
36 | + } | ||
37 | + | ||
38 | + //获取原始的body | ||
39 | + String body = readAsChars(httpServletRequest); | ||
40 | + | ||
41 | + System.out.println("original body: "+ body); | ||
42 | + | ||
43 | + //使用HttpServletRequest包装原始请求达到修改post请求中body内容的目的 | ||
44 | + CustometRequestWrapper requestWrapper = new CustometRequestWrapper(httpServletRequest); | ||
45 | + | ||
46 | + chain.doFilter(requestWrapper, response); | ||
47 | + | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public void destroy() { | ||
52 | + | ||
53 | + } | ||
54 | + | ||
55 | + private class CustometRequestWrapper extends HttpServletRequestWrapper { | ||
56 | + public CustometRequestWrapper(HttpServletRequest request) { | ||
57 | + super(request); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public ServletInputStream getInputStream() throws IOException { | ||
62 | + byte[] bytes = new byte[0]; | ||
63 | + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); | ||
64 | + | ||
65 | + return new ServletInputStream() { | ||
66 | + @Override | ||
67 | + public boolean isFinished() { | ||
68 | + return byteArrayInputStream.read() == -1 ? true:false; | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public boolean isReady() { | ||
73 | + return false; | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public void setReadListener(ReadListener readListener) { | ||
78 | + | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public int read() throws IOException { | ||
83 | + return byteArrayInputStream.read(); | ||
84 | + } | ||
85 | + }; | ||
86 | + } | ||
87 | + } | ||
88 | + | ||
89 | + public static String readAsChars(HttpServletRequest request) | ||
90 | + { | ||
91 | + | ||
92 | + BufferedReader br = null; | ||
93 | + StringBuilder sb = new StringBuilder(""); | ||
94 | + try | ||
95 | + { | ||
96 | + br = request.getReader(); | ||
97 | + String str; | ||
98 | + while ((str = br.readLine()) != null) | ||
99 | + { | ||
100 | + sb.append(str); | ||
101 | + } | ||
102 | + br.close(); | ||
103 | + } | ||
104 | + catch (IOException e) | ||
105 | + { | ||
106 | + e.printStackTrace(); | ||
107 | + } | ||
108 | + finally | ||
109 | + { | ||
110 | + if (null != br) | ||
111 | + { | ||
112 | + try | ||
113 | + { | ||
114 | + br.close(); | ||
115 | + } | ||
116 | + catch (IOException e) | ||
117 | + { | ||
118 | + e.printStackTrace(); | ||
119 | + } | ||
120 | + } | ||
121 | + } | ||
122 | + return sb.toString(); | ||
123 | + } | ||
124 | +} |
1 | +package com.sunyo.wlpt.cloud.config.server.controller; | ||
2 | + | ||
3 | +import org.springframework.beans.factory.annotation.Value; | ||
4 | +import org.springframework.cloud.context.config.annotation.RefreshScope; | ||
5 | +import org.springframework.web.bind.annotation.GetMapping; | ||
6 | +import org.springframework.web.bind.annotation.RestController; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author 子诚 | ||
10 | + * Description: | ||
11 | + * 时间:2020/6/23 10:59 | ||
12 | + */ | ||
13 | +@RestController | ||
14 | +@RefreshScope | ||
15 | +public class IndexController { | ||
16 | + | ||
17 | + @Value("${info.description}") | ||
18 | + private String description; | ||
19 | + | ||
20 | + @GetMapping("/index") | ||
21 | + public String index(){ | ||
22 | + return description; | ||
23 | + } | ||
24 | +} |
-
请 注册 或 登录 后发表评论