This action will force synchronization from jsonrock/open-cloud, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
搭建基于OAuth2的开放平台、为APP端提供统一接口管控平台、为第三方合作伙伴的业务对接提供授信可控的技术对接平台.
默认登录账号:admin 123456 测试登录账号:test 123456
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)
├── app-uaa-provider-demo -- 移动应用用户认证中心(多认证中心演示)(port = 7211)
├── opencloud-msg -- 公共消息模块
├── opencloud-msg-client -- 消息服务接口
├── opencloud-msg-provider -- 消息服务(port = 8266)
├── opencloud-scheduler -- 任务调度模块
├── opencloud-scheduler-client -- 任务调度接口
├── opencloud-scheduler-provider -- 任务调度服务(port = 8501)
├── opencloud-bpm -- 公共工作流模块...
├── 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>
本地启动
前端启动
npm install
npm run dev
项目打包部署
maven多环境打包
mvn clean install package -P {dev|test|online}
项目启动
./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项目
<!-- 引入公共包 -->
<dependency>
<artifactId>opencloud-common-starter</artifactId>
<groupId>com.github.lyd</groupId>
<version>${opencloud.common.version}</version>
</dependency>
2.配置 bootstrap.properties 或bootstrap.yml
#服务器配置
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=消息服务
//开启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 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.启动项目
针对不同应用的用户数据是单独存储,所以需要建立不同的认证中心提供用户认证。
例: 应用信息生成的 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
v-1.0.0 2019-03-18
1. 重构项目结构
2. 重构表结构
3. 重构授权逻辑
4. 提取公共配置,并迁移到Nacos配置中心
5. 优化功能
Sign in for post a comment
Comments ( 0 )