Skip to content

Commit 15a16ed

Browse files
committed
[taotao-cloud-project-1248] update uc security es moule
1 parent b2e6a30 commit 15a16ed

File tree

75 files changed

+738
-3108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+738
-3108
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ buildscript {
2020
reactorVersion = '3.4.3'
2121
servletApiVersion = '4.0.1'
2222
bannerVersion = "1.0.2"
23-
lombokVersion = '1.18.18'
23+
lombokVersion = '1.18.20'
2424
javassistVersion = '3.27.0-GA'
2525
easyCaptchaVersion = '1.6.2'
2626
hutoolVersion = '5.5.9'

taotao-cloud-microservice/taotao-cloud-gateway/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.5.9'
2727
implementation 'org.springdoc:springdoc-openapi-webflux-core:1.5.9'
2828
implementation 'com.github.xiaoymin:knife4j-springdoc-ui:3.0.3'
29+
implementation 'com.github.xiaoymin:knife4j-spring-boot-starter:3.0.3'
2930

3031
implementation "org.apache.commons:commons-pool2"
3132
implementation "org.apache.commons:commons-lang3"

taotao-cloud-microservice/taotao-cloud-gateway/src/main/java/com/taotao/cloud/gateway/configuration/DynamicRouteConfiguration.java

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@
3030
import java.util.ArrayList;
3131
import java.util.List;
3232
import java.util.concurrent.Executor;
33+
import org.springframework.beans.factory.annotation.Autowired;
3334
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3435
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
3536
import org.springframework.cloud.gateway.route.RouteDefinition;
37+
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
3638
import org.springframework.cloud.gateway.route.RouteDefinitionRepository;
39+
import org.springframework.cloud.gateway.route.RouteDefinitionWriter;
3740
import org.springframework.context.ApplicationEventPublisher;
41+
import org.springframework.context.ApplicationEventPublisherAware;
3842
import org.springframework.context.annotation.Bean;
3943
import org.springframework.context.annotation.Configuration;
44+
import org.springframework.stereotype.Component;
4045
import reactor.core.publisher.Flux;
4146
import reactor.core.publisher.Mono;
4247

@@ -147,4 +152,104 @@ private List<RouteDefinition> getListByStr(String content) {
147152
}
148153
}
149154

155+
/**
156+
* 动态更新路由网关service 1)实现一个Spring提供的事件推送接口ApplicationEventPublisherAware
157+
* 2)提供动态路由的基础方法,可通过获取bean操作该类的方法。该类提供新增路由、更新路由、删除路由,然后实现发布的功能。
158+
*/
159+
@Component
160+
public class DynamicRouteComponent implements ApplicationEventPublisherAware {
161+
162+
@Autowired
163+
private RouteDefinitionWriter routeDefinitionWriter;
164+
@Autowired
165+
private RouteDefinitionLocator routeDefinitionLocator;
166+
167+
/**
168+
* 发布事件
169+
*/
170+
@Autowired
171+
private ApplicationEventPublisher publisher;
172+
173+
@Override
174+
public void setApplicationEventPublisher(
175+
ApplicationEventPublisher applicationEventPublisher) {
176+
this.publisher = applicationEventPublisher;
177+
}
178+
179+
/**
180+
* 删除路由
181+
*
182+
* @param id
183+
* @return
184+
*/
185+
public String delete(String id) {
186+
try {
187+
LogUtil.info("gateway delete route id {}", id);
188+
this.routeDefinitionWriter.delete(Mono.just(id)).subscribe();
189+
this.publisher.publishEvent(new RefreshRoutesEvent(this));
190+
return "delete success";
191+
} catch (Exception e) {
192+
return "delete fail";
193+
}
194+
}
195+
196+
/**
197+
* 更新路由
198+
*
199+
* @param definitions
200+
* @return
201+
*/
202+
public String updateList(List<RouteDefinition> definitions) {
203+
LogUtil.info("gateway update route {}", definitions);
204+
// 删除缓存routerDefinition
205+
List<RouteDefinition> routeDefinitionsExits = routeDefinitionLocator.getRouteDefinitions()
206+
.buffer().blockFirst();
207+
if (!CollUtil.isEmpty(routeDefinitionsExits)) {
208+
routeDefinitionsExits.forEach(routeDefinition -> {
209+
LogUtil.info("delete routeDefinition:{}", routeDefinition);
210+
delete(routeDefinition.getId());
211+
});
212+
}
213+
definitions.forEach(definition -> {
214+
updateById(definition);
215+
});
216+
return "success";
217+
}
218+
219+
/**
220+
* 更新路由
221+
*
222+
* @param definition
223+
* @return
224+
*/
225+
public String updateById(RouteDefinition definition) {
226+
try {
227+
LogUtil.info("gateway update route {}", definition);
228+
this.routeDefinitionWriter.delete(Mono.just(definition.getId()));
229+
} catch (Exception e) {
230+
return "update fail,not find route routeId: " + definition.getId();
231+
}
232+
try {
233+
routeDefinitionWriter.save(Mono.just(definition)).subscribe();
234+
this.publisher.publishEvent(new RefreshRoutesEvent(this));
235+
return "success";
236+
} catch (Exception e) {
237+
return "update route fail";
238+
}
239+
}
240+
241+
/**
242+
* 增加路由
243+
*
244+
* @param definition
245+
* @return
246+
*/
247+
public String add(RouteDefinition definition) {
248+
LogUtil.info("gateway add route {}", definition);
249+
routeDefinitionWriter.save(Mono.just(definition)).subscribe();
250+
this.publisher.publishEvent(new RefreshRoutesEvent(this));
251+
return "success";
252+
}
253+
}
254+
150255
}

taotao-cloud-microservice/taotao-cloud-gateway/src/main/java/com/taotao/cloud/gateway/configuration/HttpsConfiguration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import javax.annotation.PostConstruct;
2020
import javax.annotation.PreDestroy;
2121
import javax.annotation.Resource;
22-
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.beans.factory.annotation.Value;
2422
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2523
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
2624
import org.springframework.boot.web.server.WebServer;
@@ -35,7 +33,7 @@
3533
* @since 2020/4/29 22:11
3634
*/
3735
@Configuration
38-
@ConditionalOnProperty(prefix = HttpsProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
36+
@ConditionalOnProperty(prefix = HttpsProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = false)
3937
public class HttpsConfiguration {
4038

4139
@Resource

taotao-cloud-microservice/taotao-cloud-gateway/src/main/java/com/taotao/cloud/gateway/configuration/OpenApiConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.taotao.cloud.gateway.configuration;
1717

18+
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
1819
import com.taotao.cloud.common.utils.LogUtil;
1920
import io.swagger.v3.oas.models.Components;
2021
import io.swagger.v3.oas.models.ExternalDocumentation;
@@ -44,6 +45,7 @@
4445
* @version 1.0.0
4546
* @since 2021/03/04 13:48
4647
*/
48+
@EnableKnife4j
4749
@Component
4850
public class OpenApiConfiguration {
4951

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.taotao.cloud.gateway.rule;
1+
package com.taotao.cloud.gateway.configuration;
22

33
import com.taotao.cloud.gateway.service.IRuleCacheService;
44
import com.taotao.cloud.gateway.service.impl.RuleCacheServiceImpl;
@@ -15,4 +15,5 @@ public class RuleConfiguration {
1515
public IRuleCacheService ruleCacheService() {
1616
return new RuleCacheServiceImpl();
1717
}
18+
1819
}

taotao-cloud-microservice/taotao-cloud-gateway/src/main/java/com/taotao/cloud/gateway/properties/HttpsProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class HttpsProperties {
1414
/**
1515
* 是否启用https
1616
*/
17-
private Boolean enabled = true;
17+
private Boolean enabled = false;
1818

1919
private Integer port = 9443;
2020
}

taotao-cloud-microservice/taotao-cloud-gateway/src/main/resources/application-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ taotao:
318318
group-id:
319319
filter:
320320
blacklist: true
321-
gray: true
321+
gray: false
322322
log: true
323323
sign: true
324324
trace: true

taotao-cloud-microservice/taotao-cloud-oauth2/taotao-cloud-oauth2-server/src/main/java/com/taotao/cloud/oauth2/biz/config/AuthorizationServerConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.springframework.context.annotation.Configuration;
3131
import org.springframework.core.Ordered;
3232
import org.springframework.core.annotation.Order;
33+
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
34+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
3335
import org.springframework.jdbc.core.JdbcTemplate;
3436
import org.springframework.security.config.Customizer;
3537
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -52,6 +54,8 @@
5254
* @author Joe Grandja
5355
* @author Daniel Garnier-Moiroux
5456
*/
57+
@EnableJpaAuditing
58+
@EnableJpaRepositories(basePackages = "com.example.springjdbcdemo.infrastruction")
5559
@Configuration(proxyBeanMethods = false)
5660
public class AuthorizationServerConfig {
5761

taotao-cloud-microservice/taotao-cloud-starter/taotao-cloud-starter-elasticsearch/src/main/java/com/taotao/cloud/elasticsearch/component/ElasticsearchComponent.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
import com.taotao.cloud.common.constant.StarterNameConstant;
1919
import com.taotao.cloud.common.utils.LogUtil;
20-
import com.taotao.cloud.elasticsearch.constant.ElasticsearchConstant;
20+
import com.taotao.cloud.elasticsearch.properties.ElasticsearchProperties;
2121
import com.taotao.cloud.elasticsearch.properties.RestClientPoolProperties;
22-
import lombok.extern.slf4j.Slf4j;
2322
import org.apache.http.auth.AuthScope;
2423
import org.apache.http.auth.UsernamePasswordCredentials;
2524
import org.apache.http.client.CredentialsProvider;
@@ -42,14 +41,14 @@
4241
* @version 1.0.0
4342
* @since 2020/5/3 06:47
4443
*/
45-
@ConditionalOnProperty(prefix = ElasticsearchConstant.BASE_ELASTICSEARCH_PREFIX,
46-
name = ElasticsearchConstant.ENABLED, havingValue = ElasticsearchConstant.TRUE)
44+
@ConditionalOnProperty(prefix = ElasticsearchProperties.PREFIX, name = "enabled", havingValue = "true")
4745
public class ElasticsearchComponent implements InitializingBean {
4846

4947
@Override
5048
public void afterPropertiesSet() throws Exception {
51-
LogUtil.info("[TAOTAO CLOUD][" + StarterNameConstant.TAOTAO_CLOUD_ELASTICSEARCH_STARTER + "]"
52-
+ "elasticsearch模块已启动");
49+
LogUtil.info(
50+
"[TAOTAO CLOUD][" + StarterNameConstant.TAOTAO_CLOUD_ELASTICSEARCH_STARTER + "]"
51+
+ "elasticsearch模块已启动");
5352
}
5453

5554
@Bean
@@ -62,7 +61,6 @@ public RestClientBuilderCustomizer restClientBuilderCustomizer(
6261
};
6362
}
6463

65-
6664
/**
6765
* 异步httpclient连接延时配置
6866
*

taotao-cloud-microservice/taotao-cloud-starter/taotao-cloud-starter-elasticsearch/src/main/java/com/taotao/cloud/elasticsearch/constant/ElasticsearchConstant.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

taotao-cloud-microservice/taotao-cloud-starter/taotao-cloud-starter-elasticsearch/src/main/java/com/taotao/cloud/elasticsearch/properties/ElasticsearchProperties.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.taotao.cloud.elasticsearch.properties;
1717

18-
import com.taotao.cloud.elasticsearch.constant.ElasticsearchConstant;
1918
import lombok.Data;
2019
import org.springframework.boot.context.properties.ConfigurationProperties;
2120
import org.springframework.cloud.context.config.annotation.RefreshScope;
@@ -29,9 +28,11 @@
2928
*/
3029
@Data
3130
@RefreshScope
32-
@ConfigurationProperties(prefix = ElasticsearchConstant.BASE_ELASTICSEARCH_PREFIX)
31+
@ConfigurationProperties(prefix = ElasticsearchProperties.PREFIX)
3332
public class ElasticsearchProperties {
3433

34+
public static final String PREFIX = "taotao.cloud.elasticsearch";
35+
3536
/**
3637
* Elasticsearch 总开关
3738
*/

taotao-cloud-microservice/taotao-cloud-starter/taotao-cloud-starter-elasticsearch/src/main/java/com/taotao/cloud/elasticsearch/properties/RestClientPoolProperties.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.taotao.cloud.elasticsearch.properties;
1717

18-
import com.taotao.cloud.elasticsearch.constant.ElasticsearchConstant;
1918
import lombok.Data;
2019
import org.springframework.boot.context.properties.ConfigurationProperties;
2120
import org.springframework.cloud.context.config.annotation.RefreshScope;
@@ -29,9 +28,11 @@
2928
*/
3029
@Data
3130
@RefreshScope
32-
@ConfigurationProperties(prefix = ElasticsearchConstant.BASE_ELASTICSEARCH_REST_POOL_PREFIX)
31+
@ConfigurationProperties(prefix = RestClientPoolProperties.PREFIX)
3332
public class RestClientPoolProperties {
3433

34+
public static final String PREFIX = "taotao.cloud.elasticsearch.rest-pool";
35+
3536
/**
3637
* 链接建立超时时间
3738
*/

taotao-cloud-microservice/taotao-cloud-starter/taotao-cloud-starter-file/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dependencies {
2-
implementation project(':taotao-cloud-microservice:taotao-cloud-starter:taotao-cloud-starter-common')
2+
api project(':taotao-cloud-microservice:taotao-cloud-starter:taotao-cloud-starter-common')
33

44
api 'com.upyun:java-sdk'
55
api 'com.qiniu:qiniu-java-sdk'

taotao-cloud-microservice/taotao-cloud-starter/taotao-cloud-starter-idempotent/build.gradle

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)