mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-21 05:56:49 +00:00
更新
This commit is contained in:
+26
-21
@@ -1,24 +1,29 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- maven坐标 -->
|
||||
<artifactId>udf-starter-rms</artifactId>
|
||||
<name>udf-starter-rms</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.egridcloud.com</url>
|
||||
<!-- 父依赖 -->
|
||||
<parent>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- udf-core-starter -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- maven坐标 -->
|
||||
<artifactId>udf-starter-rms</artifactId>
|
||||
<name>udf-starter-rms</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.egridcloud.com</url>
|
||||
<!-- 父依赖 -->
|
||||
<parent>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- udf-core-starter -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
</dependency>
|
||||
<!-- zuul-core -->
|
||||
<dependency>
|
||||
<groupId>com.netflix.zuul</groupId>
|
||||
<artifactId>zuul-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -45,7 +45,7 @@ public class RmsConfig {
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
@Primary
|
||||
RestTemplate restTemplate(ClientHttpRequestFactory requestFactory) {
|
||||
public RestTemplate restTemplate(ClientHttpRequestFactory requestFactory) {
|
||||
return new RestTemplate(requestFactory);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.itkk.udf.rms;
|
||||
|
||||
import com.netflix.zuul.ZuulFilter;
|
||||
import com.netflix.zuul.context.RequestContext;
|
||||
import org.itkk.udf.core.exception.AuthException;
|
||||
import org.itkk.udf.rms.meta.ApplicationMeta;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
/**
|
||||
* RmsFilter
|
||||
*/
|
||||
public class RmsFilter extends ZuulFilter {
|
||||
|
||||
/**
|
||||
* 描述 : 应用名称
|
||||
*/
|
||||
@Value("${spring.application.name}")
|
||||
private String springApplicationName;
|
||||
|
||||
/**
|
||||
* 描述 : 配置
|
||||
*/
|
||||
@Autowired
|
||||
private RmsProperties rmsProperties;
|
||||
|
||||
@Override
|
||||
public Object run() {
|
||||
//获得request
|
||||
RequestContext ctx = RequestContext.getCurrentContext();
|
||||
//获得应用元数据
|
||||
ApplicationMeta applicationMeta = rmsProperties.getApplication().get(springApplicationName);
|
||||
//判空
|
||||
if (applicationMeta == null) {
|
||||
throw new AuthException("unrecognized systemTag:" + springApplicationName);
|
||||
}
|
||||
//获得secret
|
||||
String secret = applicationMeta.getSecret();
|
||||
//计算sign
|
||||
String sign = Constant.sign(springApplicationName, secret);
|
||||
//设置头
|
||||
ctx.addZuulRequestHeader(Constant.HEADER_RMS_APPLICATION_NAME_CODE, springApplicationName);
|
||||
ctx.addZuulRequestHeader(Constant.HEADER_RMS_SIGN_CODE, sign);
|
||||
//执行
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String filterType() {
|
||||
return "pre";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int filterOrder() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user