#6 fixed websocke with jwt token header

This commit is contained in:
fabio.formosa
2020-05-08 01:10:10 +02:00
parent 1bc52a26b7
commit 25028774d7
5 changed files with 19 additions and 8 deletions

View File

@@ -150,6 +150,9 @@ public class JwtTokenHelper {
return authHeader.substring(7);
}
if(request.getParameter("access_token") != null)
return request.getParameter("access_token");
return null;
}

View File

@@ -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);
}
}

View File

@@ -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))
}
}

View File

@@ -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))
}
}

View File

@@ -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;