Skip to content

Commit

Permalink
Merge pull request #6 from backkoms/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
maventalker authored Oct 2, 2017
2 parents ae34d1e + f81c643 commit 0eaafc3
Show file tree
Hide file tree
Showing 38 changed files with 2,575 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.simplemall.account.service.IAccountService;
import com.simplemall.micro.serv.common.bean.account.Account;
import com.simplemall.micro.serv.common.constant.SystemConstants;

/**
Expand All @@ -30,9 +31,9 @@ public class AccountController {
* @return
*/
@RequestMapping(value = "login", method = {RequestMethod.GET,RequestMethod.POST})
public String login(@RequestParam("phone") String phone, @RequestParam("password") String password) {
boolean result = accountService.login(phone, password);
return result ? SystemConstants.Code.SUCCESS : SystemConstants.Code.FAIL;
public Account login(@RequestParam("phone") String phone, @RequestParam("password") String password) {
Account result = accountService.login(phone, password);
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import com.simplemall.micro.serv.common.bean.account.AccAddress;
import com.simplemall.micro.serv.common.bean.account.Account;

public interface IAccountService {

Expand All @@ -11,7 +12,7 @@ public interface IAccountService {
* @param password
* @return
*/
boolean login(String phone, String password);
Account login(String phone, String password);

/**
* @param phone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public AccAddress getAccAddress(String tid) {
}

@Override
public boolean login(String phone, String password) {
public Account login(String phone, String password) {
AccountCriteria criteria = new AccountCriteria();
criteria.createCriteria().andPhoneEqualTo(phone).andPasswordEqualTo(password);
List<Account> list = accountMapper.selectByExample(criteria);
logger.info("{}登陆成功!",phone);
return CollectionUtils.isNotEmpty(list);
return CollectionUtils.isNotEmpty(list)?list.get(0):new Account();
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions account-sevice/src/main/resources/bootstrap.properties
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
spring.boot.admin.url=http://localhost:9002

# \u8BBE\u4E3Afalse\uFF0C\u5173\u95ED\u81EA\u6211\u4FDD\u62A4
eureka.server.enable-self-preservation=false


#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
Expand Down
2 changes: 2 additions & 0 deletions base-serv/zuul-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 动态路由
使用eureka的自动服务发现,自动映射到后端对应的服务,免去了手动映射的麻烦。
6 changes: 5 additions & 1 deletion base-serv/zuul-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
Expand All @@ -28,7 +32,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;


/**
* API Gateway
*
* @author guooo
*
*/
@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication
public class ZuulServerApplication {

Expand Down
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 base-serv/zuul-server/src/main/resources/application.properties
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
4 changes: 2 additions & 2 deletions base-serv/zuul-server/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<include resource="org/springframework/boot/logging/logback/base.xml" />
<jmxConfigurator/>
<!--定义日志文件的存储地址和前缀名-->
<property name="LOG_HOME" value="F:/logs" />
<property name="LOG_PREFIX" value="micro-eureka-server" />
<property name="LOG_HOME" value="c:/dev/log4jlogs" />
<property name="LOG_PREFIX" value="micro-zuul-server" />

<!-- 一般信息按照每天生成日志文件 -->
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
Expand Down
8 changes: 7 additions & 1 deletion common-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>

<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ public static final class SHIP_WAY {
public static final String UPS = "UPS";
public static final String DHL = "DHL";
}

/**
* redis中存储的需要校验token的uri的前缀
*/
public static final String URL_NEED_CHECK_KEY = "URL2CHK";
}
Loading

0 comments on commit 0eaafc3

Please sign in to comment.