同步操作将从 soler/open-cloud 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
搭建基于OAuth2的开放平台、为APP端提供统一接口管控平台、为第三方合作伙伴的业务对接提供授信可控的技术对接平台.
默认登录账号:admin 123456 测试登录账号:test 123456
v-2.0.0 2019-05-01
1. 升级SpringCloud版本至Greenwich.SR1,SpringBoot 2.1.4.RELEASE
2. 重构项目结构
3. 增加SpringCloudGateway
4. 迁移gateway功能到base服务中
5. 增加MybatisPlus
6. 使用.yml代替.properties
7. 移除generator模块,将提供单独代码生成项目(计划中...)
v-1.0.0 2019-03-18
1. 重构项目结构
2. 重构表结构
3. 重构授权逻辑
4. 提取公共配置,并迁移到Nacos配置中心
5. 优化功能
open-cloud
├── docs
├── bin -- 执行脚本
├── config -- 公共配置,用于导入到nacos配置中心
├── generator -- mapper生成器
├── sql -- sql文件
├── opencloud-app -- 应用服务模块
├── app-admin -- 运营后台服务(port = 8301)
├── app-auth-demo -- 移动应用用户认证中心(多认证中心演示)(port = 7211)
├── opencloud-common -- 公共类和jar包依赖
├── opencloud-common-core -- 提供微服务相关依赖包、工具类、全局异常解析等...
├── opencloud-common-starter -- SpringBoot自动扫描
├── opencloud-gateway -- 开放API服务模块
├── opencloud-api-gateway -- API开放网关-基于SpringCloudGateway-(port = 8888)
├── opencloud-api-gateway-zuul --(较为稳定推荐使用)API开放网关-基于Zuul-(port = 8888)
├── opencloud-platform -- 平台服务模块
├── opencloud-base-client -- 平台基础服务接口
├── opencloud-base-provider -- 平台基础服务(port = 8233)
├── opencloud-auth-client -- 平台认证服务接口
├── opencloud-auth-provider -- 平台认证服务(port = 8211)
├── opencloud-msg-client -- 消息服务接口
├── opencloud-msg-provider -- 消息服务(port = 8266)
├── opencloud-scheduler-client -- 任务调度接口
├── opencloud-scheduler-provider -- 任务调度服务(port = 8501)
├── opencloud-bpm-client -- 工作流接口
├── opencloud-bpm-provider -- 工作流服务(port = 8255)
上手难度:★★★
本项目基于springCloud打造的分布式快速开发框架. 需要了解SpringCloud,SpringBoot开发,分布式原理。
准备环境
导入sql脚本
导入配置中心,Nacos公共配置
修改主pom.xml
初始化
maven clean install
本地启动,默认不用修改
<!--Nacos配置中心地址-->
<config.server-addr>127.0.0.1:8848</config.server-addr>
<!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID,不能使用名称,默认为空-->
<config.namespace></config.namespace>
<!--Nacos服务发现地址-->
<discovery.server-addr>127.0.0.1:8848</discovery.server-addr>
本地启动(顺序启动)
4个服务启动成功后。就可以依赖这些服务进行微服务开发了。
访问 http://localhost:8888
前端启动
npm install
npm run dev
项目打包部署
maven多环境打包
mvn clean install package -P {dev|test|online}
项目启动
1. ./docs/bin/startup.sh {start|stop|restart|status} open-base-provider.jar
2. ./docs/bin/startup.sh {start|stop|restart|status} open-auth-provider.jar
3. ./docs/bin/startup.sh {start|stop|restart|status} open-admin-provider.jar
4. ./docs/bin/startup.sh {start|stop|restart|status} open-api-gateway.jar
资源服务器Oauth2校验解析token共总结了3种存放和读取方式:
1.创建新maven项目
<!-- 引入公共包 -->
<dependency>
<artifactId>opencloud-common-starter</artifactId>
<groupId>com.opencloud</groupId>
<version>${opencloud.common.version}</version>
</dependency>
2.配置 bootstrap.yml
server:
port: 8266
spring:
application:
name: ${artifactId}
cloud:
nacos:
config:
namespace: ${config.namespace}
refreshable-dataids: common.properties
server-addr: ${config.server-addr}
shared-dataids: common.properties,db.properties,redis.properties,rabbitmq.properties
discovery:
server-addr: ${discovery.server-addr}
main:
allow-bean-definition-overriding: true
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
profiles:
active: ${profile.name}
management:
endpoints:
web:
exposure:
include: refresh,health
opencloud:
swagger2:
description: 平台消息服务
enabled: true
title: 平台消息服务
//开启feign RPC远程调用
@EnableFeignClients
// 开启服务发现
@EnableDiscoveryClient
@SpringBootApplication
public class MyServiceApplication {
public static void main(String[] args) {
SpringApplication.run(MyServiceApplication.class, args);
}
}
4.创建ResourceServerConfiguration.java 资源服务配置
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Autowired
private RedisConnectionFactory redisConnectionFactory;
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
// 构建redis获取token,这里是为了支持自定义用户信息转换器
resources.tokenServices(OpenHelper.buildRedisTokenServices(redisConnectionFactory));
}
@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.启动项目
针对不同应用的用户数据是单独存储,所以需要建立不同的认证中心提供用户认证。
例: 应用信息生成的 AppId: 1553588629729 AppSecret: 1a616ba3f91141efa1c4f4a1ce725e2c
http://localhost:8211/oauth/authorize?response_type=code&client_id=1553588629729&redirect_uri=http://www.baidu.com
未登录将进入登录页,输入系统用户登录信息 用户确认授权信息 重定向到回调地址,获得code
使用postman通过code获取access_token,
使用access_token获取已授权资源
http://localhost:8211/oauth/token?grant_type=client_credentials&client_id=1553588629729&client_secret=1a616ba3f91141efa1c4f4a1ce725e2c
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。