-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from backkoms/develop
Develop
- Loading branch information
Showing
38 changed files
with
2,575 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
spring.rabbitmq.host=localhost | ||
spring.rabbitmq.port=5672 | ||
spring.rabbitmq.username=guest | ||
spring.rabbitmq.password=guest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## 动态路由 | ||
使用eureka的自动服务发现,自动映射到后端对应的服务,免去了手动映射的麻烦。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...rv/zuul-server/src/main/java/com/simplemall/micro/serv/zuul/filter/AccessTokenFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.simplemall.micro.serv.zuul.filter; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.netflix.zuul.ZuulFilter; | ||
import com.netflix.zuul.context.RequestContext; | ||
|
||
/** | ||
* token过滤器,校验token必输项方法,token不能为空 | ||
* | ||
* @author guooo | ||
* | ||
*/ | ||
@Component | ||
public class AccessTokenFilter extends ZuulFilter { | ||
|
||
private static Logger log = LoggerFactory.getLogger(AccessTokenFilter.class); | ||
|
||
/* | ||
* 过滤器的具体逻辑。可用很复杂,包括查sql,nosql去判断该请求到底有没有权限访问。 | ||
* | ||
* @see com.netflix.zuul.IZuulFilter#run() | ||
*/ | ||
@Override | ||
public Object run() { | ||
//TODO 可将Front-app服务中的APISecurityCheck中针对accessToken的校验迁移至此,提前验证 | ||
RequestContext ctx = RequestContext.getCurrentContext(); | ||
HttpServletRequest request = ctx.getRequest(); | ||
log.info(String.format("%s >>> %s", request.getMethod(), request.getRequestURL().toString())); | ||
Object accessToken = request.getParameter("accessToken"); | ||
if(accessToken == null) { | ||
log.warn("token is empty"); | ||
ctx.setSendZuulResponse(false); | ||
ctx.setResponseStatusCode(401); | ||
try { | ||
ctx.getResponse().getWriter().write("token is empty"); | ||
}catch (Exception e){} | ||
|
||
return null; | ||
} | ||
log.info("ok"); | ||
return null; | ||
} | ||
|
||
/* | ||
* 这里可以写逻辑判断,是否要过滤,本文true,永远过滤。 | ||
* | ||
* @see com.netflix.zuul.IZuulFilter#shouldFilter() | ||
*/ | ||
@Override | ||
public boolean shouldFilter() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int filterOrder() { | ||
return 0; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) pre:路由之前 routing:路由之时 post: 路由之后 error:发送错误调用 | ||
* | ||
* @see com.netflix.zuul.ZuulFilter#filterType() | ||
*/ | ||
@Override | ||
public String filterType() { | ||
return "pre"; | ||
} | ||
|
||
} |
23 changes: 17 additions & 6 deletions
23
base-serv/zuul-server/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
server.port=9005 | ||
logging.level.tk.mybatis=TRACE | ||
spring.application.name=zuul-server | ||
spring.mvc.view.prefix=/templates/ | ||
spring.mvc.view.suffix=.ftl | ||
spring.freemarker.cache=false | ||
spring.freemarker.request-context-attribute=request | ||
|
||
eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ | ||
|
||
spring.boot.admin.url=http://localhost:9002 | ||
|
||
#Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} | ||
#Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} | ||
#resolved up problems | ||
management.security.enabled=false | ||
management.security.enabled=false | ||
|
||
|
||
# routes to serviceId,simple cases,wo usually use eureka client to discovery the service instead of to configure it like down below | ||
#zuul.routes.account.path=/acc/** | ||
#zuul.routes.account.serviceId=ACCOUNT-SERVICE | ||
|
||
#zuul.routes.product.path=/prd/** | ||
#zuul.routes.product.serviceId=product-service | ||
|
||
#zuul.routes.pay.path=/pay/** | ||
#zuul.routes.pay.serviceId=payment-service | ||
|
||
#zuul.routes.order.path=/order/** | ||
#zuul.routes.order.serviceId=order-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.