更新rms

This commit is contained in:
wangkang
2017-07-29 10:18:35 +08:00
parent 836a4c783e
commit c03c86fb55
5 changed files with 57 additions and 69 deletions
@@ -22,9 +22,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import com.egridcloud.udf.core.exception.PermissionException;
import com.egridcloud.udf.rms.mate.AuthMate;
import com.egridcloud.udf.rms.mate.PathMate;
import com.egridcloud.udf.rms.mate.ServiceMate;
/**
* 描述 : 远程服务
@@ -97,7 +95,7 @@ public class Rms {
* @return 请求头
*/
private HttpHeaders buildSystemTagHeaders(String serviceCode) {
String secret = rmsProperties.getAuthorization().get(springApplicationName).getSecret();
String secret = rmsProperties.getApplication().get(springApplicationName).getSecret();
HttpHeaders headers = new HttpHeaders();
headers.add(Constant.HEADER_RMS_APPLICATION_NAME_CODE, springApplicationName);
headers.add(Constant.HEADER_RMS_SIGN_CODE, Constant.sign(springApplicationName, secret));
@@ -122,22 +120,12 @@ public class Rms {
* @return url
*/
private String getRmsUrl(String serviceCode) {
//获得认证元数据
AuthMate authMate = rmsProperties.getAuthorization().get(springApplicationName);
//获取路径元数据
PathMate pathMate = rmsProperties.getService().get(springApplicationName);
//判断路径访问权限
if (!authMate.getAll()) {
if (authMate.getDisabled()) {
throw new PermissionException(springApplicationName + " is disabled");
}
if (authMate.getPurview().indexOf(serviceCode) == -1) {
throw new PermissionException("no access to this servoceCode : " + serviceCode);
}
}
StringBuilder url = new StringBuilder(pathMate.getIsHttps() ? Constant.HTTPS : Constant.HTTP);
url.append(rmsProperties.getService().get(pathMate.getApplicationName()));
url.append(pathMate.getUri());
//获取服务元数据
ServiceMate serviceMate = rmsProperties.getService().get(serviceCode);
//构建请求路径
StringBuilder url = new StringBuilder(serviceMate.getIsHttps() ? Constant.HTTPS : Constant.HTTP);
url.append(rmsProperties.getApplication().get(serviceMate.getApplicationName()).getServiceId());
url.append(serviceMate.getUri());
return url.toString();
}
@@ -20,8 +20,8 @@ import org.springframework.web.servlet.ModelAndView;
import com.egridcloud.udf.core.exception.AuthException;
import com.egridcloud.udf.core.exception.PermissionException;
import com.egridcloud.udf.rms.mate.AuthMate;
import com.egridcloud.udf.rms.mate.PathMate;
import com.egridcloud.udf.rms.mate.ApplicationMate;
import com.egridcloud.udf.rms.mate.ServiceMate;
/**
* 描述 : SystemTagAuthHandlerInterceptor
@@ -72,9 +72,9 @@ public class RmsAuthHandlerInterceptor implements HandlerInterceptor {
//判断环境(开发环境无需校验)
if (!DEV_PROFILES.equals(env.getProperty("spring.profiles.active"))) {
//判断systemTag是否有效
if (this.rmsProperties.getAuthorization().containsKey(rmsApplicationName)) {
if (this.rmsProperties.getApplication().containsKey(rmsApplicationName)) {
//获得secret
String secret = this.rmsProperties.getAuthorization().get(rmsApplicationName).getSecret();
String secret = this.rmsProperties.getApplication().get(rmsApplicationName).getSecret();
//计算sign
String sign = Constant.sign(rmsApplicationName, secret);
//比较sign
@@ -82,25 +82,25 @@ public class RmsAuthHandlerInterceptor implements HandlerInterceptor {
throw new AuthException("sign Validation failed");
}
//比较是否有调用接口的权限
AuthMate authMate = rmsProperties.getAuthorization().get(rmsApplicationName);
ApplicationMate applicationMate = rmsProperties.getApplication().get(rmsApplicationName);
//判断是否有调用所有服务的权限
if (!authMate.getAll()) {
if (!applicationMate.getAll()) {
//判断是否禁止调用所有服务权限
if (authMate.getDisabled()) {
if (applicationMate.getDisabled()) {
throw new PermissionException(rmsApplicationName + " is disabled");
}
//判断是否有调用该服务的权限
if (authMate.getPurview().indexOf(rmsServiceCode) != -1) {
if (applicationMate.getPurview().indexOf(rmsServiceCode) != -1) {
//比较接口编号和服务设定的有效性
if (rmsProperties.getService().containsKey(rmsServiceCode)) {
//获得服务元数据
PathMate pathMate = rmsProperties.getService().get(rmsServiceCode);
ServiceMate serviceMate = rmsProperties.getService().get(rmsServiceCode);
//比较url和method
if (!pathMate.getUri().equals(url) || !pathMate.getMethod().equals(method)) {
throw new AuthException("url and method verification error");
if (!serviceMate.getUri().equals(url) || !serviceMate.getMethod().equals(method)) {
throw new PermissionException("url and method verification error");
}
} else {
throw new AuthException("service code not exist");
throw new PermissionException("service code not exist");
}
} else {
throw new PermissionException("no access to this servoceCode : " + rmsServiceCode);
@@ -11,8 +11,8 @@ import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import com.egridcloud.udf.rms.mate.AuthMate;
import com.egridcloud.udf.rms.mate.PathMate;
import com.egridcloud.udf.rms.mate.ApplicationMate;
import com.egridcloud.udf.rms.mate.ServiceMate;
/**
* 描述 : Config
@@ -27,24 +27,19 @@ public class RmsProperties {
/**
* 描述 : 应用清单(应用名称 : 应用地址)
*/
private Map<String, String> application;
private Map<String, ApplicationMate> application;
/**
* 描述 : 服务路径(服务编号 : 服务元数据)
*/
private Map<String, PathMate> service;
/**
* 描述 : 认证(应用名称 : 权限元数据)
*/
private Map<String, AuthMate> authorization;
private Map<String, ServiceMate> service;
/**
* 描述 : 获取application
*
* @return the application
*/
public Map<String, String> getApplication() {
public Map<String, ApplicationMate> getApplication() {
return application;
}
@@ -53,7 +48,7 @@ public class RmsProperties {
*
* @param application the application to set
*/
public void setApplication(Map<String, String> application) {
public void setApplication(Map<String, ApplicationMate> application) {
this.application = application;
}
@@ -62,7 +57,7 @@ public class RmsProperties {
*
* @return the service
*/
public Map<String, PathMate> getService() {
public Map<String, ServiceMate> getService() {
return service;
}
@@ -71,26 +66,8 @@ public class RmsProperties {
*
* @param service the service to set
*/
public void setService(Map<String, PathMate> service) {
public void setService(Map<String, ServiceMate> service) {
this.service = service;
}
/**
* 描述 : 获取authorization
*
* @return the authorization
*/
public Map<String, AuthMate> getAuthorization() {
return authorization;
}
/**
* 描述 : 设置authorization
*
* @param authorization the authorization to set
*/
public void setAuthorization(Map<String, AuthMate> authorization) {
this.authorization = authorization;
}
}
@@ -1,5 +1,5 @@
/**
* AuthMate.java
* ApplicationMate.java
* Created at 2016-12-22
* Created by Administrator
* Copyright (C) 2016 egridcloud.com, All rights reserved.
@@ -7,12 +7,17 @@
package com.egridcloud.udf.rms.mate;
/**
* 描述 : Auth元数据
* 描述 : Application元数据
*
* @author Administrator
*
*/
public class AuthMate {
public class ApplicationMate {
/**
* 描述 : 服务ID
*/
private String serviceId;
/**
* 描述 : 私钥
@@ -34,6 +39,24 @@ public class AuthMate {
*/
private Boolean disabled = false;
/**
* 描述 : 获取serviceId
*
* @return the serviceId
*/
public String getServiceId() {
return serviceId;
}
/**
* 描述 : 设置serviceId
*
* @param serviceId the serviceId to set
*/
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}
/**
* 描述 : 获取all
*
@@ -1,5 +1,5 @@
/**
* PathMate.java
* ServiceMate.java
* Created at 2016-12-22
* Created by Administrator
* Copyright (C) 2016 egridcloud.com, All rights reserved.
@@ -7,12 +7,12 @@
package com.egridcloud.udf.rms.mate;
/**
* 描述 : path元数据
* 描述 : service元数据
*
* @author Administrator
*
*/
public class PathMate {
public class ServiceMate {
/**
* 描述 : 应用名称