# open-cloud **Repository Path**: jangels/open-cloud ## Basic Information - **Project Name**: open-cloud - **Description**: 微服务开放平台-基于SpringCloud2.0+,SpringSecurity,Oauth2,nacos服务发现和配置管理.统一API网关,在线调试文档,身份认证,接口鉴权,限流等。搭建基于API的生态体系,微服务架构的企业级开放平台,利于业务扩容。并提供基于vue.js开发的平台运维系统,界面美观,易操作。项目结构清晰,简单易懂,代码合理封装.开箱即用。 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 776 - **Created**: 2019-03-26 - **Last Updated**: 2021-11-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

Nacos SpringCloud SpringBoot iview vue License

# 微服务开放平台 --- #### 简介 搭建基于OAuth2的开放平台、为APP端提供统一接口管控平台、为第三方合作伙伴的业务对接提供授信可控的技术对接平台. + 统一API网关、访问鉴权、参数验签、外部调用更安全. + 分布式架构,基于服务发现,Fegin(伪RPC)方式内部调用,更便捷. + 深度整合SpringCloud+SpringSecurity+Oauth2,更细粒度、灵活的ABAC权限控制. + 前后端分离方式开发应用,分工合作更高效! + 代码合理封装、简单易懂、 在线访问 默认登录账号:admin 123456 测试登录账号:test 123456 #### 代码仓库 ##### 请随手给个Star! 感谢支持! 服务端源码-码云 服务端源码-Github 前端ui源码 使用手册 #### 代码结构 ``` lua open-cloud ├── docs ├── bin -- 执行脚本 ├── config -- 公共配置,用于导入到nacos配置中心 ├── generator -- mapper生成器 ├── sql -- sql文件 ├── opencloud-common -- 公共类和jar包依赖 ├── opencloud-common-core -- 提供微服务相关依赖包、工具类、全局异常解析等... ├── opencloud-common-starter -- SpringBoot自动扫描 ├── opencloud-gateway -- API网关模块 ├── opencloud-gateway-client -- API网关接口 ├── opencloud-gateway-provider -- API网关(port = 8888) ├── opencloud-upms -- 通用权限模块 ├── opencloud-base-client -- 平台基础服务接口 ├── opencloud-base-provider -- 平台基础服务(port = 8233) ├── opencloud-auth-client -- 平台认证服务接口 ├── opencloud-auth-provider -- 平台认证服务(port = 8211) ├── opencloud-app -- 应用服务模块 ├── opencloud-admin-provider -- 运营后台服务(port = 8301) ├── opencloud-msg -- 公共消息模块 ├── opencloud-msg-client -- 消息服务接口 ├── opencloud-msg-provider -- 消息服务(port = 8266) ├── opencloud-bpm -- 公共工作流模块... ├── opencloud-bpm-client -- 工作流接口 ├── opencloud-bpm-provider -- 工作流服务(port = 8255) ├── opencloud-zipkin -- 链路追踪 ``` #### 系统结构图 ![springcloud](/docs/springcloud.jpg) #### 数据模型 ##### 基础权限模型 ![base](/docs/base.png) ##### 网关访问限制模型 ![gateway](/docs/gateway.png) #### 快速开始 上手难度:★★★ 本项目基于springCloud打造的分布式快速开发框架. 需要了解SpringCloud,SpringBoot开发,分布式原理。 #### 注:Nacos版本选择V0.9.0以下版本. 1.0.0以上版本暂未测试! 1. 准备环境 + Java1.8 + 阿里巴巴Nacos服务发现和注册中心 nacos.io + Redis + RabbitMq + Mysql + Maven + Nodejs 2. 导入sql脚本 + docs/sql/oauth2.sql + docs/sql/base.sql + docs/sql/gateway.sql + docs/sql/zipkin.sql 3. 导入Nacos公共配置 + 访问 http://localhost:8848/nacos/index.html + 新建配置 + docs/config/db.properties > db.properties + docs/config/rabbitmq.properties > rabbitmq.properties + docs/config/redis.properties > redis.properties + docs/config/common.properties > common.properties 4. 修改主pom.xml 初始化 ``` bush maven clean install ``` 本地启动,默认不用修改 ``` xml 127.0.0.1:8848 127.0.0.1:8848 ``` 5. 本地启动 + AuthApplication + BaseApplication + GatewayApplication + AdminApplication 4个服务启动成功后。就可以依赖这些服务进行微服务开发了。 访问 http://localhost:8888 6. 前端启动 ```bush npm install npm run dev ``` 访问 http://localhost:8080 7. 项目打包部署 maven多环境打包 ```bush mvn clean install package -P {dev|test|online} ``` 项目启动 ```bush ./docs/bin/startup.sh {start|stop|restart|status} open-base-provider.jar ./docs/bin/startup.sh {start|stop|restart|status} open-auth-provider.jar ./docs/bin/startup.sh {start|stop|restart|status} open-gateway-provider.jar ./docs/bin/startup.sh {start|stop|restart|status} open-admin-provider.jar ``` #### 集成开发 1.创建新maven项目 ```xml opencloud-common-starter com.github.lyd ${opencloud.common.version} ``` 2.配置 bootstrap.properties 或bootstrap.yml ```properties #服务器配置 server.port=4560 #spring配置 spring.profiles.active=${profile.name} spring.application.name=my-service #Nacos配置中心 spring.cloud.nacos.config.server-addr=127.0.0.1:8848 #Nacos共享配置 spring.cloud.nacos.config.shared-dataids=common.properties,db.properties,redis.properties,rabbitmq.properties spring.cloud.nacos.config.refreshable-dataids=common.properties spring.cloud.nacos.config.namespace=${config.namespace} #Nacos服务发现 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.cloud.nacos.discovery.metadata.name=消息服务 # springCloud资源服务器默认配置,默认使用common公共的客户端ID。也可以使用新的客户端ID security.oauth2.client.client-id=${opencloud.common.client-id} security.oauth2.client.client-secret=${opencloud.common.client-secret} security.oauth2.client.scope=${opencloud.common.scope} security.oauth2.client.access-token-uri=${opencloud.common.access-token-uri} security.oauth2.client.user-authorization-uri=${opencloud.common.user-authorization-uri} security.oauth2.resource.token-info-uri=${opencloud.common.token-info-uri} security.oauth2.resource.user-info-uri=${opencloud.common.user-info-uri} #自定义API文档 opencloud.swagger2.enabled=true opencloud.swagger2.title=消息服务 opencloud.swagger2.description=消息服务 ``` 3. 创建MyServiceApplication.java ```java //开启feign RPC远程调用 @EnableFeignClients // 开启服务发现 @EnableDiscoveryClient @SpringBootApplication public class MyServiceApplication { public static void main(String[] args) { SpringApplication.run(MyServiceApplication.class, args); } } ``` 4.创建ResourceServerConfiguration.java 资源服务配置 ```java @Configuration @EnableResourceServer public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { @Autowired private ResourceServerProperties properties; @Override public void configure(ResourceServerSecurityConfigurer resources) throws Exception { // 构建远程获取token,这里是为了支持自定义用户信息转换器 resources.tokenServices(OpenHelper.buildRemoteTokenServices(properties)); } @Override public void configure(HttpSecurity http) throws Exception { http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) .and() .authorizeRequests() // 内部访问直接放行 .antMatchers("/v1/**").permitAll() // 只有拥有actuator权限可执行远程端点 .requestMatchers(EndpointRequest.toAnyEndpoint()).hasAnyAuthority(CommonConstants.AUTHORITY_ACTUATOR) .anyRequest().authenticated() .and() //认证鉴权错误处理,为了统一异常处理。每个资源服务器都应该加上。 .exceptionHandling() .accessDeniedHandler(new OpenAccessDeniedHandler()) .authenticationEntryPoint(new OpenAuthenticationEntryPoint()) .and() .csrf().disable(); } } ``` 5.启动项目 #### 第三方接口调用 #### 更新日志 v-1.0.0 2019-03-18 1. 重构项目结构 2. 重构表结构 3. 重构授权逻辑 4. 提取公共配置,并迁移到Nacos配置中心 5. 优化功能 #### 问题反馈 交流群:760809808 open-cloud学习交流群 ![760809808](/docs/1548831206525.png)