-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KNOX-2929 - Logged in user is shown on Knox UIs (#819)
- Loading branch information
Showing
15 changed files
with
352 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!-- | ||
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. | ||
--> | ||
<div style="text-align: right; color: rgb(130, 180, 93);">Logged in as {{ getUser() }}</div> |
55 changes: 55 additions & 0 deletions
55
gateway-admin-ui/admin-ui/app/sessionInformation/session.information.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
gateway-admin-ui/admin-ui/app/sessionInformation/session.information.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SessionInformation> { | ||
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<any> { | ||
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); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
gateway-admin-ui/admin-ui/app/sessionInformation/session.information.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
knox-token-generation-ui/token-generation/app/session.information.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- | ||
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. | ||
--> | ||
<!-- The text color is the same as the Cloudera logo's color --> | ||
<div style="text-align: right; color: rgb(130, 180, 93);">Logged in as {{ getUser() }}</div> |
56 changes: 56 additions & 0 deletions
56
knox-token-generation-ui/token-generation/app/session.information.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.