diff --git a/config/environment.default.js b/config/environment.default.js index 221b2e8ef9..59d27a04fa 100644 --- a/config/environment.default.js +++ b/config/environment.default.js @@ -29,13 +29,13 @@ module.exports = { timePerMethod: {'PATCH': 3} //time in seconds } }, - // Authentications +/* // Authentications auth: { target: { host: 'https://fis.tiss.tuwien.ac.at', page: '' } - }, + },*/ // Form settings form: { // NOTE: Map server-side validators to comparative Angular form validators diff --git a/src/app/+login-page/shibboleth/shibboleth.component.ts b/src/app/+login-page/shibboleth/shibboleth.component.ts index ae5be125b9..f386f9c5ea 100644 --- a/src/app/+login-page/shibboleth/shibboleth.component.ts +++ b/src/app/+login-page/shibboleth/shibboleth.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import {ShibbLoginAction} from '../../core/auth/auth.actions'; +import {GetJWTafterShibbLoginAction} from '../../core/auth/auth.actions'; import {Store} from '@ngrx/store'; import {CoreState} from '../../core/core.reducers'; @@ -13,7 +13,7 @@ export class ShibbolethComponent implements OnInit { constructor( private store: Store,) { } ngOnInit() { - this.store.dispatch(new ShibbLoginAction()); + this.store.dispatch(new GetJWTafterShibbLoginAction()); } } diff --git a/src/app/core/auth/auth.actions.ts b/src/app/core/auth/auth.actions.ts index f949536aac..c79f250e09 100644 --- a/src/app/core/auth/auth.actions.ts +++ b/src/app/core/auth/auth.actions.ts @@ -57,11 +57,11 @@ export class AuthenticateAction implements Action { } /** - * ShibbLoginAction. - * @class ShibbLoginAction + * GetJWTafterShibbLoginAction. + * @class GetJWTafterShibbLoginAction * @implements {Action} */ -export class ShibbLoginAction implements Action { +export class GetJWTafterShibbLoginAction implements Action { public type: string = AuthActionTypes.SHIBB_LOGIN; } @@ -380,7 +380,7 @@ export class SetRedirectUrlAction implements Action { */ export type AuthActions = AuthenticateAction - | ShibbLoginAction + | GetJWTafterShibbLoginAction | AuthenticatedAction | AuthenticatedErrorAction | AuthenticatedSuccessAction diff --git a/src/app/core/auth/auth.effects.ts b/src/app/core/auth/auth.effects.ts index 57745cf823..40d46944a7 100644 --- a/src/app/core/auth/auth.effects.ts +++ b/src/app/core/auth/auth.effects.ts @@ -30,7 +30,7 @@ import { RetrieveAuthMethodsAction, RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsSuccessAction, - ShibbLoginAction + GetJWTafterShibbLoginAction } from './auth.actions'; import { EPerson } from '../eperson/models/eperson.model'; import { AuthStatus } from './models/auth-status.model'; @@ -65,7 +65,7 @@ export class AuthEffects { @Effect() public shibbLogin$: Observable = this.actions$.pipe( ofType(AuthActionTypes.SHIBB_LOGIN), - switchMap((action: ShibbLoginAction) => { + switchMap((action: GetJWTafterShibbLoginAction) => { return this.authService.startShibbAuth().pipe( take(1), map((response: AuthStatus) => new AuthenticationSuccessAction(response.token)), diff --git a/src/app/core/auth/auth.interceptor.ts b/src/app/core/auth/auth.interceptor.ts index 177f09f0bc..dc9cfa34ec 100644 --- a/src/app/core/auth/auth.interceptor.ts +++ b/src/app/core/auth/auth.interceptor.ts @@ -34,9 +34,6 @@ export class AuthInterceptor implements HttpInterceptor { constructor(private inj: Injector, private router: Router, private store: Store) { } - private is405AuthResponse(response: HttpResponseBase): boolean { - return response.status === 405; - } private is302Response(response: HttpResponseBase): boolean { return response.status === 302; @@ -59,7 +56,8 @@ export class AuthInterceptor implements HttpInterceptor { } private isLoginResponse(http: HttpRequest | HttpResponseBase): boolean { - return http.url && http.url.endsWith('/authn/login'); + return http.url && http.url.endsWith('/authn/login') + /*|| http.url.endsWith('/shibboleth');*/ } private isLogoutResponse(http: HttpRequest | HttpResponseBase): boolean { @@ -81,17 +79,27 @@ export class AuthInterceptor implements HttpInterceptor { return authStatus; } - private getSSOLocationfromHeader(header: HttpHeaders): string { - console.log('HEADER www-authenticate: ', header.get('www-authenticate')); - let location = ''; + private getShibbUrlFromHeader(header: HttpHeaders): string { + // console.log('HEADER www-authenticate: ', header.get('www-authenticate')); + let shibbolethUrl = ''; + if (header.get('www-authenticate').startsWith('shibboleth realm')) { - const strings = header.get('www-authenticate').split(','); - location = strings[1]; + let urlParts: string[] = header.get('www-authenticate').split(','); + let location = urlParts[1]; + let re = /"/g; + location = location.replace(re, '').trim(); location = location.replace('location=', ''); - console.log('This should be the location: ', location); - return location = location.replace('"', '').trim(); + // console.log('location: ', location); + urlParts = location.split('?'); + const host = urlParts[1].replace('target=', ''); + console.log('host: ', host); + shibbolethUrl = host + location + '/shibboleth'; + re = /%3A%2F%2F/g; + shibbolethUrl = shibbolethUrl.replace(re, '://'); + // console.log('shibbolethUrl: ', shibbolethUrl); + return shibbolethUrl; } - return location; + return shibbolethUrl; } intercept(req: HttpRequest, next: HttpHandler): Observable> { @@ -159,11 +167,6 @@ export class AuthInterceptor implements HttpInterceptor { // Intercept an error response if (error instanceof HttpErrorResponse) { - // Check for 405 - /* if (this.is405AuthResponse(error)) { - console.log('the caught error is a 405'); - }*/ - // Checks if is a response from a request to an authentication endpoint if (this.isAuthRequest(error)) { console.log('catchError isAuthRequest=true'); @@ -171,8 +174,8 @@ export class AuthInterceptor implements HttpInterceptor { this.refreshTokenRequestUrls = []; // console.log('error: ', error); let location = ''; - if (error.headers.get('www-authenticate') != null) { - location = this.getSSOLocationfromHeader(error.headers); + if (error.headers.get('www-authenticate') != null && error.headers.get('www-authenticate').includes('shibboleth realm')) { + location = this.getShibbUrlFromHeader(error.headers); } // Create a new HttpResponse and return it, so it can be handle properly by AuthService. const authResponse = new HttpResponse({ diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 3f1a4e676e..7698d605c7 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -231,15 +231,15 @@ export class AuthService { if (isNotEmpty(status.ssoLoginUrl)) { // url = this.parseSSOLocation(status.ssoLoginUrl); // console.log('Parsed SSOLoginUrl: ', url); - url = 'https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login?target=https://fis.tiss.tuwien.ac.at'; - // url = status.ssoLoginUrl; + // url = 'https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login?target=https://fis.tiss.tuwien.ac.at'; + url = status.ssoLoginUrl; } return url; }) ) } - private parseSSOLocation(url: string): string { + /* private parseSSOLocation(url: string): string { console.log('auth.service parseSSOLocation was called'); const parseUrl = decodeURIComponent(url); // const urlTree: UrlTree = this.router.parseUrl(url); @@ -252,7 +252,7 @@ export class AuthService { // console.log(url); const target = `?target=${this.config.auth.target.host}${this.config.auth.target.page}`; return parseUrl.replace(/\?target=http.+/g, target); - } + }*/ /** * Create a new user diff --git a/src/app/core/auth/authenticated.guard.ts b/src/app/core/auth/authenticated.guard.ts index af0622cd19..2fae15f194 100644 --- a/src/app/core/auth/authenticated.guard.ts +++ b/src/app/core/auth/authenticated.guard.ts @@ -53,6 +53,7 @@ export class AuthenticatedGuard implements CanActivate, CanLoad { } private handleAuth(url: string): Observable { + console.log('authenticated.guard.handleAuth() was called with url: ', url); // get observable const observable = this.store.pipe(select(isAuthenticated)); diff --git a/src/app/core/auth/models/auth-shibb.model.ts b/src/app/core/auth/models/auth-shibb.model.ts new file mode 100644 index 0000000000..1375baf09b --- /dev/null +++ b/src/app/core/auth/models/auth-shibb.model.ts @@ -0,0 +1,5 @@ +export class AuthShibbModel { + host: string; + target: string; + startShibSessionUrl: string; // as configured in backend +} diff --git a/src/app/shared/log-in/log-in.component.html b/src/app/shared/log-in/log-in.component.html index bd70bf255e..5d2b2cab36 100644 --- a/src/app/shared/log-in/log-in.component.html +++ b/src/app/shared/log-in/log-in.component.html @@ -33,13 +33,13 @@ -
+