mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2026-01-16 22:33:23 +09:00
#6 fixed websocke with jwt token header
This commit is contained in:
@@ -150,6 +150,9 @@ public class JwtTokenHelper {
|
||||
return authHeader.substring(7);
|
||||
}
|
||||
|
||||
if(request.getParameter("access_token") != null)
|
||||
return request.getParameter("access_token");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,14 @@ export class SocketOption{
|
||||
brokerName : string;
|
||||
reconnectionTimeout : number = 30000
|
||||
|
||||
constructor(socketUrl : string, topicName : string, brokerName : string = null, reconnectionTimeout : number = 30000){
|
||||
getAccessToken: Function = () => null;
|
||||
|
||||
constructor(socketUrl : string, topicName : string, getAccessToken?: Function, brokerName : string = null, reconnectionTimeout : number = 30000){
|
||||
this.socketUrl = socketUrl;
|
||||
this.topicName = topicName;
|
||||
this.brokerName = brokerName;
|
||||
this.reconnectionTimeout = reconnectionTimeout;
|
||||
this.getAccessToken = getAccessToken || (() => null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Injectable, OnInit } from '@angular/core';
|
||||
import { WebsocketService } from '.';
|
||||
import { WebsocketService, ApiService } from '.';
|
||||
import { SocketOption } from '../model/SocketOption.model';
|
||||
|
||||
@Injectable()
|
||||
export class LogsWebsocketService extends WebsocketService {
|
||||
|
||||
constructor(){
|
||||
super(new SocketOption('/quartz-manager/logs', '/topic/logs'))
|
||||
constructor(private apiService: ApiService){
|
||||
super(new SocketOption('/quartz-manager/logs', '/topic/logs', apiService.getToken))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Injectable, OnInit } from '@angular/core';
|
||||
import { WebsocketService } from '.';
|
||||
import { WebsocketService, ApiService } from '.';
|
||||
import { SocketOption } from '../model/SocketOption.model';
|
||||
|
||||
@Injectable()
|
||||
export class ProgressWebsocketService extends WebsocketService {
|
||||
|
||||
constructor(){
|
||||
super(new SocketOption('/quartz-manager/progress', '/topic/progress'))
|
||||
constructor(private apiService: ApiService){
|
||||
super(new SocketOption('/quartz-manager/progress', '/topic/progress', apiService.getToken))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -109,7 +109,12 @@ export class WebsocketService {
|
||||
|
||||
connect = () => {
|
||||
const headers = {};
|
||||
this._socket.client = new SockJS(this._options.socketUrl);
|
||||
|
||||
let socketUrl = this._options.socketUrl;
|
||||
if(this._options.getAccessToken())
|
||||
socketUrl += `?access_token=${this._options.getAccessToken()}`
|
||||
|
||||
this._socket.client = new SockJS(socketUrl);
|
||||
this._socket.stomp = Stomp.over(this._socket.client);
|
||||
this._socket.stomp.connect(headers, this._socketListener, this._onSocketError);
|
||||
this._socket.stomp.onclose = this.scheduleReconnection;
|
||||
|
||||
Reference in New Issue
Block a user