开源中国 2018 年度最后一场技术盛会邀你来约~错过就要等明年啦!点此立即预约

GVP老干爹 / Cloud-AdminJavaApache-2.0

指数
0
Watch 2.4k Star 6.2k Fork 3.1k
已合并
!18 AG-Admin v2.5全面升级支持Spring Boot2

老干爹:2.5-SNAPSHOT老干爹:master

The Sun 创建于: 2018-03-07 16:54

AG-Admin v2.5全面升级支持Spring Boot2

0 条评论, 1 人参与 547642_geek_qi

展开详细操作日志 收起操作日志
The Sun 合并了 Pull Request 2018-03-07 16:55

登录 后才可以发表评论

文件改动数量已经超过 100 个,请拉取代码本地查看

100 文件发生了变化 ,影响行数: +381 -2984
@@ -5,4 +5,5 @@
target/
.project
.settings/
-.classpath
\ No newline at end of file
+.classpath
+ace-modules/ace-tool/src/main/resources/application-dev.yml
# AG-Admin(`开源学习`)
-AG-Admin是国内首个基于`Spring Cloud`微`服务`化`开发平台`,具有统一授权、认证后台管理系统,其中包含具备用户管理、资源权限管理、网关API管理等多个模块,支持多业务系统并行开发,可以作为后端服务的开发脚手架。代码简洁,架构清晰,适合学习和直接项目中使用。核心技术采用Eureka、Fegin、Ribbon、Zuul、Hystrix、`JWT Token`、Mybatis等主要框架和中间件,前端采用`vue-element-admin`组件。
+AG-Admin是国内首个基于`Spring Cloud`微`服务`化`开发平台`,具有统一授权、认证后台管理系统,其中包含具备用户管理、资源权限管理、网关API管理等多个模块,支持多业务系统并行开发,可以作为后端服务的开发脚手架。代码简洁,架构清晰,适合学习和直接项目中使用。核心技术采用`Spring Boot2`以及`Spring Cloud (Finchley.M8)`相关核心组件,前端采用`vue-element-admin`组件。
+
### QQ群号:169824183
### 更新日志,查看[点击打开](https://gitee.com/geek_qi/ace-security/blob/master/README.md#%E5%BC%80%E6%BA%90%E7%89%88%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97)
 
@@ -23,20 +24,22 @@ AG-Admin是国内首个基于`Spring Cloud`微`服务`化`开发平台`,具有
菜单管理|√|√
权限管理|√|√
操作日志|√|√
-数据字典|×|`√`
服务运维监控| √|`√`
-完整用户认证 | × | `√`
服务管理模块|√|`√`
分布式事务|×|`√`
-2.0UI|×|`√`
+数据字典|×|`√`
+新版UI|×|`√`
完整开发文档|×|`√`
快速工程Cli|×|`√`
跨服务数据聚合|×|`√`
+服务动态路由|×|`√`
部门岗位|×|`√`
多租户模块|×|`√`
数据权限|×|`√`
分级授权|x|`√`
定时任务|×|`√`
+附件服务|`Doing`|`Doing`
+消息服务|`Doing`|`Doing`
 
## 超级管理员
![img](http://geek_qi.gitee.io/ag-admin/img/base.gif)
@@ -47,10 +50,17 @@ AG-Admin是国内首个基于`Spring Cloud`微`服务`化`开发平台`,具有
## 服务管理
![img](http://geek_qi.gitee.io/ag-admin/img/service.gif)
 
-### 联系老A,`QQ:463540703`,`微信:whb2lyx`,进行企业版购买
-
----
# 开源版更新日志
+
+### 2018.03.08 重大更新
+- 全面升级`Spring Boot 2.0.0.Release`&`Spring Cloud Finchley.M8`
+- 调整目录结构,移除ace-demo模块
+- zipkin链路模块升级
+- monitor监控模块优化
+- 增加Lucense全文搜索模块
+- 增加OSS附件服务模块
+
### 2018.02.25
- 增加服务管理模块
 
@@ -107,21 +117,17 @@ AG-Admin是国内首个基于`Spring Cloud`微`服务`化`开发平台`,具有
```
├─ace-security
│ │
-│ ├─ace-admin----------------管理端服务层
+│ ├─ace-modules--------------公共服务模块(基础系统、搜索、OSS)
│ │
│ ├─ace-auth-----------------鉴权中心
│ │
│ ├─ace-gate-----------------网关负载中心
│ │
+│ ├─ace-common---------------通用脚手架
+│ │
│ ├─ace-center---------------服务注册中心
│ │
-│ ├─ace-monitor--------------统一监控中心
-│ │
-│ ├─ace-config---------------统一配置中心
-│ │
-│ ├─ace-api------------------公共服务接口包
-│ │
-│ ├─ace-demo-----------------示例服务代码
+│ ├─ace-control--------------运维中心(监控、链路)
│ │
│ └─ace-sidebar--------------调用第三方语言
@@ -219,16 +225,6 @@ Apache License Version 2.0
## 虽然本产品是开源产品,但未经本人允许擅自申请专利,将公开追究法律责任。
 
 
-
-
# 我们的用户
![img](http://upload-images.jianshu.io/upload_images/5700335-67814644d39fce24.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image.png](http://upload-images.jianshu.io/upload_images/5700335-a6f45909f94ab3b8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![NLDCF.png](https://s1.ax1x.com/2017/10/24/NLDCF.png)
-
-# 相信有了你们的支持,AG开源会越来越好,项目也会越来越完善。
-
-通过微信或支付宝,扫描下面的二维码,即可捐赠,如下图所示:
-
-微信 | 支付宝
----|---
-![微信](http://upload-images.jianshu.io/upload_images/5700335-41754303a4ccb703.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1080/q/50) | ![支付宝](http://upload-images.jianshu.io/upload_images/5700335-c4a626166c15058e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1080/q/50)
\ No newline at end of file
ace-admin/src/main/java/com/github/wxiaoqi/security/admin/config/MapperConfiguration.java 100644 → 0
-package com.github.wxiaoqi.security.admin.config;
-
-
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.bind.RelaxedPropertyResolver;
-import org.springframework.context.EnvironmentAware;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.env.Environment;
-import tk.mybatis.spring.mapper.MapperScannerConfigurer;
-
-/**
- * mybatis mapper 扫描配置类
- *
- * @author wanghaobin
- * @date 2016年12月15日
- * @since 1.7
- */
-@Configuration
-@AutoConfigureAfter(MybatisConfiguration.class)
-public class MapperConfiguration implements EnvironmentAware {
-
- private RelaxedPropertyResolver propertyResolver;
-
- private String basePackage;
-
- @Bean
- public MapperScannerConfigurer mapperScannerConfigurer(Environment environment){
-
- MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
- mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
- mapperScannerConfigurer.setBasePackage(basePackage);
- return mapperScannerConfigurer;
- }
-
-
- @Override
- public void setEnvironment(Environment environment) {
- this.propertyResolver = new RelaxedPropertyResolver(environment, null);
- this.basePackage = propertyResolver.getProperty("mybatis.basepackage");
- }
-}
\ No newline at end of file
ace-admin/src/main/java/com/github/wxiaoqi/security/admin/config/MybatisConfiguration.java 100644 → 0
-package com.github.wxiaoqi.security.admin.config;
-
-
-import com.alibaba.druid.pool.DruidDataSource;
-import com.github.pagehelper.PageHelper;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.ibatis.plugin.Interceptor;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.SqlSessionFactoryBean;
-import org.mybatis.spring.SqlSessionTemplate;
-import org.springframework.boot.bind.RelaxedPropertyResolver;
-import org.springframework.context.EnvironmentAware;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.env.Environment;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-import org.springframework.transaction.annotation.EnableTransactionManagement;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Properties;
-
-/**
- * mybatis 配置数据源类
- *
- * @author wanghaobin
- * @date 2016年12月15日
- * @since 1.7
- */
-@Configuration
-@EnableTransactionManagement
-public class MybatisConfiguration implements EnvironmentAware {
-
-
- private RelaxedPropertyResolver propertyResolver;
-
- private String driveClassName;
- private String url;
- private String userName;
- private String password;
- private String xmlLocation;
- private String typeAliasesPackage;
- /////////////////////druid参数///////////////////////////////////////////////////
- private String filters;
- private String maxActive;
- private String initialSize;
- private String maxWait;
- private String minIdle;
- private String timeBetweenEvictionRunsMillis;
- private String minEvictableIdleTimeMillis;
- private String validationQuery;
- private String testWhileIdle;
- private String testOnBorrow;
- private String testOnReturn;
- private String poolPreparedStatements;
- private String maxOpenPreparedStatements;
- //////////////////////////////////////////////////////////////////////////
-
- @Bean
- public DataSource druidDataSource() {
- DruidDataSource druidDataSource = new DruidDataSource();
- druidDataSource.setUrl(url);
- druidDataSource.setUsername(userName);
- druidDataSource.setPassword(password);
- druidDataSource.setDriverClassName(StringUtils.isNotBlank(driveClassName)?driveClassName:"com.mysql.jdbc.Driver");
- druidDataSource.setMaxActive(StringUtils.isNotBlank(maxActive)? Integer.parseInt(maxActive):10);
- druidDataSource.setInitialSize(StringUtils.isNotBlank(initialSize)? Integer.parseInt(initialSize):1);
- druidDataSource.setMaxWait(StringUtils.isNotBlank(maxWait)? Integer.parseInt(maxWait):60000);
- druidDataSource.setMinIdle(StringUtils.isNotBlank(minIdle)? Integer.parseInt(minIdle):3);
- druidDataSource.setTimeBetweenEvictionRunsMillis(StringUtils.isNotBlank(timeBetweenEvictionRunsMillis)?
- Integer.parseInt(timeBetweenEvictionRunsMillis):60000);
- druidDataSource.setMinEvictableIdleTimeMillis(StringUtils.isNotBlank(minEvictableIdleTimeMillis)?
- Integer.parseInt(minEvictableIdleTimeMillis):300000);
- druidDataSource.setValidationQuery(StringUtils.isNotBlank(validationQuery)?validationQuery:"select 'x'");
- druidDataSource.setTestWhileIdle(StringUtils.isNotBlank(testWhileIdle)? Boolean.parseBoolean(testWhileIdle):true);
- druidDataSource.setTestOnBorrow(StringUtils.isNotBlank(testOnBorrow)? Boolean.parseBoolean(testOnBorrow):false);
- druidDataSource.setTestOnReturn(StringUtils.isNotBlank(testOnReturn)? Boolean.parseBoolean(testOnReturn):false);
- druidDataSource.setPoolPreparedStatements(StringUtils.isNotBlank(poolPreparedStatements)? Boolean.parseBoolean(poolPreparedStatements):true);
- druidDataSource.setMaxOpenPreparedStatements(StringUtils.isNotBlank(maxOpenPreparedStatements)? Integer.parseInt(maxOpenPreparedStatements):20);
-
- try {
- druidDataSource.setFilters(StringUtils.isNotBlank(filters)?filters:"stat, wall");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return druidDataSource;
- }
-
- @Bean(name = "sqlSessionFactory")
- public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) {
- SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
- bean.setDataSource(dataSource);
- if(StringUtils.isNotBlank(typeAliasesPackage)){
- bean.setTypeAliasesPackage(typeAliasesPackage);
- }
- //分页插件
- PageHelper pageHelper = new PageHelper();
- Properties properties = new Properties();
- properties.setProperty("reasonable", "true");
- properties.setProperty("supportMethodsArguments", "true");
- properties.setProperty("returnPageInfo", "check");
- properties.setProperty("params", "count=countSql");
- pageHelper.setProperties(properties);
- //添加XML目录
- ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
- Interceptor[] plugins = new Interceptor[]{pageHelper};
- bean.setPlugins(plugins);
- try {
- bean.setMapperLocations(resolver.getResources(xmlLocation));
- return bean.getObject();
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- @Bean
- public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
- return new SqlSessionTemplate(sqlSessionFactory);
- }
-
- @Override
- public void setEnvironment(Environment environment) {
- this.propertyResolver = new RelaxedPropertyResolver(environment, null);
- this.url = propertyResolver.getProperty("spring.datasource.url");
- this.userName= propertyResolver.getProperty("spring.datasource.username");
- this.password = propertyResolver.getProperty("spring.datasource.password");
- this.driveClassName = propertyResolver.getProperty("spring.datasource.driver-class-name");
- this.filters = propertyResolver.getProperty("spring.datasource.filters");
- this.maxActive = propertyResolver.getProperty("spring.datasource.maxActive");
- this.initialSize = propertyResolver.getProperty("spring.datasource.initialSize");
- this.maxWait = propertyResolver.getProperty("spring.datasource.maxWait");
- this.minIdle = propertyResolver.getProperty("spring.datasource.minIdle");
- this.timeBetweenEvictionRunsMillis = propertyResolver.getProperty("spring.datasource.timeBetweenEvictionRunsMillis");
- this.minEvictableIdleTimeMillis = propertyResolver.getProperty("spring.datasource.minEvictableIdleTimeMillis");
- this.validationQuery = propertyResolver.getProperty("spring.datasource.validationQuery");
- this.testWhileIdle = propertyResolver.getProperty("spring.datasource.testWhileIdle");
- this.testOnBorrow = propertyResolver.getProperty("spring.datasource.testOnBorrow");
- this.testOnReturn = propertyResolver.getProperty("spring.datasource.testOnReturn");
- this.poolPreparedStatements = propertyResolver.getProperty("spring.datasource.poolPreparedStatements");
- this.maxOpenPreparedStatements = propertyResolver.getProperty("spring.datasource.maxOpenPreparedStatements");
- this.typeAliasesPackage = propertyResolver.getProperty("mybatis.typeAliasesPackage");
- this.xmlLocation = propertyResolver.getProperty("mybatis.xmlLocation");
- }
-
- @Bean
- public DataSourceTransactionManager transactionManager(DataSource dataSource) {
- return new DataSourceTransactionManager(dataSource);
- }
-
-}
ace-admin/src/main/java/com/github/wxiaoqi/security/admin/config/SwaggerConfiguration.java 100644 → 0
-package com.github.wxiaoqi.security.admin.config;
-
-import static com.google.common.base.Predicates.or;
-import static springfox.documentation.builders.PathSelectors.regex;
-
-import org.springframework.boot.bind.RelaxedPropertyResolver;
-import org.springframework.context.EnvironmentAware;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.env.Environment;
-import org.springframework.web.context.request.async.DeferredResult;
-
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
-import springfox.documentation.builders.ApiInfoBuilder;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.service.ApiInfo;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
-/**
- * swagger配置项
- *
- * @description
- * @author wanghaobin
- * @date 2017年6月20日
- * @since 1.7
- */
-@Configuration
-@EnableSwagger2
-public class SwaggerConfiguration extends WebMvcConfigurerAdapter implements EnvironmentAware {
- private String basePackage;
- private String creatName;
- private String serviceName;
- private RelaxedPropertyResolver propertyResolver;
- private String description;
- /**
- * 这个地方要重新注入一下资源文件,不然不会注入资源的,也没有注入requestHandlerMappping,相当于xml配置的
- * <!--swagger资源配置-->
- * <mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"/>
- * <mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>
- * 不知道为什么,这也是spring boot的一个缺点(菜鸟觉得的)
- * @param registry
- */
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("swagger-ui.html")
- .addResourceLocations("classpath:/META-INF/resources/");
- registry.addResourceHandler("/webjars*")
- .addResourceLocations("classpath:/META-INF/resources/webjars/");
- }
-
-
-
- @Bean
- public Docket createRestApi() {
- return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage(this.basePackage))
- .paths(PathSelectors.any()).build();
- }
-
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title(this.serviceName+" Restful APIs")
- .description(this.description)
- .contact(this.creatName).version("1.0").build();
- }
-
- @Override
- public void setEnvironment(Environment environment) {
- this.propertyResolver = new RelaxedPropertyResolver(environment, null);
- this.basePackage = propertyResolver.getProperty("swagger.basepackage");
- this.creatName = propertyResolver.getProperty("swagger.service.developer");
- this.serviceName = propertyResolver.getProperty("swagger.service.name");
- this.description = propertyResolver.getProperty("swagger.service.description");
- }
-}
ace-admin/src/main/java/com/github/wxiaoqi/security/admin/config/WebConfiguration.java 100644 → 0
-package com.github.wxiaoqi.security.admin.config;
-
-import com.github.wxiaoqi.security.auth.client.interceptor.ServiceAuthRestInterceptor;
-import com.github.wxiaoqi.security.auth.client.interceptor.UserAuthRestInterceptor;
-import com.github.wxiaoqi.security.common.handler.GlobalExceptionHandler;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
-
-import java.util.ArrayList;
-import java.util.Collections;
-
-/**
- * Created by ace on 2017/9/8.
- */
-@Configuration("admimWebConfig")
-@Primary
-public class WebConfiguration extends WebMvcConfigurerAdapter {
- @Bean
- GlobalExceptionHandler getGlobalExceptionHandler() {
- return new GlobalExceptionHandler();
- }
-
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- ArrayList<String> commonPathPatterns = getExcludeCommonPathPatterns();
- registry.addInterceptor(getServiceAuthRestInterceptor()).addPathPatterns("/**").excludePathPatterns(commonPathPatterns.toArray(new String[]{}));
- commonPathPatterns.add("/api/user/validate");
- registry.addInterceptor(getUserAuthRestInterceptor()).addPathPatterns("/**").excludePathPatterns(commonPathPatterns.toArray(new String[]{}));
- super.addInterceptors(registry);
- }
-
- @Bean
- ServiceAuthRestInterceptor getServiceAuthRestInterceptor() {
- return new ServiceAuthRestInterceptor();
- }
-
- @Bean
- UserAuthRestInterceptor getUserAuthRestInterceptor() {
- return new UserAuthRestInterceptor();
- }
-
- private ArrayList<String> getExcludeCommonPathPatterns() {
- ArrayList<String> list = new ArrayList<>();
- String[] urls = {
- "/v2/api-docs",
- "/swagger-resources/**",
- "/cache/**",
- "/api/log/save"
- };
- Collections.addAll(list, urls);
- return list;
- }
-
-// @Override
-// public void addResourceHandlers(ResourceHandlerRegistry registry) {
-// registry.addResourceHandler("/static/cache/**").addResourceLocations(
-// "classpath:/META-INF/static/");
-// super.addResourceHandlers(registry);
-// }
-}
ace-admin/src/main/java/com/github/wxiaoqi/security/admin/config/druid/DruidStatFilter.java 100644 → 0
-package com.github.wxiaoqi.security.admin.config.druid;
-
-import com.alibaba.druid.support.http.WebStatFilter;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.annotation.WebFilter;
-import javax.servlet.annotation.WebInitParam;
-import java.io.IOException;
-
-/**
- * ${DESCRIPTION}
- *
- * @author wanghaobin
- * @create 2017-06-20 21:34
- */
-@WebFilter(filterName="druidWebStatFilter",urlPatterns="/druid/*",
- initParams={
- @WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略资源
- })
-public class DruidStatFilter extends WebStatFilter {
-
- @Override
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
- response.setContentType("text/html");
- super.doFilter(request, response, chain);
- }
-}
ace-admin/src/main/java/com/github/wxiaoqi/security/admin/config/druid/DruidStatViewServlet.java 100644 → 0
-package com.github.wxiaoqi.security.admin.config.druid;
-
-import com.alibaba.druid.support.http.StatViewServlet;
-
-import javax.servlet.annotation.WebInitParam;
-import javax.servlet.annotation.WebServlet;
-
-/**
- * ${DESCRIPTION}
- *
- * @author wanghaobin
- * @create 2017-06-20 21:34
- */
-@SuppressWarnings("serial")
-@WebServlet(urlPatterns = "/druid/*",
- initParams={
-// @WebInitParam(name="allow",value="127.0.0.1,192.168.1.188"),// IP白名单 (没有配置或者为空,则允许所有访问)
-// @WebInitParam(name="deny",value="192.168.1.111"),// IP黑名单 (存在共同时,deny优先于allow)
-// @WebInitParam(name="loginUsername",value="admin"),// 用户名
-// @WebInitParam(name="loginPassword",value="123456"),// 密码
-// @WebInitParam(name="resetEnable",value="false")// 禁用HTML页面上的“Reset All”功能
- })
-public class DruidStatViewServlet extends StatViewServlet {
-
-
-}
ace-auth/ace-auth-client/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>ace-auth</artifactId>
<groupId>com.github.wxiaoqi</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
 
@@ -14,35 +14,29 @@
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-common</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
- <version>4.3.9.RELEASE</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-netflix-core</artifactId>
- <version>1.3.1.RELEASE</version>
- <scope>provided</scope>
+ <groupId>com.github.wxiaoqi</groupId>
+ <artifactId>ace-auth-common</artifactId>
+ <version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
- <artifactId>feign-core</artifactId>
- <version>9.5.0</version>
- <scope>provided</scope>
+ <artifactId>feign-okhttp</artifactId>
</dependency>
<dependency>
- <groupId>com.github.wxiaoqi</groupId>
- <artifactId>ace-auth-common</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-openfeign-core</artifactId>
+ <version>2.0.0.M1</version>
+ <scope>provided</scope>
</dependency>
<dependency>
- <groupId>io.github.openfeign</groupId>
- <artifactId>feign-okhttp</artifactId>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>5.0.4.RELEASE</version>
+ <scope>provided</scope>
</dependency>
</dependencies>
 
ace-auth/ace-auth-client/src/main/java/com/github/wxiaoqi/security/auth/client/config/FeignOkHttpConfig.java
@@ -6,7 +6,7 @@ import okhttp3.ConnectionPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.cloud.netflix.feign.FeignAutoConfiguration;
+import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
ace-auth/ace-auth-client/src/main/java/com/github/wxiaoqi/security/auth/client/feign/ServiceAuthFeign.java
package com.github.wxiaoqi.security.auth.client.feign;
 
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
-import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
ace-auth/ace-auth-client/src/main/java/com/github/wxiaoqi/security/auth/client/interceptor/OkHttpTokenInterceptor.java
package com.github.wxiaoqi.security.auth.client.interceptor;
 
import com.github.wxiaoqi.security.auth.client.config.ServiceAuthConfig;
+import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.auth.client.jwt.ServiceAuthUtil;
import com.github.wxiaoqi.security.common.constant.CommonConstants;
+import com.github.wxiaoqi.security.common.context.BaseContextHandler;
import lombok.extern.java.Log;
import okhttp3.Interceptor;
import okhttp3.Request;
@@ -21,30 +23,45 @@ import java.io.IOException;
@Component
@Log
public class OkHttpTokenInterceptor implements Interceptor {
- @Autowired
- @Lazy
- private ServiceAuthUtil serviceAuthUtil;
- @Autowired
- @Lazy
- private ServiceAuthConfig serviceAuthConfig;
+ @Autowired
+ @Lazy
+ private ServiceAuthUtil serviceAuthUtil;
+ @Autowired
+ @Lazy
+ private ServiceAuthConfig serviceAuthConfig;
+ @Autowired
+ @Lazy
+ private UserAuthConfig userAuthConfig;
 
 
- @Override
- public Response intercept(Chain chain) throws IOException {
- Request request = chain.request();
- Response response = chain.proceed(request);
- if(HttpStatus.FORBIDDEN.value()==response.code()){
- if(response.body().string().contains(String.valueOf(CommonConstants.EX_CLIENT_INVALID_CODE))){
- log.info("Client Token Expire,Retry to request...");
- serviceAuthUtil.refreshClientToken();
- Request newRequest = chain.request()
- .newBuilder()
- .header(serviceAuthConfig.getTokenHeader(),serviceAuthUtil.getClientToken())
- .build();
- response = chain.proceed(newRequest);
- }
- }
- return response;
- }
-
+ @Override
+ public Response intercept(Chain chain) throws IOException {
+ Request newRequest = null;
+ if (chain.request().url().toString().contains("client/token")) {
+ newRequest = chain.request()
+ .newBuilder()
+ .header(userAuthConfig.getTokenHeader(), BaseContextHandler.getToken())
+ .build();
+ } else {
+ newRequest = chain.request()
+ .newBuilder()
+ .header(userAuthConfig.getTokenHeader(), BaseContextHandler.getToken())
+ .header(serviceAuthConfig.getTokenHeader(), serviceAuthUtil.getClientToken())
+ .build();
+ }
+ Response response = chain.proceed(newRequest);
+ if (HttpStatus.FORBIDDEN.value() == response.code()) {
+ if (response.body().string().contains(String.valueOf(CommonConstants.EX_CLIENT_INVALID_CODE))) {
+ log.info("Client Token Expire,Retry to request...");
+ serviceAuthUtil.refreshClientToken();
+ newRequest = chain.request()
+ .newBuilder()
+ .header(userAuthConfig.getTokenHeader(), BaseContextHandler.getToken())
+ .header(serviceAuthConfig.getTokenHeader(), serviceAuthUtil.getClientToken())
+ .build();
+ response = chain.proceed(newRequest);
+ }
+ }
+ return response;
+ }
}
ace-auth/ace-auth-client/src/main/java/com/github/wxiaoqi/security/auth/client/interceptor/ServiceFeignInterceptor.java 100644 → 0
-package com.github.wxiaoqi.security.auth.client.interceptor;
-
-import com.github.wxiaoqi.security.auth.client.config.ServiceAuthConfig;
-import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
-import com.github.wxiaoqi.security.auth.client.jwt.ServiceAuthUtil;
-import com.github.wxiaoqi.security.common.context.BaseContextHandler;
-import feign.RequestInterceptor;
-import feign.RequestTemplate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-/**
- *
- * @author ace
- * @date 2017/9/15
- */
-public class ServiceFeignInterceptor implements RequestInterceptor {
- private Logger logger = LoggerFactory.getLogger(ServiceFeignInterceptor.class);
- @Autowired
- private ServiceAuthConfig serviceAuthConfig;
- @Autowired
- private UserAuthConfig userAuthConfig;
- @Autowired
- private ServiceAuthUtil serviceAuthUtil;
-
- public ServiceFeignInterceptor() {
- }
-
-
- @Override
- public void apply(RequestTemplate requestTemplate) {
- requestTemplate.header(serviceAuthConfig.getTokenHeader(), serviceAuthUtil.getClientToken());
- requestTemplate.header(userAuthConfig.getTokenHeader(), BaseContextHandler.getToken());
- }
-
- public void setServiceAuthConfig(ServiceAuthConfig serviceAuthConfig) {
- this.serviceAuthConfig = serviceAuthConfig;
- }
-
- public void setUserAuthConfig(UserAuthConfig userAuthConfig) {
- this.userAuthConfig = userAuthConfig;
- }
-
- public void setServiceAuthUtil(ServiceAuthUtil serviceAuthUtil) {
- this.serviceAuthUtil = serviceAuthUtil;
- }
-}
\ No newline at end of file
ace-auth/ace-auth-client/src/main/java/com/github/wxiaoqi/security/auth/client/jwt/ServiceAuthUtil.java
@@ -3,7 +3,6 @@ package com.github.wxiaoqi.security.auth.client.jwt;
 
import com.github.wxiaoqi.security.auth.client.config.ServiceAuthConfig;
import com.github.wxiaoqi.security.auth.client.feign.ServiceAuthFeign;
-import com.github.wxiaoqi.security.auth.common.event.AuthRemoteEvent;
import com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo;
import com.github.wxiaoqi.security.auth.common.util.jwt.JWTHelper;
import com.github.wxiaoqi.security.common.exception.auth.ClientTokenException;
@@ -26,11 +25,13 @@ import java.util.List;
@Configuration
@Slf4j
@EnableScheduling
-public class ServiceAuthUtil implements ApplicationListener<AuthRemoteEvent> {
+public class ServiceAuthUtil{
@Autowired
private ServiceAuthConfig serviceAuthConfig;
+
@Autowired
private ServiceAuthFeign serviceAuthFeign;
+
private List<String> allowedClient;
private String clientToken;
 
@@ -81,9 +82,4 @@ public class ServiceAuthUtil implements ApplicationListener&lt;AuthRemoteEvent&gt; {
}
return allowedClient;
}
-
- @Override
- public void onApplicationEvent(AuthRemoteEvent authRemoteEvent) {
- this.allowedClient = authRemoteEvent.getAllowedClient();
- }
}
\ No newline at end of file
ace-auth/ace-auth-common/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>ace-auth</artifactId>
<groupId>com.github.wxiaoqi</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
 
ace-auth/ace-auth-common/src/main/java/com/github/wxiaoqi/security/auth/common/event/AuthRemoteEvent.java 100644 → 0
-package com.github.wxiaoqi.security.auth.common.event;
-
-import lombok.Data;
-import org.springframework.cloud.bus.event.RemoteApplicationEvent;
-
-import java.util.List;
-
-/**
- * @author ace
- * @create 2017/11/4.
- */
-@Data
-public class AuthRemoteEvent extends RemoteApplicationEvent {
- private List<String> allowedClient;
-
- //jackson序列化反序列化必须有无参构造函数
- public AuthRemoteEvent() {
- }
-
- public AuthRemoteEvent(Object source, String originService, String destinationService, List<String> allowedClient) {
- // source is the object that is publishing the event
- // originService is the unique context ID of the publisher
- super(source, originService, destinationService);
- this.allowedClient = allowedClient;
- }
-
-
-}
ace-auth/ace-auth-server/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>ace-auth</artifactId>
<groupId>com.github.wxiaoqi</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
 
@@ -19,28 +19,38 @@
 
<dependency>
<groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
 
<dependency>
<groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
+ <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
+
<dependency>
<groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
+ <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
 
<dependency>
<groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-sleuth</artifactId>
+ <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
 
<dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
+ <groupId>org.springframework.amqp</groupId>
+ <artifactId>spring-rabbit</artifactId>
</dependency>
 
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-redis</artifactId>
+ </dependency>
 
<!-- 持久层 -->
<dependency>
@@ -53,6 +63,13 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>
 
+ <!-- druid -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>druid-spring-boot-starter</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+
<!-- 通用mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
@@ -63,17 +80,7 @@
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
- <version>1.1.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-feign</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-eureka</artifactId>
+ <version>1.2.3</version>
</dependency>
 
<!-- 数据库驱动 -->
@@ -82,10 +89,6 @@
<artifactId>druid</artifactId>
</dependency>
 
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-redis</artifactId>
- </dependency>
 
<dependency>
<groupId>com.alibaba</groupId>
@@ -100,30 +103,28 @@
 
<dependency>
<groupId>com.github.wxiaoqi</groupId>
- <artifactId>ace-admin-interface</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <artifactId>ace-interface</artifactId>
+ <version>2.0-SNAPSHOT</version>
</dependency>
 
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-common</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
</dependency>
+
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-auth-common</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
</dependency>
+
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-auth-common</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
</dependency>
 
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-bus-amqp</artifactId>
- </dependency>
</dependencies>
 
<build>
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/AuthBootstrap.java
@@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
-import org.springframework.cloud.netflix.feign.EnableFeignClients;
+import org.springframework.cloud.openfeign.EnableFeignClients;
 
/**
* Created by Ace on 2017/6/2.
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/configuration/WebConfiguration.java
@@ -7,17 +7,16 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
-
-import java.util.ArrayList;
-import java.util.Collections;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
/**
- * Created by ace on 2017/9/8.
+ *
+ * @author ace
+ * @date 2017/9/8
*/
@Configuration("admimWebConfig")
@Primary
-public class WebConfiguration extends WebMvcConfigurerAdapter {
+public class WebConfiguration implements WebMvcConfigurer {
@Bean
GlobalExceptionHandler getGlobalExceptionHandler() {
return new GlobalExceptionHandler();
@@ -25,10 +24,8 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
 
@Override
public void addInterceptors(InterceptorRegistry registry) {
- ArrayList<String> commonPathPatterns = getExcludeCommonPathPatterns();
- registry.addInterceptor(getServiceAuthRestInterceptor()).addPathPatterns("/**").excludePathPatterns(commonPathPatterns.toArray(new String[]{}));
- registry.addInterceptor(getUserAuthRestInterceptor()).addPathPatterns("/**").excludePathPatterns(commonPathPatterns.toArray(new String[]{}));
- super.addInterceptors(registry);
+ registry.addInterceptor(getServiceAuthRestInterceptor()).addPathPatterns("/service/**");
+ registry.addInterceptor(getUserAuthRestInterceptor()).addPathPatterns("/service/**");
}
 
@Bean
@@ -41,16 +38,4 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
return new UserAuthRestInterceptor();
}
 
-
- private ArrayList<String> getExcludeCommonPathPatterns() {
- ArrayList<String> list = new ArrayList<>();
- String[] urls = {
- "/v2/api-docs",
- "/swagger-resources/**",
- "/client/**",
- "/jwt/**"
- };
- Collections.addAll(list, urls);
- return list;
- }
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/feign/IUserService.java
@@ -2,7 +2,7 @@ package com.github.wxiaoqi.security.auth.feign;
 
import com.github.wxiaoqi.security.api.vo.user.UserInfo;
import com.github.wxiaoqi.security.auth.configuration.FeignConfiguration;
-import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/impl/DBAuthClientService.java
package com.github.wxiaoqi.security.auth.service.impl;
 
import com.github.wxiaoqi.security.auth.bean.ClientInfo;
-import com.github.wxiaoqi.security.auth.common.event.AuthRemoteEvent;
import com.github.wxiaoqi.security.auth.entity.Client;
import com.github.wxiaoqi.security.auth.mapper.ClientMapper;
import com.github.wxiaoqi.security.auth.service.AuthClientService;
@@ -51,6 +50,7 @@ public class DBAuthClientService implements AuthClientService {
return client;
}
 
+ @Override
public void validate(String clientId, String secret) throws Exception {
Client client = new Client();
client.setCode(clientId);
@@ -99,13 +99,6 @@ public class DBAuthClientService implements AuthClientService {
if(dbClient==null) {
client.setSecret(UUIDUtils.generateShortUuid());
clientMapper.insert(client);
- }else{
- // 主动推送
- final List<String> clients = clientMapper.selectAllowedClient(dbClient.getId() + "");
- final String myUniqueId = context.getId();
- final AuthRemoteEvent event =
- new AuthRemoteEvent(this, myUniqueId, name, clients);
- context.publishEvent(event);
}
});
}
ace-auth/ace-auth-server/src/main/resources/application.yml
@@ -37,11 +37,11 @@ spring: