From c03c86fb5544996508e8a5128129450556c635fb Mon Sep 17 00:00:00 2001 From: wangkang Date: Tue, 23 May 2017 10:10:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0rms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/egridcloud/udf/rms/Rms.java | 28 ++++--------- .../udf/rms/RmsAuthHandlerInterceptor.java | 24 ++++++------ .../com/egridcloud/udf/rms/RmsProperties.java | 39 ++++--------------- .../{AuthMate.java => ApplicationMate.java} | 29 ++++++++++++-- .../mate/{PathMate.java => ServiceMate.java} | 6 +-- 5 files changed, 57 insertions(+), 69 deletions(-) rename udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/{AuthMate.java => ApplicationMate.java} (73%) rename udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/{PathMate.java => ServiceMate.java} (89%) diff --git a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/Rms.java b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/Rms.java index 1648ab4..4e63c5d 100644 --- a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/Rms.java +++ b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/Rms.java @@ -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(); } diff --git a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsAuthHandlerInterceptor.java b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsAuthHandlerInterceptor.java index ce23be4..5e3449c 100644 --- a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsAuthHandlerInterceptor.java +++ b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsAuthHandlerInterceptor.java @@ -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); diff --git a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsProperties.java b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsProperties.java index e2cefa9..67196ca 100644 --- a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsProperties.java +++ b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/RmsProperties.java @@ -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 application; + private Map application; /** * 描述 : 服务路径(服务编号 : 服务元数据) */ - private Map service; - - /** - * 描述 : 认证(应用名称 : 权限元数据) - */ - private Map authorization; + private Map service; /** * 描述 : 获取application * * @return the application */ - public Map getApplication() { + public Map getApplication() { return application; } @@ -53,7 +48,7 @@ public class RmsProperties { * * @param application the application to set */ - public void setApplication(Map application) { + public void setApplication(Map application) { this.application = application; } @@ -62,7 +57,7 @@ public class RmsProperties { * * @return the service */ - public Map getService() { + public Map getService() { return service; } @@ -71,26 +66,8 @@ public class RmsProperties { * * @param service the service to set */ - public void setService(Map service) { + public void setService(Map service) { this.service = service; } - /** - * 描述 : 获取authorization - * - * @return the authorization - */ - public Map getAuthorization() { - return authorization; - } - - /** - * 描述 : 设置authorization - * - * @param authorization the authorization to set - */ - public void setAuthorization(Map authorization) { - this.authorization = authorization; - } - } diff --git a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/AuthMate.java b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/ApplicationMate.java similarity index 73% rename from udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/AuthMate.java rename to udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/ApplicationMate.java index 12366ef..a94248c 100644 --- a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/AuthMate.java +++ b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/ApplicationMate.java @@ -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 * diff --git a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/PathMate.java b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/ServiceMate.java similarity index 89% rename from udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/PathMate.java rename to udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/ServiceMate.java index 9d930f8..2da18da 100644 --- a/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/PathMate.java +++ b/udf-starter-rms/src/main/java/com/egridcloud/udf/rms/mate/ServiceMate.java @@ -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 { /** * 描述 : 应用名称