parent
530a92a3ea
commit
a08313ea81
@ -1,34 +1,35 @@ |
||||
* [首页](/?t=1571107529420) |
||||
* [首页](/?t=1572076365237) |
||||
* 开发文档 |
||||
* [快速体验](files/10010_快速体验.md?t=1571107529423) |
||||
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1571107529447) |
||||
* [新增接口](files/10020_新增接口.md?t=1571107529447) |
||||
* [开发流程](files/10021_开发流程.md?t=1571107529447) |
||||
* [业务参数校验](files/10030_业务参数校验.md?t=1571107529447) |
||||
* [错误处理](files/10040_错误处理.md?t=1571107529447) |
||||
* [编写文档](files/10041_编写文档.md?t=1571107529447) |
||||
* [接口交互详解](files/10050_接口交互详解.md?t=1571107529448) |
||||
* [easyopen支持](files/10070_easyopen支持.md?t=1571107529448) |
||||
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1571107529448) |
||||
* [ISV管理](files/10085_ISV管理.md?t=1571107529448) |
||||
* [自定义返回结果](files/10087_自定义返回结果.md?t=1571107529448) |
||||
* [自定义过滤器](files/10088_自定义过滤器.md?t=1571107529448) |
||||
* [路由授权](files/10090_路由授权.md?t=1571107529448) |
||||
* [接口限流](files/10092_接口限流.md?t=1571107529448) |
||||
* [监控日志](files/10093_监控日志.md?t=1571107529448) |
||||
* [SDK开发](files/10095_SDK开发.md?t=1571107529449) |
||||
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1571107529449) |
||||
* [应用授权](files/10097_应用授权.md?t=1571107529449) |
||||
* [提供restful接口](files/10100_提供restful接口.md?t=1571107529449) |
||||
* [文件上传](files/10104_文件上传.md?t=1571107529449) |
||||
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1571107529449) |
||||
* [预发布灰度发布](files/10110_预发布灰度发布.md?t=1571107529449) |
||||
* [动态修改请求参数](files/10111_动态修改请求参数.md?t=1571107529450) |
||||
* [使用eureka](files/10112_使用eureka.md?t=1571107529450) |
||||
* [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1571107529450) |
||||
* [快速体验](files/10010_快速体验.md?t=1572076365239) |
||||
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1572076365257) |
||||
* [新增接口](files/10020_新增接口.md?t=1572076365257) |
||||
* [开发流程](files/10021_开发流程.md?t=1572076365257) |
||||
* [业务参数校验](files/10030_业务参数校验.md?t=1572076365258) |
||||
* [错误处理](files/10040_错误处理.md?t=1572076365258) |
||||
* [编写文档](files/10041_编写文档.md?t=1572076365258) |
||||
* [接口交互详解](files/10050_接口交互详解.md?t=1572076365258) |
||||
* [easyopen支持](files/10070_easyopen支持.md?t=1572076365258) |
||||
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1572076365258) |
||||
* [ISV管理](files/10085_ISV管理.md?t=1572076365258) |
||||
* [自定义返回结果](files/10087_自定义返回结果.md?t=1572076365259) |
||||
* [自定义过滤器](files/10088_自定义过滤器.md?t=1572076365259) |
||||
* [自定义校验token](files/10089_自定义校验token.md?t=1572076365259) |
||||
* [路由授权](files/10090_路由授权.md?t=1572076365259) |
||||
* [接口限流](files/10092_接口限流.md?t=1572076365259) |
||||
* [监控日志](files/10093_监控日志.md?t=1572076365259) |
||||
* [SDK开发](files/10095_SDK开发.md?t=1572076365259) |
||||
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1572076365260) |
||||
* [应用授权](files/10097_应用授权.md?t=1572076365260) |
||||
* [提供restful接口](files/10100_提供restful接口.md?t=1572076365260) |
||||
* [文件上传](files/10104_文件上传.md?t=1572076365260) |
||||
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1572076365260) |
||||
* [预发布灰度发布](files/10110_预发布灰度发布.md?t=1572076365261) |
||||
* [动态修改请求参数](files/10111_动态修改请求参数.md?t=1572076365261) |
||||
* [使用eureka](files/10112_使用eureka.md?t=1572076365261) |
||||
* [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1572076365261) |
||||
* 原理分析 |
||||
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1571107529450) |
||||
* [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1571107529450) |
||||
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1571107529450) |
||||
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1571107529450) |
||||
* [常见问题](files/90100_常见问题.md?t=1571107529450) |
||||
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1572076365261) |
||||
* [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1572076365261) |
||||
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1572076365261) |
||||
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1572076365262) |
||||
* [常见问题](files/90100_常见问题.md?t=1572076365262) |
||||
|
@ -0,0 +1,54 @@ |
||||
# 自定义校验token(2.5.0) |
||||
|
||||
从2.5.0开始在`@ApiMapping`注解中新增了一个属性`needToken`,用来告诉网关是否校验token |
||||
|
||||
```java |
||||
/** |
||||
* 是否需要appAuthToken,设置为true,网关端会校验token是否存在 |
||||
*/ |
||||
boolean needToken() default false; |
||||
``` |
||||
|
||||
使用方式: |
||||
|
||||
```java |
||||
@ApiMapping(value = "story.token.get", needToken = true/* 设置true,网关会校验token是否存在 */) |
||||
public StoryResult token(StoryParam story) { |
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext(); |
||||
String appAuthToken = openContext.getAppAuthToken(); |
||||
StoryResult result = new StoryResult(); |
||||
result.setName("appAuthToken:" + appAuthToken); |
||||
return result; |
||||
} |
||||
``` |
||||
|
||||
指定了needToken=true后,网关会判断客户端是否传了`app_auth_token`参数,没有传则返回错误信息。 |
||||
|
||||
网关默认简单校验参数值是否存在,如果要校验有效性,需要自己实现。 |
||||
|
||||
自己实现步骤: |
||||
|
||||
- 在ZuulConfig类中重写`doAfter`方法 |
||||
- 设置`ApiConfig中的tokenValidator属性` |
||||
|
||||
`TokenValidator`是一个函数式接口,可以直接使用Lambda表达式,示例代码如下: |
||||
|
||||
```java |
||||
public class ZuulConfig extends AlipayZuulConfiguration { |
||||
|
||||
@Override |
||||
protected void doAfter() { |
||||
ApiConfig.getInstance().setTokenValidator(apiParam -> { |
||||
// 获取客户端传递过来的token |
||||
String token = apiParam.fetchAccessToken(); |
||||
if (StringUtils.isBlank(token)) { |
||||
return false; |
||||
} |
||||
// TODO: 校验token有效性,可以从redis中读取 |
||||
|
||||
// 返回true表示这个token真实、有效 |
||||
return true; |
||||
}); |
||||
} |
||||
} |
||||
``` |
@ -0,0 +1 @@ |
||||
ALTER TABLE `sop`.`config_service_route` ADD COLUMN `need_token` TINYINT NOT NULL DEFAULT 0 COMMENT '是否需要token' AFTER `permission`; |
@ -1 +1 @@ |
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.c6dfb7ee.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,a=n[0],f=n[1],i=n[2],d=0,l=[];d<a.length;d++)c=a[d],u[c]&&l.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);h&&h(n);while(l.length)l.shift()();return o.push.apply(o,i||[]),t()}function t(){for(var e,n=0;n<o.length;n++){for(var t=o[n],r=!0,c=1;c<t.length;c++){var a=t[c];0!==u[a]&&(r=!1)}r&&(o.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},o=[];function a(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-0faf9ba2":"88458f58","chunk-25908fca":"05d6b15b","chunk-2c1f2e8f":"f092c0a0","chunk-2d2085ef":"91d75f3c","chunk-2d221c34":"20057287","chunk-4de1c2b6":"e74e3d03","chunk-6f78c9fe":"3ac83b41","chunk-73b2dcec":"05b5ee28","chunk-9b31c83a":"e60adb43","chunk-9f479afe":"0d0ed757","chunk-c3ce42fe":"9517b588"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-0faf9ba2":1,"chunk-25908fca":1,"chunk-2c1f2e8f":1,"chunk-4de1c2b6":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-c3ce42fe":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-0faf9ba2":"ed1510dd","chunk-25908fca":"89ab33e8","chunk-2c1f2e8f":"0314067f","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-4de1c2b6":"a37cd815","chunk-6f78c9fe":"31d6cfe0","chunk-73b2dcec":"99cf6327","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-c3ce42fe":"6b789903"}[e]+".css",u=f.p+r,o=document.getElementsByTagName("link"),a=0;a<o.length;a++){var i=o[a],d=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(d===r||d===u))return n()}var l=document.getElementsByTagName("style");for(a=0;a<l.length;a++){i=l[a],d=i.getAttribute("data-href");if(d===r||d===u)return n()}var h=document.createElement("link");h.rel="stylesheet",h.type="text/css",h.onload=n,h.onerror=function(n){var r=n&&n.target&&n.target.src||u,o=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");o.code="CSS_CHUNK_LOAD_FAILED",o.request=r,delete c[e],h.parentNode.removeChild(h),t(o)},h.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(h)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var o=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=o);var i,d=document.createElement("script");d.charset="utf-8",d.timeout=120,f.nc&&d.setAttribute("nonce",f.nc),d.src=a(e),i=function(n){d.onerror=d.onload=null,clearTimeout(l);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,o=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");o.type=r,o.request=c,t[1](o)}u[e]=void 0}};var l=setTimeout(function(){i({type:"timeout",target:d})},12e4);d.onerror=d.onload=i,document.head.appendChild(d)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],d=i.push.bind(i);i.push=n,i=i.slice();for(var l=0;l<i.length;l++)n(i[l]);var h=d;t()})([]);</script><script src=static/js/chunk-elementUI.298ac98c.js></script><script src=static/js/chunk-libs.75deb05f.js></script><script src=static/js/app.f05d6d01.js></script></body></html> |
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.c6dfb7ee.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,a=n[0],f=n[1],i=n[2],d=0,l=[];d<a.length;d++)c=a[d],u[c]&&l.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);h&&h(n);while(l.length)l.shift()();return o.push.apply(o,i||[]),t()}function t(){for(var e,n=0;n<o.length;n++){for(var t=o[n],r=!0,c=1;c<t.length;c++){var a=t[c];0!==u[a]&&(r=!1)}r&&(o.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},o=[];function a(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-0faf9ba2":"88458f58","chunk-25908fca":"05d6b15b","chunk-2c1f2e8f":"f092c0a0","chunk-2d2085ef":"91d75f3c","chunk-2d221c34":"20057287","chunk-4de1c2b6":"e74e3d03","chunk-6f78c9fe":"3ac83b41","chunk-73b2dcec":"05b5ee28","chunk-9b31c83a":"52bc6b2c","chunk-9f479afe":"0d0ed757","chunk-c3ce42fe":"9517b588"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-0faf9ba2":1,"chunk-25908fca":1,"chunk-2c1f2e8f":1,"chunk-4de1c2b6":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-c3ce42fe":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-0faf9ba2":"ed1510dd","chunk-25908fca":"89ab33e8","chunk-2c1f2e8f":"0314067f","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-4de1c2b6":"a37cd815","chunk-6f78c9fe":"31d6cfe0","chunk-73b2dcec":"99cf6327","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-c3ce42fe":"6b789903"}[e]+".css",u=f.p+r,o=document.getElementsByTagName("link"),a=0;a<o.length;a++){var i=o[a],d=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(d===r||d===u))return n()}var l=document.getElementsByTagName("style");for(a=0;a<l.length;a++){i=l[a],d=i.getAttribute("data-href");if(d===r||d===u)return n()}var h=document.createElement("link");h.rel="stylesheet",h.type="text/css",h.onload=n,h.onerror=function(n){var r=n&&n.target&&n.target.src||u,o=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");o.code="CSS_CHUNK_LOAD_FAILED",o.request=r,delete c[e],h.parentNode.removeChild(h),t(o)},h.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(h)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var o=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=o);var i,d=document.createElement("script");d.charset="utf-8",d.timeout=120,f.nc&&d.setAttribute("nonce",f.nc),d.src=a(e),i=function(n){d.onerror=d.onload=null,clearTimeout(l);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,o=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");o.type=r,o.request=c,t[1](o)}u[e]=void 0}};var l=setTimeout(function(){i({type:"timeout",target:d})},12e4);d.onerror=d.onload=i,document.head.appendChild(d)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],d=i.push.bind(i);i.push=n,i=i.slice();for(var l=0;l<i.length;l++)n(i[l]);var h=d;t()})([]);</script><script src=static/js/chunk-elementUI.298ac98c.js></script><script src=static/js/chunk-libs.75deb05f.js></script><script src=static/js/app.f05d6d01.js></script></body></html> |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,46 +0,0 @@ |
||||
package com.gitee.sop.gatewaycommon.bean; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* @author tanghc |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
public class BaseRouteDefinition { |
||||
|
||||
/** |
||||
* 路由的Id |
||||
*/ |
||||
private String id; |
||||
/** |
||||
* 路由规则转发的目标uri |
||||
*/ |
||||
private String uri; |
||||
|
||||
/** |
||||
* uri后面跟的path |
||||
*/ |
||||
private String path; |
||||
|
||||
/** |
||||
* 路由执行的顺序 |
||||
*/ |
||||
private int order = 0; |
||||
|
||||
/** |
||||
* 是否忽略验证,业务参数验证除外 |
||||
*/ |
||||
private int ignoreValidate; |
||||
|
||||
/** |
||||
* 是否合并结果 |
||||
*/ |
||||
private int mergeResult; |
||||
|
||||
/** |
||||
* 接口是否需要授权才能访问 |
||||
*/ |
||||
private int permission; |
||||
} |
@ -1,19 +0,0 @@ |
||||
package com.gitee.sop.gatewaycommon.bean; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author tanghc |
||||
*/ |
||||
@Data |
||||
public class BaseServiceRouteInfo<T extends BaseRouteDefinition> { |
||||
private String serviceId; |
||||
private List<T> routeDefinitionList = Collections.emptyList(); |
||||
|
||||
public String fetchServiceIdLowerCase() { |
||||
return this.serviceId.toLowerCase(); |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
package com.gitee.sop.gatewaycommon.validate; |
||||
|
||||
import com.gitee.sop.gatewaycommon.param.ApiParam; |
||||
|
||||
/** |
||||
* @author tanghc |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface TokenValidator { |
||||
boolean validateToken(ApiParam apiParam); |
||||
} |
@ -0,0 +1,28 @@ |
||||
package com.gitee.sop.storyweb.controller; |
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping; |
||||
import com.gitee.sop.servercommon.bean.OpenContext; |
||||
import com.gitee.sop.servercommon.bean.ServiceContext; |
||||
import com.gitee.sop.storyweb.controller.param.StoryParam; |
||||
import com.gitee.sop.storyweb.controller.result.StoryResult; |
||||
import io.swagger.annotations.Api; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @author tanghc |
||||
*/ |
||||
@RestController |
||||
@Slf4j |
||||
@Api(tags = "故事接口") |
||||
public class TokenController { |
||||
|
||||
@ApiMapping(value = "story.token.get", needToken = true/* 设置true,网关会校验token是否存在 */) |
||||
public StoryResult token(StoryParam story) { |
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext(); |
||||
String appAuthToken = openContext.getAppAuthToken(); |
||||
StoryResult result = new StoryResult(); |
||||
result.setName("appAuthToken:" + appAuthToken); |
||||
return result; |
||||
} |
||||
} |
Loading…
Reference in new issue