Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # README.md # pom.xml # zlt-business/code-generator/pom.xml # zlt-business/file-center/pom.xml # zlt-business/pom.xml # zlt-business/search-center/pom.xml # zlt-business/search-center/search-client/pom.xml # zlt-business/search-center/search-server/pom.xml # zlt-business/user-center/pom.xml # zlt-commons/pom.xml # zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml # zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java # zlt-commons/zlt-common-core/pom.xml # zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java # zlt-commons/zlt-common-core/src/main/java/com/central/common/resolver/TokenArgumentResolver.java # zlt-commons/zlt-common-core/src/main/resources/META-INF/spring.factories # zlt-commons/zlt-common-spring-boot-starter/pom.xml # zlt-commons/zlt-common-spring-boot-starter/src/main/resources/META-INF/spring.factories # zlt-commons/zlt-db-spring-boot-starter/pom.xml # zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/MybatisPlusAutoConfigure.java # zlt-commons/zlt-elasticsearch-spring-boot-starter/pom.xml # zlt-commons/zlt-loadbalancer-spring-boot-starter/pom.xml # zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RandomRuleChooser.java # zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RoundRuleChooser.java # zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java # zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java # zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionRegisterBeanPostProcessor.java # zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java # zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/utils/QueryUtils.java # zlt-commons/zlt-log-spring-boot-starter/pom.xml # zlt-commons/zlt-oss-spring-boot-starter/pom.xml # zlt-commons/zlt-redis-spring-boot-starter/pom.xml # zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml # zlt-commons/zlt-swagger2-spring-boot-starter/pom.xml # zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml # zlt-config/pom.xml # zlt-config/src/main/resources/bootstrap.properties # zlt-demo/dubbo-demo/pom.xml # zlt-demo/pom.xml # zlt-demo/rocketmq-demo/pom.xml # zlt-demo/rocketmq-demo/rocketmq-consume/pom.xml # zlt-demo/rocketmq-demo/rocketmq-produce/pom.xml # zlt-demo/rocketmq-demo/rocketmq-transactional/pom.xml # zlt-demo/seata-demo/account-service/pom.xml # zlt-demo/seata-demo/business-service/pom.xml # zlt-demo/seata-demo/order-service/pom.xml # zlt-demo/seata-demo/pom.xml # zlt-demo/seata-demo/seata-common-starter/pom.xml # zlt-demo/seata-demo/storage-service/pom.xml # zlt-demo/sharding-jdbc-demo/pom.xml # zlt-demo/sso-demo/oidc-sso/pom.xml # zlt-demo/sso-demo/pom.xml # zlt-demo/sso-demo/ss-sso/pom.xml # zlt-demo/sso-demo/web-sso/pom.xml # zlt-demo/txlcn-demo/pom.xml # zlt-demo/txlcn-demo/txlcn-demo-common/pom.xml # zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/pom.xml # zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/pom.xml # zlt-demo/txlcn-demo/txlcn-demo-spring-service-c/pom.xml # zlt-gateway/pom.xml # zlt-gateway/sc-gateway/pom.xml # zlt-job/job-admin/pom.xml # zlt-job/job-core/pom.xml # zlt-job/job-executor-samples/pom.xml # zlt-job/pom.xml # zlt-monitor/log-center/pom.xml # zlt-monitor/pom.xml # zlt-monitor/sc-admin/pom.xml # zlt-transaction/pom.xml # zlt-transaction/txlcn-tm/pom.xml # zlt-uaa/pom.xml # zlt-web/back-web/pom.xml # zlt-web/layui-web/Dockerfile # zlt-web/layui-web/src/main/resources/static/index.html # zlt-web/layui-web/src/main/resources/static/login.html # zlt-web/layui-web/src/main/resources/static/module/index.js # zlt-web/layui-web/src/main/resources/static/pages/attestation/app.html # zlt-web/layui-web/src/main/resources/static/pages/log/sysLog.html # zlt-web/layui-web/src/main/resources/static/pages/log/traceLog.html # zlt-web/layui-web/src/main/resources/static/pages/system/menus.html # zlt-web/pom.xml
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
|
||||
|
||||
+5
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
@@ -22,5 +22,9 @@
|
||||
<module>sso-demo</module>
|
||||
<!-- dubbo集成demo -->
|
||||
<module>dubbo-demo</module>
|
||||
<!-- webSocket集成demo -->
|
||||
<module>websocket-demo</module>
|
||||
<!-- 资源服务器demo -->
|
||||
<module>resources-server-demo</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
## 一、说明
|
||||
资源服务器 demo 样例,以最简化的代码演示如何快速集成一个带鉴权功能的服务,适用于 `无网络隔离` 架构。
|
||||
|
||||
> 关于无网络隔离架构的设计可参考文档:[无网络隔离架构](https://www.kancloud.cn/zlt2000/microservices-platform/1153640)
|
||||
|
||||
|
||||
## 二、启动以下服务
|
||||
1. zlt-uaa:统一认证中心
|
||||
2. user-center:用户服务
|
||||
3. sc-gateway:api网关
|
||||
4. resources-server-demo
|
||||
|
||||
> 环境配置与启动参考文档:https://www.kancloud.cn/zlt2000/microservices-platform/919418
|
||||
|
||||
|
||||
## 三、测试
|
||||
### 3.1. 测试接口一
|
||||
http://localhost:8093/test/notAuth
|
||||
> 无需token访问
|
||||
|
||||
|
||||
### 3.2. 测试接口二
|
||||
通过 @LoginUser 获取当前登录人
|
||||
|
||||
http://localhost:8093/test/auth?access_token=xxx
|
||||
> - xxx 需替换为正确的 access_token
|
||||
> - 可以通过修改 `bootstrap.yml` 文件中的 `zlt.security.ignore.httpUrls` 参数添加排除校验的url。
|
||||
|
||||
|
||||
### 3.3. 测试接口三
|
||||
通过 LoginUserContextHolder 获取当前登录人
|
||||
|
||||
http://localhost:8093/test/auth2?access_token=xxx
|
||||
> - xxx 需替换为正确的 access_token
|
||||
|
||||
|
||||
## 四、获取access_token
|
||||
可使用任意授权模式获取;
|
||||
|
||||
例如:密码模式授权
|
||||
- 请求方式:POST
|
||||
- 请求头:Authorization:Basic d2ViQXBwOndlYkFwcA==
|
||||
- 请求地址:http://localhost:9900/api-uaa/oauth/token?grant_type=password&username=admin&password=admin
|
||||
|
||||
> 授权接口清单参考文档:https://www.kancloud.cn/zlt2000/microservices-platform/1158135
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>resources-server-demo</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-auth-client-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.zlt;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2022/6/25
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class ResourcesServerApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ResourcesServerApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.zlt.config;
|
||||
|
||||
import com.central.oauth2.common.config.DefaultResourceServerConf;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
||||
|
||||
/**
|
||||
* security资源服务器配置
|
||||
*
|
||||
* @author zlt
|
||||
* @version 1.0
|
||||
* @date 2022/6/25
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Configuration
|
||||
@EnableResourceServer
|
||||
public class MyResourceConfig extends DefaultResourceServerConf {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.zlt.config;
|
||||
|
||||
import com.central.common.config.DefaultWebMvcConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* web服务器配置
|
||||
*
|
||||
* @author zlt
|
||||
* @version 1.0
|
||||
* @date 2022/6/25
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig extends DefaultWebMvcConfig {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.zlt.controller;
|
||||
|
||||
import com.central.common.annotation.LoginUser;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.model.SysUser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2022/6/25
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class TestController {
|
||||
/**
|
||||
* 通过 @LoginUser 获取当前登录人
|
||||
*/
|
||||
@GetMapping("/test/auth")
|
||||
public String auth(@LoginUser SysUser user) {
|
||||
return "auth:" + user.getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 LoginUserContextHolder 获取当前登录人
|
||||
*/
|
||||
@GetMapping("/test/auth2")
|
||||
public String auth() {
|
||||
return "auth2:" + LoginUserContextHolder.getUser().getUsername();
|
||||
}
|
||||
|
||||
@GetMapping("/test/notAuth")
|
||||
public String notAuth() {
|
||||
return "notAuth:ok";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
port: 8093
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: zlt-resources-server
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
zlt:
|
||||
security:
|
||||
ignore:
|
||||
httpUrls: >
|
||||
/test/notAuth
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>rocketmq-demo</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>rocketmq-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>rocketmq-consume</artifactId>
|
||||
<description>rocketMQ消费者demo</description>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>rocketmq-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>rocketmq-produce</artifactId>
|
||||
<description>rocketMQ生产者demo</description>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>rocketmq-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>rocketmq-transactional</artifactId>
|
||||
<description>rocketMQ事务消息demo</description>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>seata-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>account-service</artifactId>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>seata-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>business-service</artifactId>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>seata-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>order-service</artifactId>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>seata-demo</artifactId>
|
||||
<description>seata分布式事务demo</description>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>seata-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>seata-common-starter</artifactId>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>seata-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>storage-service</artifactId>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>sharding-jdbc-demo</artifactId>
|
||||
<description>sharding-jdbc分库分表demo</description>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>sso-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>oidc-sso</artifactId>
|
||||
<description>OIDC协议单点登录demo</description>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>sso-demo</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>sso-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>ss-sso</artifactId>
|
||||
<description>springSecurity单点登录demo</description>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>sso-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>web-sso</artifactId>
|
||||
<description>前后端分离单点登录demo</description>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<description>txlcn分布式事务demo</description>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>txlcn-demo-common</artifactId>
|
||||
<name>demo-common</name>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>txlcn-demo-spring-service-b</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>txlcn-demo-spring-service-c</artifactId>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
## 代码说明
|
||||
- [SpringBoot的WebSocket接口如何实现鉴权?](https://www.kancloud.cn/zlt2000/microservices-platform/2278851)
|
||||
|
||||
|
||||
## 启动以下服务
|
||||
|
||||
1. zlt-uaa:统一认证中心
|
||||
2. user-center:用户服务
|
||||
3. sc-gateway:api网关
|
||||
4. websocket-demo
|
||||
|
||||
> 环境配置与启动参考文档:https://www.kancloud.cn/zlt2000/microservices-platform/919418
|
||||
|
||||
|
||||
## 获取access_token
|
||||
可使用任意授权模式获取;
|
||||
|
||||
例如:密码模式授权
|
||||
- 请求方式:POST
|
||||
- 请求头:Authorization:Basic d2ViQXBwOndlYkFwcA==
|
||||
- 请求地址:http://localhost:9900/api-uaa/oauth/token?grant_type=password&username=admin&password=admin
|
||||
|
||||
> 授权接口清单参考文档:https://www.kancloud.cn/zlt2000/microservices-platform/1158135
|
||||
|
||||
|
||||
## 测试步骤
|
||||
使用 `Postman` 进行测试(最新版本支持 webSocket 接口)
|
||||
|
||||
点击 `New` 按钮,选择 `WebSocket Request` ;
|
||||
|
||||
在 `URL` 中输入 `ws://localhost:8092/websocket/test`
|
||||
|
||||
在 `Headers` 中添加:`Authorization:Bearer xxx`
|
||||
|
||||
或者
|
||||
|
||||
在 `参数` 中添加:`ws://localhost:8092/websocket/test?access_token=xxx`
|
||||
|
||||
> xxx 需替换为正确的 access_token
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.5.0</version>
|
||||
</parent>
|
||||
<artifactId>websocket-demo</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-auth-client-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.zlt;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2022/5/8
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class WebSocketApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebSocketApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.zlt.config;
|
||||
|
||||
import com.central.oauth2.common.config.DefaultResourceServerConf;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
||||
|
||||
/**
|
||||
* security资源服务器配置
|
||||
*
|
||||
* @author zlt
|
||||
* @version 1.0
|
||||
* @date 2022/5/9
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Configuration
|
||||
@EnableResourceServer
|
||||
public class MyResourceConfig extends DefaultResourceServerConf {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.zlt.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
/**
|
||||
* WebSocket配置
|
||||
*
|
||||
* @author zlt
|
||||
* @version 1.0
|
||||
* @date 2022/5/8
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Configuration
|
||||
public class WebSocketConfig {
|
||||
@Bean
|
||||
public ServerEndpointExporter serverEndpointExporter() {
|
||||
return new ServerEndpointExporter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.zlt.controller;
|
||||
|
||||
import com.central.oauth2.common.config.WcAuthConfigurator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2022/5/8
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ServerEndpoint(value = "/websocket/test", configurator = WcAuthConfigurator.class)
|
||||
public class TestWebSocketController {
|
||||
@OnOpen
|
||||
public void onOpen(Session session) throws IOException {
|
||||
session.getBasicRemote().sendText("TestWebSocketController-ok");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
port: 8092
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: zlt-websocket
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
zlt:
|
||||
security:
|
||||
ignore:
|
||||
httpUrls: >
|
||||
/websocket/**
|
||||
Reference in New Issue
Block a user