Commit 990378ee authored by Lukas Burgey's avatar Lukas Burgey

Automatically log in when only one IdP is configured

parent e59c4b2c
......@@ -26,8 +26,9 @@ export class UserService {
public messages: string[] = [];
// local copy of services
public services: t.Service[] = [];
public groupMap = new Map();
public groupsParsed = false;
public groupMap: Map<string, t.Service[]> = new Map();
public groupsParsed: boolean = false;
public idps: Observable<t.AuthInfo>;
constructor(
......@@ -37,6 +38,16 @@ export class UserService {
private _stompService: StompRService,
) {
this.update();
this.idps = this.getIdPs();
// if there is only one IdP immediately use it to login
this.idps.subscribe(
(authInfo: t.AuthInfo) => {
if (authInfo.idps && authInfo.idps.length == 1) {
this.login(authInfo.idps[0]);
}
}
);
}
// PRIVATE API
......@@ -244,25 +255,23 @@ export class UserService {
return new MatTableDataSource(this.user.ssh_keys);
}
public loggedIn():boolean {
public loggedIn(): boolean {
if (this.userState) {
return true;
}
return false;
}
public update() {
this.http
.get('/backend/api/state')
.subscribe(
(data: t.StateAPIResult) => {
this.stateAPIUpdate(data);
},
(err: HttpErrorResponse) => {
console.log('Error', err);
this.snackBar.open('Error receiving data from the server');
}
);
public update(): void {
this.http.get('/backend/api/state').subscribe(
(data: t.StateAPIResult) => {
this.stateAPIUpdate(data);
},
(err: HttpErrorResponse) => {
console.log('Error', err);
this.snackBar.open('Error receiving data from the server');
}
);
}
public errorHandler(error: any): void {
......@@ -271,12 +280,25 @@ export class UserService {
}
}
public getIdPs(): Observable<t.AuthInfo> {
return this.http.get('/backend/auth/v1/info').map(
(authInfo: t.AuthInfo) => {
return authInfo;
}
).catch(
(error: any) => {
this.errorHandler(error);
return Observable.of(null);
}
);
}
public getIdPPreference(): Observable<t.AllAuthInfo> {
let idpID = Number(this.cookieService.get(environment.idpCookieName));
return this.http.get('/backend/auth/v1/info').map(
return this.idps.map(
(authInfo: t.AuthInfo) => {
let selected = authInfo.idps[1];
let selected = authInfo.idps[0];
if (!idpID) {
idpID = authInfo.default;
......@@ -301,7 +323,10 @@ export class UserService {
public login(idp: t.IdP) {
this.setIdPPreference(idp);
window.location.href = '/backend/auth/v1/request';
if (!this.loggedIn()) {
window.location.href = '/backend/auth/v1/request';
}
}
public logout() {
......@@ -316,7 +341,7 @@ export class UserService {
);
}
public sentQuestionnaire(stateItemID: number, answers: any) {
public sentQuestionnaire(stateItemID: number, answers: Object) {
return this.http.post('/backend/api/questionnaire?id='+String(stateItemID), answers).subscribe(
(data: t.UserState) => {
this.snackBar.open('Uploaded questionnaire');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment