尝试websocket支持登陆
parent
84be003a8f
commit
9789fcd3fa
|
@ -50,11 +50,20 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
String jwt = request.getHeader(JwtUtils.getHeader());
|
||||
// 这里如果没有jwt,继续往后走,因为后面还有鉴权管理器等去判断是否拥有身份凭证,所以是可以放行的
|
||||
// 没有jwt相当于匿名访问,若有一些接口是需要权限的,则不能访问这些接口
|
||||
System.out.println("sec-websocket-protocol==" + request.getHeader("sec-websocket-protocol"));
|
||||
if (StringUtils.isBlank(jwt)) {
|
||||
jwt = request.getParameter(JwtUtils.getHeader());
|
||||
String secWebsocketProtocolHeader = request.getHeader("sec-websocket-protocol");
|
||||
if (secWebsocketProtocolHeader != null) {
|
||||
jwt = secWebsocketProtocolHeader;
|
||||
}else {
|
||||
jwt = request.getParameter(JwtUtils.getHeader());
|
||||
}
|
||||
if (StringUtils.isBlank(jwt)) {
|
||||
jwt = request.getHeader(JwtUtils.getApiKeyHeader());
|
||||
if (StringUtils.isBlank(jwt)) {
|
||||
|
|
|
@ -19,8 +19,6 @@ public class LogChannel {
|
|||
@OnMessage(maxMessageSize = 1) // MaxMessage 1 byte
|
||||
public void onMessage(String message) {
|
||||
|
||||
log.debug("Recv Message: {}", message);
|
||||
|
||||
try {
|
||||
this.session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "此节点不接收任何客户端信息"));
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
<script>
|
||||
|
||||
import userService from "./service/UserService";
|
||||
|
||||
export default {
|
||||
name: 'log',
|
||||
components: {},
|
||||
|
@ -39,9 +41,13 @@ export default {
|
|||
console.log(window.location.host)
|
||||
let url = "ws://localhost:18080/channel/log";
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
url = `ws://${window.location.host}/channel/log`
|
||||
if (location.protocol === "https:") {
|
||||
url = `wss://${window.location.host}/channel/log`
|
||||
}else {
|
||||
url = `ws://${window.location.host}/channel/log`
|
||||
}
|
||||
}
|
||||
window.websocket = new WebSocket(url);
|
||||
window.websocket = new WebSocket(url, userService.getToken());
|
||||
window.websocket.onclose = e => {
|
||||
console.log(`conn closed: code=${e.code}, reason=${e.reason}, wasClean=${e.wasClean}`)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue