SUPPORT-9136: move socket subscription to auth service
This commit is contained in:
parent
9cc7dff3be
commit
28ec0c83ee
3 changed files with 25 additions and 22 deletions
|
|
@ -26,6 +26,7 @@ import {DropdownTreeviewSelectComponent} from "../../account_applications/compon
|
||||||
import {TreeviewModule} from "ngx-treeview";
|
import {TreeviewModule} from "ngx-treeview";
|
||||||
import {ErvuStaticGrid} from "../../account_applications/component/grid/ErvuStaticGrid";
|
import {ErvuStaticGrid} from "../../account_applications/component/grid/ErvuStaticGrid";
|
||||||
import {TemporaryFileUpload} from "../../account_applications/component/field/TemporaryFileUpload";
|
import {TemporaryFileUpload} from "../../account_applications/component/field/TemporaryFileUpload";
|
||||||
|
import {AuthorizationService} from "./service/authorization.service";
|
||||||
|
|
||||||
registerLocaleData(localeRu);
|
registerLocaleData(localeRu);
|
||||||
export const DIRECTIVES = [
|
export const DIRECTIVES = [
|
||||||
|
|
@ -62,7 +63,7 @@ export const DIRECTIVES = [
|
||||||
DIRECTIVES
|
DIRECTIVES
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
TokenInterceptor,
|
TokenInterceptor, AuthorizationService,
|
||||||
{provide: ProgressIndicationService, useClass: AppProgressIndicationService }
|
{provide: ProgressIndicationService, useClass: AppProgressIndicationService }
|
||||||
],
|
],
|
||||||
bootstrap: [],
|
bootstrap: [],
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy} from "@angular/core";
|
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy} from "@angular/core";
|
||||||
import {AuthorizationService} from "../service/authorization.service";
|
import {AuthorizationService} from "../service/authorization.service";
|
||||||
import {WebsocketService} from "../websocket/websocket.service";
|
|
||||||
import {StatusUpdateService} from "../service/status-update.service";
|
|
||||||
import {Subscription} from "rxjs";
|
import {Subscription} from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
@ -17,31 +15,16 @@ export class AppHeaderComponent implements OnDestroy {
|
||||||
|
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
|
|
||||||
constructor(protected authService: AuthorizationService, protected cd: ChangeDetectorRef,
|
constructor(protected authService: AuthorizationService, protected cd: ChangeDetectorRef) {
|
||||||
protected websocketService: WebsocketService,
|
|
||||||
protected statusUpdateService: StatusUpdateService) {
|
|
||||||
this.subscription = authService.onSessionUpdate
|
this.subscription = authService.onSessionUpdate
|
||||||
.subscribe(session => {
|
.subscribe(session => {
|
||||||
this.name = session.name;
|
this.name = session.name;
|
||||||
this.realm = session.realm;
|
this.realm = session.realm;
|
||||||
cd.markForCheck();
|
cd.markForCheck();
|
||||||
|
|
||||||
if (this.authService.hasRole('security_administrator')) {
|
|
||||||
this.websocketService.subscribe(({data}) => {
|
|
||||||
let parsedObj = JSON.parse(data);
|
|
||||||
|
|
||||||
if (parsedObj && parsedObj.traceId) {
|
|
||||||
if (parsedObj.className === 'update' || parsedObj.className === 'processError') {
|
|
||||||
this.statusUpdateService.update(parsedObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.websocketService.unsubscribe();
|
|
||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import {Injectable} from "@angular/core";
|
import {Injectable, OnDestroy} from "@angular/core";
|
||||||
import {Subject} from "rxjs";
|
import {Subject} from "rxjs";
|
||||||
import {HttpClient} from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
|
import {WebsocketService} from "../websocket/websocket.service";
|
||||||
|
import {StatusUpdateService} from "./status-update.service";
|
||||||
|
|
||||||
export interface UserSession {
|
export interface UserSession {
|
||||||
userId: string,
|
userId: string,
|
||||||
|
|
@ -11,13 +13,14 @@ export interface UserSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class AuthorizationService {
|
export class AuthorizationService implements OnDestroy {
|
||||||
|
|
||||||
private session: UserSession;
|
private session: UserSession;
|
||||||
|
|
||||||
public onSessionUpdate: Subject<UserSession> = new Subject<UserSession>();
|
public onSessionUpdate: Subject<UserSession> = new Subject<UserSession>();
|
||||||
|
|
||||||
constructor(protected httpClient: HttpClient) {}
|
constructor(protected httpClient: HttpClient, protected websocketService: WebsocketService,
|
||||||
|
protected statusUpdateService: StatusUpdateService) {}
|
||||||
|
|
||||||
public getCurrentSession(): Promise<any> {
|
public getCurrentSession(): Promise<any> {
|
||||||
if (this.session) return new Promise(resolve => resolve(this.session));
|
if (this.session) return new Promise(resolve => resolve(this.session));
|
||||||
|
|
@ -26,6 +29,18 @@ export class AuthorizationService {
|
||||||
.then((session: UserSession) => {
|
.then((session: UserSession) => {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.onSessionUpdate.next(session);
|
this.onSessionUpdate.next(session);
|
||||||
|
|
||||||
|
if (this.hasRole('security_administrator')) {
|
||||||
|
this.websocketService.subscribe(({data}) => {
|
||||||
|
let parsedObj = JSON.parse(data);
|
||||||
|
|
||||||
|
if (parsedObj && parsedObj.traceId) {
|
||||||
|
if (parsedObj.className === 'update' || parsedObj.className === 'processError') {
|
||||||
|
this.statusUpdateService.update(parsedObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
return session;
|
return session;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -61,4 +76,8 @@ export class AuthorizationService {
|
||||||
getRoles(): string[] {
|
getRoles(): string[] {
|
||||||
return this.isAuthorized() ? this.session.roles : null;
|
return this.isAuthorized() ? this.session.roles : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.websocketService.unsubscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue