增加webSocket鉴权样例工程:websocket-demo
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user