fanxw před 1 rokem
rodič
revize
4aea23eb75

+ 6 - 2
pom.xml

@@ -4,7 +4,7 @@
4
 	<modelVersion>4.0.0</modelVersion>
4
 	<modelVersion>4.0.0</modelVersion>
5
 
5
 
6
 	<groupId>com.unis.module</groupId>
6
 	<groupId>com.unis.module</groupId>
7
-	<artifactId>depot-eureka-tianjin</artifactId>
7
+	<artifactId>depot-server</artifactId>
8
 	<version>0.0.1-SNAPSHOT</version>
8
 	<version>0.0.1-SNAPSHOT</version>
9
 	<packaging>jar</packaging>
9
 	<packaging>jar</packaging>
10
 
10
 
@@ -14,7 +14,7 @@
14
 	<parent>
14
 	<parent>
15
 		<groupId>org.springframework.boot</groupId>
15
 		<groupId>org.springframework.boot</groupId>
16
 		<artifactId>spring-boot-starter-parent</artifactId>
16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.3.RELEASE</version>
17
+		<version>2.0.4.RELEASE</version>
18
 		<relativePath/> <!-- lookup parent from repository -->
18
 		<relativePath/> <!-- lookup parent from repository -->
19
 	</parent>
19
 	</parent>
20
 
20
 
@@ -36,6 +36,10 @@
36
 			<artifactId>spring-boot-starter-test</artifactId>
36
 			<artifactId>spring-boot-starter-test</artifactId>
37
 			<scope>test</scope>
37
 			<scope>test</scope>
38
 		</dependency>
38
 		</dependency>
39
+		<dependency>  
40
+		    <groupId>org.springframework.boot</groupId>  
41
+		    <artifactId>spring-boot-starter-security</artifactId>  
42
+		</dependency>
39
 	</dependencies>
43
 	</dependencies>
40
 
44
 
41
 	<dependencyManagement>
45
 	<dependencyManagement>

+ 3 - 0
src/main/java/com/unis/module/eureka/EurekaApplication.java

@@ -1,7 +1,9 @@
1
 package com.unis.module.eureka;
1
 package com.unis.module.eureka;
2
 
2
 
3
 import org.springframework.boot.SpringApplication;
3
 import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
6
+import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
5
 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
7
 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6
 
8
 
7
 /**
9
 /**
@@ -13,6 +15,7 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
13
  */
15
  */
14
 @SpringBootApplication
16
 @SpringBootApplication
15
 @EnableEurekaServer
17
 @EnableEurekaServer
18
+@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
16
 public class EurekaApplication {
19
 public class EurekaApplication {
17
 
20
 
18
     public static void main(String[] args) {
21
     public static void main(String[] args) {

+ 51 - 0
src/main/java/com/unis/module/eureka/WebSecurityConfig.java

@@ -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
+}

+ 17 - 1
src/main/resources/application.yml

@@ -3,6 +3,7 @@ server:
3
 
3
 
4
 eureka:
4
 eureka:
5
   instance:
5
   instance:
6
+    hostname: localhost
6
     prefer-ip-address: true
7
     prefer-ip-address: true
7
     # 仅测试使用,部署上线不使用
8
     # 仅测试使用,部署上线不使用
8
     status-page-url-path: /swagger-ui.html
9
     status-page-url-path: /swagger-ui.html
@@ -10,14 +11,29 @@ eureka:
10
     register-with-eureka: false
11
     register-with-eureka: false
11
     fetch-registry: false
12
     fetch-registry: false
12
     service-url:
13
     service-url:
13
-      defaultZone: http://172.16.0.16:9001/eureka/
14
+      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
15
+      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka
14
   server:
16
   server:
15
     # 关闭自我保护机制(不关闭会在所有服务连接异常85%后不在注销服务)
17
     # 关闭自我保护机制(不关闭会在所有服务连接异常85%后不在注销服务)
16
     enable-self-preservation: false
18
     enable-self-preservation: false
17
     # 每隔30s扫描服务列表,移除失效服务(默认60000)
19
     # 每隔30s扫描服务列表,移除失效服务(默认60000)
18
     eviction-interval-timer-in-ms: 30000
20
     eviction-interval-timer-in-ms: 30000
21
+    
22
+spring:
23
+  security:
24
+    basic:
25
+      enabled: true
26
+    user:
27
+      # 用户名
28
+      name: tj_admin
29
+      # 用户密码
30
+      password: Admin_1234
31
+
19
 management:
32
 management:
33
+  server:
34
+    port: -1
20
   endpoints:
35
   endpoints:
36
+    #enabled-by-default: false
21
     web:
37
     web:
22
       exposure:
38
       exposure:
23
         include: '*'
39
         include: '*'