Sfoglia il codice sorgente

图片 截取签名

weiximei 6 anni fa
parent
commit
52d696fd17

+ 3
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/ImageServiceimpl.java Vedi File

@@ -38,6 +38,9 @@ public class ImageServiceimpl implements ImageServiceI {
38 38
         ossClient.shutdown();
39 39
         Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
40 40
         String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
41
+
42
+        // 截取掉签名
43
+        url = url.substring(0, url.lastIndexOf("&Signature"));
41 44
         return url;
42 45
     }
43 46
 }

+ 24
- 8
CODE/smart-community/gateway/pom.xml Vedi File

@@ -50,13 +50,6 @@
50 50
             <scope>test</scope>
51 51
         </dependency>
52 52
 
53
-
54
-        <!--<dependency>-->
55
-            <!--<groupId>com.didispace</groupId>-->
56
-            <!--<artifactId>swagger-butler-core</artifactId>-->
57
-            <!--<version>1.0.0</version>-->
58
-        <!--</dependency>-->
59
-
60 53
         <dependency>
61 54
             <groupId>io.springfox</groupId>
62 55
             <artifactId>springfox-swagger2</artifactId>
@@ -93,7 +86,6 @@
93 86
         <dependency>
94 87
             <groupId>org.springframework.boot</groupId>
95 88
             <artifactId>spring-boot-starter-jdbc</artifactId>
96
-
97 89
         </dependency>
98 90
 
99 91
         <dependency>
@@ -109,6 +101,30 @@
109 101
             <version>${spring-session-jdbc.version}</version>
110 102
         </dependency>
111 103
 
104
+        <!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session-core -->
105
+        <dependency>
106
+            <groupId>org.springframework.session</groupId>
107
+            <artifactId>spring-session-core</artifactId>
108
+            <version>${spring-session-jdbc.version}</version>
109
+        </dependency>
110
+
111
+        <!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session-hazelcast -->
112
+        <dependency>
113
+            <groupId>org.springframework.session</groupId>
114
+            <artifactId>spring-session-hazelcast</artifactId>
115
+            <version>${spring-session-jdbc.version}</version>
116
+        </dependency>
117
+
118
+        <!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session -->
119
+        <dependency>
120
+            <groupId>org.springframework.session</groupId>
121
+            <artifactId>spring-session</artifactId>
122
+            <version>1.3.4.RELEASE</version>
123
+        </dependency>
124
+
125
+
126
+
127
+
112 128
         <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
113 129
         <dependency>
114 130
             <groupId>org.projectlombok</groupId>

+ 18
- 24
CODE/smart-community/gateway/src/main/java/com/community/huiju/GatewayApplication.java Vedi File

@@ -1,15 +1,9 @@
1 1
 package com.community.huiju;
2 2
 
3
-//import com.didispace.swagger.butler.EnableSwaggerButler;
4 3
 import org.springframework.boot.SpringApplication;
5 4
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
6
-import org.springframework.boot.autoconfigure.SpringBootApplication;
7 5
 import org.springframework.cloud.client.SpringCloudApplication;
8
-import org.springframework.cloud.client.discovery.DiscoveryClient;
9 6
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
10
-import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator;
11
-import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties;
12
-import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
13 7
 import org.springframework.context.annotation.Bean;
14 8
 import org.springframework.context.annotation.PropertySource;
15 9
 import org.springframework.web.cors.CorsConfiguration;
@@ -34,24 +28,24 @@ public class GatewayApplication {
34 28
      *      * 反之,就是非简单跨域,此跨域有一个预检机制,说直白点,就是会发两次请求,一次OPTIONS请求,一次真正的请求
35 29
      *     
36 30
      */
37
-//    @Bean
38
-//    public CorsFilter corsFilter() {
39
-//        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
40
-//        final CorsConfiguration config = new CorsConfiguration();
41
-//        config.setAllowCredentials(true); // 允许cookies跨域
42
-//        config.addAllowedOrigin("*");// #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
43
-//        config.addAllowedHeader("*");// #允许访问的头信息,*表示全部
44
-//        config.setMaxAge(18000L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
45
-//        config.addAllowedMethod("OPTIONS");// 允许提交请求的方法,*表示全部允许
46
-//        config.addAllowedMethod("HEAD");
47
-//        config.addAllowedMethod("GET");// 允许Get的请求方法
48
-//        config.addAllowedMethod("PUT");
49
-//        config.addAllowedMethod("POST");
50
-//        config.addAllowedMethod("DELETE");
51
-//        config.addAllowedMethod("PATCH");
52
-//        source.registerCorsConfiguration("/**", config);
53
-//        return new CorsFilter(source);
54
-//    }
31
+    @Bean
32
+    public CorsFilter corsFilter() {
33
+        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
34
+        final CorsConfiguration config = new CorsConfiguration();
35
+        config.setAllowCredentials(true); // 允许cookies跨域
36
+        config.addAllowedOrigin("*");// #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
37
+        config.addAllowedHeader("*");// #允许访问的头信息,*表示全部
38
+        config.setMaxAge(18000L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
39
+        config.addAllowedMethod("OPTIONS");// 允许提交请求的方法,*表示全部允许
40
+        config.addAllowedMethod("HEAD");
41
+        config.addAllowedMethod("GET");// 允许Get的请求方法
42
+        config.addAllowedMethod("PUT");
43
+        config.addAllowedMethod("POST");
44
+        config.addAllowedMethod("DELETE");
45
+        config.addAllowedMethod("PATCH");
46
+        source.registerCorsConfiguration("/**", config);
47
+        return new CorsFilter(source);
48
+    }
55 49
 
56 50
 
57 51
 }

+ 3
- 1
CODE/smart-community/gateway/src/main/java/com/community/huiju/config/HttpSessionConfig.java Vedi File

@@ -2,13 +2,14 @@ package com.community.huiju.config;
2 2
 
3 3
 import org.springframework.context.annotation.Bean;
4 4
 import org.springframework.context.annotation.Configuration;
5
+import org.springframework.session.MapSession;
5 6
 import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession;
6 7
 import org.springframework.session.web.http.HeaderHttpSessionIdResolver;
7 8
 import org.springframework.session.web.http.HttpSessionIdResolver;
8 9
 
9 10
 
10 11
 @Configuration
11
-@EnableJdbcHttpSession
12
+@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS*48*7)
12 13
 public class HttpSessionConfig {
13 14
 
14 15
     @Bean
@@ -16,4 +17,5 @@ public class HttpSessionConfig {
16 17
         return HeaderHttpSessionIdResolver.xAuthToken();
17 18
     }
18 19
 
20
+
19 21
 }

+ 18
- 0
CODE/smart-community/gateway/src/main/java/com/community/huiju/exception/WisdomSecurityException.java Vedi File

@@ -0,0 +1,18 @@
1
+package com.community.huiju.exception;
2
+
3
+import org.springframework.security.core.AuthenticationException;
4
+
5
+/**
6
+ * @author weiximei
7
+ */
8
+public class WisdomSecurityException extends AuthenticationException {
9
+
10
+
11
+    public WisdomSecurityException(String msg, Throwable t) {
12
+        super(msg, t);
13
+    }
14
+
15
+    public WisdomSecurityException(String msg) {
16
+        super(msg);
17
+    }
18
+}

+ 11
- 2
CODE/smart-community/gateway/src/main/resources/bootstrap.yml Vedi File

@@ -5,19 +5,29 @@ spring:
5 5
     name: gateway-server
6 6
   cloud:
7 7
     config:
8
-      name: gateway
8
+      name: zuul #gateway
9 9
       profile: test
10 10
       label: master
11 11
 #      uri: http://localhost:7001/
12 12
       discovery:
13 13
         enabled: true
14 14
         serviceId: config-server
15
+    gateway:
16
+      default-filters: SaveSession
17
+      discovery:
18
+        locator:
19
+          enabled: true
15 20
   session:
16 21
     store-type: none
17 22
   servlet:
18 23
     multipart:
19 24
       max-file-size: 10MB
20 25
       max-request-size: 50MB
26
+#  datasource:
27
+#    driver-class-name: com.mysql.jdbc.Driver
28
+#    url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/smart_community_dev?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
29
+#    username: root
30
+#    password: DQ@0lW##kBb2+-jPZC1s$Ma0h5$9W((q
21 31
 eureka:
22 32
   client:
23 33
     service-url:
@@ -45,4 +55,3 @@ mybatis:
45 55
   configuration:
46 56
     call-setters-on-nulls: true
47 57
 
48
-

+ 3
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ImageServiceimpl.java Vedi File

@@ -38,6 +38,9 @@ public class ImageServiceimpl implements ImageServiceI {
38 38
         ossClient.shutdown();
39 39
         Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
40 40
         String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
41
+
42
+        // 截取掉签名
43
+        url = url.substring(0, url.lastIndexOf("&Signature"));
41 44
         return url;
42 45
     }
43 46
 }

+ 3
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/ImageServiceimpl.java Vedi File

@@ -38,6 +38,9 @@ public class ImageServiceimpl implements ImageServiceI {
38 38
         ossClient.shutdown();
39 39
         Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
40 40
         String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
41
+
42
+        // 截取掉签名
43
+        url = url.substring(0, url.lastIndexOf("&Signature"));
41 44
         return url;
42 45
     }
43 46
 }