diff --git a/gateway-admin-ui/admin-ui/app/app.module.ts b/gateway-admin-ui/admin-ui/app/app.module.ts index c0fa8b96ef..02c10ef0b2 100644 --- a/gateway-admin-ui/admin-ui/app/app.module.ts +++ b/gateway-admin-ui/admin-ui/app/app.module.ts @@ -47,6 +47,7 @@ import {ResourceDetailComponent} from './resource-detail/resource-detail.compone import {ProviderConfigSelectorComponent} from './provider-config-selector/provider-config-selector.component'; import {NewDescWizardComponent} from './new-desc-wizard/new-desc-wizard.component'; import {ProviderConfigWizardComponent} from './provider-config-wizard/provider-config-wizard.component'; +import {SessionInformationComponent} from './sessionInformation/session.information.component'; @NgModule({ imports: [BrowserModule, @@ -74,7 +75,8 @@ import {ProviderConfigWizardComponent} from './provider-config-wizard/provider-c ResourceDetailComponent, ProviderConfigSelectorComponent, NewDescWizardComponent, - ProviderConfigWizardComponent + ProviderConfigWizardComponent, + SessionInformationComponent ], providers: [TopologyService, ServiceDefinitionService, @@ -85,7 +87,8 @@ import {ProviderConfigWizardComponent} from './provider-config-wizard/provider-c {provide: APP_BASE_HREF, useValue: '/'} ], bootstrap: [AppComponent, - GatewayVersionComponent + GatewayVersionComponent, + SessionInformationComponent ] }) export class AppModule { diff --git a/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.html b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.html new file mode 100644 index 0000000000..77da6559e3 --- /dev/null +++ b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.html @@ -0,0 +1,15 @@ + +
Logged in as {{ getUser() }}
diff --git a/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.ts b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.ts new file mode 100644 index 0000000000..59ae3e549b --- /dev/null +++ b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.ts @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {Component, OnInit} from '@angular/core'; +import {SessionInformationService} from './session.information.service'; +import {SessionInformation} from './session.information'; + +@Component({ + selector: 'app-session-information', + templateUrl: './session.information.component.html', + providers: [SessionInformationService] +}) + +export class SessionInformationComponent implements OnInit { + + sessionInformation: SessionInformation; + logoutSupported = true; + + constructor(private sessionInformationService: SessionInformationService) { + this['showSessionInformation'] = true; + } + + getUser() { + if (this.sessionInformation) { + return this.sessionInformation.user; + } else { + console.debug('SessionInformationComponent --> getUser() --> dr.who'); + return 'dr.who'; + } + } + + ngOnInit(): void { + console.debug('SessionInformationComponent --> ngOnInit() --> '); + this.sessionInformationService.getSessionInformation() + .then(sessionInformation => this.setSessonInformation(sessionInformation)); + } + + setSessonInformation(sessionInformation: SessionInformation) { + this.sessionInformation = sessionInformation; + console.debug('SessionInformationComponent --> setSessonInformation() --> ' + this.sessionInformation.user); + } +} diff --git a/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.service.ts b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.service.ts new file mode 100644 index 0000000000..95a3cdc8ff --- /dev/null +++ b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.service.ts @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {Injectable} from '@angular/core'; +import {HttpClient, HttpErrorResponse, HttpHeaders} from '@angular/common/http'; +import Swal from 'sweetalert2'; + +import 'rxjs/add/operator/toPromise'; +import {SessionInformation} from './session.information'; + +@Injectable() +export class SessionInformationService { + pathParts = window.location.pathname.split('/'); + topologyContext = '/' + this.pathParts[1] + '/' + this.pathParts[2] + '/'; + sessionUrl = this.topologyContext + 'session/api/v1/sessioninfo'; + + constructor(private http: HttpClient) {} + + getSessionInformation(): Promise { + let headers = new HttpHeaders(); + headers = this.addJsonHeaders(headers); + return this.http.get(this.sessionUrl, { headers: headers}) + .toPromise() + .then(response => response['sessioninfo'] as SessionInformation) + .catch((err: HttpErrorResponse) => { + console.debug('HomepageService --> getSessionInformation() --> ' + this.sessionUrl + '\n error: ' + err.message); + if (err.status === 401) { + window.location.assign(document.location.pathname); + } else { + return this.handleError(err); + } + }); + } + + addJsonHeaders(headers: HttpHeaders): HttpHeaders { + return this.addCsrfHeaders(headers.append('Accept', 'application/json').append('Content-Type', 'application/json')); + } + + addCsrfHeaders(headers: HttpHeaders): HttpHeaders { + return this.addXHRHeaders(headers.append('X-XSRF-Header', 'homepage')); + } + + addXHRHeaders(headers: HttpHeaders): HttpHeaders { + return headers.append('X-Requested-With', 'XMLHttpRequest'); + } + + private handleError(error: HttpErrorResponse): Promise { + Swal.fire({ + icon: 'error', + title: 'Oops!', + text: 'Something went wrong!\n' + (error.error ? error.error : error.statusText), + confirmButtonColor: '#7cd1f9' + }); + return Promise.reject(error.message || error); + } +} diff --git a/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.ts b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.ts new file mode 100644 index 0000000000..549bb09dde --- /dev/null +++ b/gateway-admin-ui/admin-ui/app/sessionInformation/session.information.ts @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class SessionInformation { + user: string; + logoutUrl: string; + logoutPageUrl: string; + globalLgoutPageUrl: string; +} diff --git a/gateway-admin-ui/admin-ui/index.html b/gateway-admin-ui/admin-ui/index.html index 0a24f6816e..ab2d882cf3 100644 --- a/gateway-admin-ui/admin-ui/index.html +++ b/gateway-admin-ui/admin-ui/index.html @@ -42,6 +42,7 @@ style="max-width:200px; margin-top: -9px;" src="assets/knox-logo-transparent.gif" alt="Apache Knox Manager"> + diff --git a/knox-token-generation-ui/token-generation/app/app.module.ts b/knox-token-generation-ui/token-generation/app/app.module.ts index 7a63bb5d84..a5962de1d2 100644 --- a/knox-token-generation-ui/token-generation/app/app.module.ts +++ b/knox-token-generation-ui/token-generation/app/app.module.ts @@ -20,15 +20,16 @@ import { HttpClientModule } from '@angular/common/http'; import { TokenGenerationComponent } from './token-generation.component'; import { ReactiveFormsModule } from '@angular/forms'; import { TokenGenService } from './token-generation.service'; +import { SessionInformationComponent } from './session.information.component'; @NgModule({ imports: [BrowserModule, HttpClientModule, ReactiveFormsModule ], - declarations: [TokenGenerationComponent], + declarations: [TokenGenerationComponent, SessionInformationComponent], providers: [TokenGenService], - bootstrap: [TokenGenerationComponent] + bootstrap: [TokenGenerationComponent, SessionInformationComponent] }) export class AppModule { } diff --git a/knox-token-generation-ui/token-generation/app/session.information.component.html b/knox-token-generation-ui/token-generation/app/session.information.component.html new file mode 100644 index 0000000000..c81cdcd1d3 --- /dev/null +++ b/knox-token-generation-ui/token-generation/app/session.information.component.html @@ -0,0 +1,16 @@ + + +
Logged in as {{ getUser() }}
diff --git a/knox-token-generation-ui/token-generation/app/session.information.component.ts b/knox-token-generation-ui/token-generation/app/session.information.component.ts new file mode 100644 index 0000000000..01d4728043 --- /dev/null +++ b/knox-token-generation-ui/token-generation/app/session.information.component.ts @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {Component, OnInit} from '@angular/core'; +import {TokenGenService} from './token-generation.service'; +import {SessionInformation} from './token-generation.models'; + +@Component({ + selector: 'app-session-information', + templateUrl: './session.information.component.html', + providers: [TokenGenService] +}) + +export class SessionInformationComponent implements OnInit { + + sessionInformation: SessionInformation; + logoutSupported = true; + + constructor(private tokenGenerationService: TokenGenService) { + this['showSessionInformation'] = true; + } + + getUser() { + if (this.sessionInformation) { + return this.sessionInformation.user; + } else { + console.debug('SessionInformationComponent --> getUser() --> dr.who'); + return 'dr.who'; + } + } + + ngOnInit(): void { + console.debug('SessionInformationComponent --> ngOnInit() --> '); + this.tokenGenerationService.getSessionInformation() + .then(sessionInformation => this.setSessionInformation(sessionInformation)); + } + + private setSessionInformation(sessionInformation: SessionInformation) { + this.sessionInformation = sessionInformation; + console.debug('SessionInformationComponent --> setSessionInformation() --> ' + this.sessionInformation.user); + } + +} diff --git a/knox-token-generation-ui/token-generation/app/token-generation.models.ts b/knox-token-generation-ui/token-generation/app/token-generation.models.ts index b0825207df..f419c800a4 100644 --- a/knox-token-generation-ui/token-generation/app/token-generation.models.ts +++ b/knox-token-generation-ui/token-generation/app/token-generation.models.ts @@ -50,3 +50,12 @@ export interface TokenData { lifespanHours: number; lifespanMins: number; } + +export class SessionInformation { + user: string; + logoutUrl: string; + logoutPageUrl: string; + globalLgoutPageUrl: string; + canSeeAllTokens: boolean; + currentKnoxSsoCookieTokenId: string; +} diff --git a/knox-token-generation-ui/token-generation/app/token-generation.service.ts b/knox-token-generation-ui/token-generation/app/token-generation.service.ts index b20933594a..19c651b184 100644 --- a/knox-token-generation-ui/token-generation/app/token-generation.service.ts +++ b/knox-token-generation-ui/token-generation/app/token-generation.service.ts @@ -17,13 +17,14 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'; import Swal from 'sweetalert2'; -import { TokenData, TokenRequestParams, TokenResultData, TssStatusData } from './token-generation.models'; +import { TokenData, TokenRequestParams, TokenResultData, TssStatusData, SessionInformation } from './token-generation.models'; @Injectable() export class TokenGenService { readonly baseURL: string; readonly tokenURL: string; readonly tssStatusRequestURL: string; + readonly sessionUrl: string; constructor(private http: HttpClient) { const knoxtokenURL = 'knoxtoken/api/v2/token'; @@ -35,6 +36,7 @@ export class TokenGenService { this.baseURL = temporaryURL.substring(0, temporaryURL.lastIndexOf('/') + 1); this.tokenURL = topologyContext + knoxtokenURL; this.tssStatusRequestURL = topologyContext + tssStatusURL; + this.sessionUrl = topologyContext + 'session/api/v1/sessioninfo'; } getTokenStateServiceStatus(): Promise { @@ -70,6 +72,22 @@ export class TokenGenService { }); } + getSessionInformation(): Promise { + let headers = new HttpHeaders(); + headers = this.addHeaders(headers); + return this.http.get(this.sessionUrl, { headers: headers}) + .toPromise() + .then(response => response['sessioninfo'] as SessionInformation) + .catch((err: HttpErrorResponse) => { + console.debug('TokenManagementService --> getSessionInformation() --> ' + this.sessionUrl + '\n error: ' + err.message); + if (err.status === 401) { + window.location.assign(document.location.pathname); + } else { + return this.handleError(err); + } + }); + } + getGeneratedTokenData(params: TokenRequestParams): Promise { let headers = new HttpHeaders(); headers = this.addHeaders(headers); diff --git a/knox-token-generation-ui/token-generation/index.html b/knox-token-generation-ui/token-generation/index.html index 6b8d4c5658..c26d66dea1 100644 --- a/knox-token-generation-ui/token-generation/index.html +++ b/knox-token-generation-ui/token-generation/index.html @@ -27,6 +27,12 @@ +
+ + Apache Knox Home +
+ + diff --git a/knox-token-management-ui/token-management/app/app.module.ts b/knox-token-management-ui/token-management/app/app.module.ts index f49275980f..7ec5e55fe5 100644 --- a/knox-token-management-ui/token-management/app/app.module.ts +++ b/knox-token-management-ui/token-management/app/app.module.ts @@ -32,6 +32,7 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import {TokenManagementComponent} from './token.management.component'; import {TokenManagementService} from './token.management.service'; +import {SessionInformationComponent} from './session.information.component'; @NgModule({ imports: [BrowserModule, @@ -52,9 +53,9 @@ import {TokenManagementService} from './token.management.service'; MatSlideToggleModule, MatCheckboxModule ], - declarations: [TokenManagementComponent], + declarations: [TokenManagementComponent, SessionInformationComponent], providers: [TokenManagementService], - bootstrap: [TokenManagementComponent] + bootstrap: [TokenManagementComponent, SessionInformationComponent] }) export class AppModule { } diff --git a/knox-token-management-ui/token-management/app/session.information.component.html b/knox-token-management-ui/token-management/app/session.information.component.html new file mode 100644 index 0000000000..c81cdcd1d3 --- /dev/null +++ b/knox-token-management-ui/token-management/app/session.information.component.html @@ -0,0 +1,16 @@ + + +
Logged in as {{ getUser() }}
diff --git a/knox-token-management-ui/token-management/app/session.information.component.ts b/knox-token-management-ui/token-management/app/session.information.component.ts new file mode 100644 index 0000000000..9c2038daa0 --- /dev/null +++ b/knox-token-management-ui/token-management/app/session.information.component.ts @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {Component, OnInit} from '@angular/core'; +import {TokenManagementService} from './token.management.service'; +import {SessionInformation} from './session.information'; + +@Component({ + selector: 'app-session-information', + templateUrl: './session.information.component.html', + providers: [TokenManagementService] +}) + +export class SessionInformationComponent implements OnInit { + + sessionInformation: SessionInformation; + logoutSupported = true; + + constructor(private tokenManagementService: TokenManagementService) { + this['showSessionInformation'] = true; + } + + getUser() { + if (this.sessionInformation) { + return this.sessionInformation.user; + } else { + console.debug('SessionInformationComponent --> getUser() --> dr.who'); + return 'dr.who'; + } + } + + ngOnInit(): void { + console.debug('SessionInformationComponent --> ngOnInit() --> '); + this.tokenManagementService.getSessionInformation() + .then(sessionInformation => this.setSessionInformation(sessionInformation)); + } + + private setSessionInformation(sessionInformation: SessionInformation) { + this.sessionInformation = sessionInformation; + console.debug('SessionInformationComponent --> setSessionInformation() --> ' + this.sessionInformation.user); + } + +}