diff --git a/sfera-mock/src/main/java/ch/sbb/sferamock/messages/services/OperationModeSelector.java b/sfera-mock/src/main/java/ch/sbb/sferamock/messages/services/OperationModeSelector.java index f37220a6..f686444c 100644 --- a/sfera-mock/src/main/java/ch/sbb/sferamock/messages/services/OperationModeSelector.java +++ b/sfera-mock/src/main/java/ch/sbb/sferamock/messages/services/OperationModeSelector.java @@ -30,7 +30,7 @@ public Optional selectOperationMode(List incomingO return getObserver(statusReportEnabled); } if (validModes.contains(driver)) { - return Optional.empty(); + return Optional.of(driver); } if (validModes.contains(observer)) { return getObserver(!statusReportEnabled); diff --git a/webapp/src/app/auth.service.ts b/webapp/src/app/auth.service.ts index 88e73707..f3e1050c 100644 --- a/webapp/src/app/auth.service.ts +++ b/webapp/src/app/auth.service.ts @@ -20,6 +20,9 @@ export class AuthService { } + /** + * deprecated + */ exchange(ru: string = '', train: string = '', role: string = ''): Observable { return this.httpClient.get(`${environment.backendUrl}/customClaim/requestToken`, { params: new HttpParams().set('ru', ru).set('train', train).set('role', role), diff --git a/webapp/src/app/mqtt-playground/mqtt-playground.component.ts b/webapp/src/app/mqtt-playground/mqtt-playground.component.ts index 55571548..1ac9c42b 100644 --- a/webapp/src/app/mqtt-playground/mqtt-playground.component.ts +++ b/webapp/src/app/mqtt-playground/mqtt-playground.component.ts @@ -5,7 +5,6 @@ import { MqService } from "../mq.service"; import { SbbIcon } from "@sbb-esta/angular/icon"; import { AsyncPipe } from "@angular/common"; import { MqttConnectionState } from "ngx-mqtt"; -import { AuthService } from "../auth.service"; import { firstValueFrom, map } from "rxjs"; import { OidcSecurityService } from "angular-auth-oidc-client"; @@ -23,8 +22,8 @@ import { OidcSecurityService } from "angular-auth-oidc-client"; }) export class MqttPlaygroundComponent implements OnDestroy { - constructor(public mqService: MqService, private authService: AuthService, private oidcSecurityService: OidcSecurityService) { - this.authService.exchange().subscribe(async token => { + constructor(public mqService: MqService, private oidcSecurityService: OidcSecurityService) { + this.oidcSecurityService.getAccessToken().subscribe(async token => { const userName = await firstValueFrom(this.oidcSecurityService.getUserData().pipe(map((data) => data?.preferred_username))); this.mqService.connect(userName, token) }); diff --git a/webapp/src/app/sfera-observer/sfera-observer.component.ts b/webapp/src/app/sfera-observer/sfera-observer.component.ts index b491e1d8..61db2049 100644 --- a/webapp/src/app/sfera-observer/sfera-observer.component.ts +++ b/webapp/src/app/sfera-observer/sfera-observer.component.ts @@ -4,8 +4,6 @@ import { SbbFormFieldModule } from "@sbb-esta/angular/form-field"; import { SbbInputModule } from "@sbb-esta/angular/input"; import { MqService } from "../mq.service"; import { SbbButtonModule } from "@sbb-esta/angular/button"; -import { SimpleXmlComponent } from "../simple-xml/simple-xml.component"; -import { AuthService } from "../auth.service"; import { firstValueFrom, map, Subscription } from "rxjs"; import { CommonModule } from "@angular/common"; import { MqttConnectionState } from "ngx-mqtt"; @@ -27,7 +25,6 @@ import { SbbAccordionModule } from "@sbb-esta/angular/accordion"; SbbInputModule, SbbButtonModule, SbbCheckboxModule, - SimpleXmlComponent, MessageTableComponent, SbbAccordionModule, ], @@ -55,7 +52,6 @@ export class SferaObserverComponent implements OnDestroy { protected readonly MqttConnectionState = MqttConnectionState; constructor(private oidcSecurityService: OidcSecurityService, - private authService: AuthService, protected mqService: MqService) { } @@ -65,9 +61,9 @@ export class SferaObserverComponent implements OnDestroy { this.g2bTopic = customTopicPrefix + '90940/2/G2B/' + this.companyControl.value + '/' + trainOperation + '/' + this.clientIdControl.value; this.b2gTopic = customTopicPrefix + '90940/2/B2G/' + this.companyControl.value + '/' + trainOperation + '/' + this.clientIdControl.value; this.eventTopic = customTopicPrefix + '90940/2/event/' + this.companyControl.value + '/' + trainOperation; - const exchangeToken = await firstValueFrom(this.authService.exchange(this.companyControl.value, trainOperation, 'read-only')); + const token = await firstValueFrom(this.oidcSecurityService.getAccessToken()); const username = await firstValueFrom(this.oidcSecurityService.getUserData().pipe(map((data) => data?.preferred_username))); - await this.mqService.connect(username, exchangeToken); + await this.mqService.connect(username, token); this.g2bSubscription = this.mqService.observe(this.g2bTopic) .subscribe(value => {