|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+package com.unis.module.eureka;
|
|
|
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.EnableWebSecurity;
|
|
|
6
|
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
7
|
+
|
|
|
8
|
+@Configuration
|
|
|
9
|
+@EnableWebSecurity
|
|
|
10
|
+public class WebSecurityConfig
|
|
|
11
|
+extends WebSecurityConfigurerAdapter
|
|
|
12
|
+{
|
|
|
13
|
+
|
|
|
14
|
+ @Override
|
|
|
15
|
+ protected void configure(HttpSecurity http) throws Exception {
|
|
|
16
|
+ String[] urls = {
|
|
|
17
|
+ "*",
|
|
|
18
|
+ "/*",
|
|
|
19
|
+ "/*/*",
|
|
|
20
|
+ "/*/*/*",
|
|
|
21
|
+ "/*/*/*/*",
|
|
|
22
|
+ "/*/*/*/*/*/*",
|
|
|
23
|
+ "/depot-system/userInfo/login",
|
|
|
24
|
+ "/login",
|
|
|
25
|
+ "depot-system/userInfo/login",
|
|
|
26
|
+ "login"
|
|
|
27
|
+ };
|
|
|
28
|
+
|
|
|
29
|
+ http.authorizeRequests().anyRequest().permitAll() //允许所有用户访问所有资源
|
|
|
30
|
+ .and()
|
|
|
31
|
+ .csrf().disable(); // 禁用CSRF(防止伪造的跨域攻击)
|
|
|
32
|
+
|
|
|
33
|
+ super.configure(http);
|
|
|
34
|
+//
|
|
|
35
|
+// http.authorizeRequests() // 对请求执行认证与授权
|
|
|
36
|
+// .antMatchers(urls) // 匹配某些请求路径
|
|
|
37
|
+// .permitAll() // (对此前匹配的请求路径)不需要通过认证即允许访问
|
|
|
38
|
+// .anyRequest() // 除以上配置过的请求路径以外的所有请求路径
|
|
|
39
|
+// .authenticated(); // 要求是已经通过认证的
|
|
|
40
|
+// super.configure(http);
|
|
|
41
|
+
|
|
|
42
|
+// http.httpBasic().and().authorizeRequests().antMatchers("/actuator/**").authenticated().anyRequest().permitAll();
|
|
|
43
|
+// http
|
|
|
44
|
+// // 关闭csrf token认证不需要csrf防护
|
|
|
45
|
+// .csrf().disable()
|
|
|
46
|
+// // 关闭session会话管理器 JWT 不需要
|
|
|
47
|
+// .sessionManagement().disable()
|
|
|
48
|
+// // 关闭记住我功能 JWT 不需要
|
|
|
49
|
+// .rememberMe().disable();
|
|
|
50
|
+ }
|
|
|
51
|
+}
|