Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AuthenticationService } from '../auth/auth.service';
import { UserInfoModel, NtNameModel } from '../auth/auth.model';
import { AppSettingsService } from './../shared/app-settings/app-settings.service';
@Component({
selector: 'app-sso-redirect',
template: `<div class="redirect"><app-spinner></app-spinner><div>`,
styleUrls: ['./../shared/spinner/spinner.component.scss']
})
export class SsoRedirectComponent implements OnInit {
constructor(
private router: Router,
private authenticationService: AuthenticationService,
private activatedRoute: ActivatedRoute,
private appSettingsService: AppSettingsService
) {}
ntName: string;
attachmentId: string; // for attachmentViewer only
// errorMsg = '';
// errorStatus = false;
ntNameRequest = new NtNameModel();
userInfo: UserInfoModel;
userRoles = [''];
ngOnInit() {
// this is to solve the issue of redirecting a logged in user back to log in
// when the back button is pressed
// we grab the userRole from sessionStorage to resolve that issue.
// const decodedUserInfo = this.authenticationService.getDecodedUserInfo();
// if (decodedUserInfo) {
// this.userRoles = decodedUserInfo.userRoles;
// if (
// this.userRoles.some(role => role === 'ADMIN' || role === 'BASE_USER')
// ) {
// this.router.navigate(['search275']);
// } else if (this.userRoles.some(role => role === 'EWV')) {
// this.router.navigate(['ewvSearch']);
// }
// } else {
this.activatedRoute.queryParams.subscribe(params => {
this.ntName = encodeURIComponent(params['user']);
if (params['attachmentId']) {
this.attachmentId = params['attachmentId'];
}
if (this.ntName && this.ntName !== 'undefined') {
this.ntNameRequest.getNtname = this.ntName;
this.authenticationService.getUserInfo(this.ntNameRequest).subscribe(
data => {
// if (data['errorCode']) {
// this.authenticationService.setErrorMsg(data['message'], true);
// this.router.navigate(['/']);
// this.errorMsg = data.message;
// this.errorStatus = true; }
this.userInfo = data;
this.redirect();
},
error => {
console.log('error login in', error);
this.authenticationService.setErrorMsg(error.error.message, true);
this.router.navigate(['/']);
}
);
}
});
// -- old working code --
// this.activatedRoute.params.subscribe(param => {
// this.ntName = encodeURIComponent(param['user']);
// if (this.ntName && this.ntName !== 'undefined') {
// this.ntNameRequest.getNtname = this.ntName;
// this.authenticationService.getUserInfo(this.ntNameRequest).subscribe(
// data => {
// // if (data['errorCode']) {
// // this.authenticationService.setErrorMsg(data['message'], true);
// // this.router.navigate(['/']);
// // this.errorMsg = data.message;
// // this.errorStatus = true; }
// this.userInfo = data;
// this.redirect();
// },
// error => {
// console.log('error login in', error);
// this.authenticationService.setErrorMsg(error.error.message, true);
// this.router.navigate(['/']);
// }
// );
// }
// });
// }
// end of working code
}
redirect() {
if (this.userInfo.userRoles !== undefined) {
sessionStorage.setItem('jwt', this.userInfo.jwt);
if (
this.userInfo.userRoles.some(
data => data === 'ARS_BASE_ATTACHMENT_USER'
)
) {
if (this.attachmentId) {
this.router.navigate(['attachmentViewer'], {
queryParams: { attachmentId: this.attachmentId }
});
} else {
this.appSettingsService.setMenu();
this.router.navigate(['search275']);
}
} else if (this.userInfo.userRoles.some(data => data === 'ARS_ADMIN')) {
if (this.attachmentId) {
this.router.navigate(['attachmentViewer'], {
queryParams: { attachmentId: this.attachmentId }
});
} else {
this.appSettingsService.setMenu();
this.router.navigate(['userAdmin']);
}
} else if (
this.userInfo.userRoles.some(data => data === 'EWV_BASE_USER')
) {
this.appSettingsService.setMenu();
this.router.navigate(['ewvSearch']);
} else if (this.userInfo.userRoles.some(data => data === 'EWV_ADMIN')) {
this.appSettingsService.setMenu();
this.router.navigate(['ewvAdmin']);
} else {
this.router.navigate(['/']);
}
}
}
}