Skip to content

Commit d506074

Browse files
Added notification when the shibboleth authentication is failed (#732)
1 parent aa6e71b commit d506074

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

src/app/shared/log-in/container/log-in-container.component.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { ConfigurationProperty } from '../../../core/shared/configuration-proper
2525
import { ActivatedRoute, Router } from '@angular/router';
2626
import { CookieService } from '../../../core/services/cookie.service';
2727
import { CookieServiceMock } from '../../mocks/cookie.service.mock';
28+
import { NotificationsServiceStub } from '../../testing/notifications-service.stub';
29+
import { NotificationsService } from '../../notifications/notifications.service';
2830

2931
describe('LogInContainerComponent', () => {
3032

@@ -36,6 +38,7 @@ describe('LogInContainerComponent', () => {
3638
let hardRedirectService: HardRedirectService;
3739
let configurationDataService: ConfigurationDataService;
3840
let authService: any;
41+
let notificationService: NotificationsServiceStub;
3942

4043
beforeEach(waitForAsync(() => {
4144
hardRedirectService = jasmine.createSpyObj('hardRedirectService', {
@@ -55,6 +58,7 @@ describe('LogInContainerComponent', () => {
5558
]
5659
}))
5760
});
61+
notificationService = new NotificationsServiceStub();
5862

5963
// refine the test module by declaring the test component
6064
TestBed.configureTestingModule({
@@ -85,6 +89,7 @@ describe('LogInContainerComponent', () => {
8589
} },
8690
{ provide: Router, useValue: new RouterMock() },
8791
{ provide: CookieService, useClass: CookieServiceMock },
92+
{ provide: NotificationsService, useValue: notificationService },
8893
LogInContainerComponent
8994
],
9095
schemas: [

src/app/shared/log-in/log-in.component.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { ConfigurationProperty } from '../../core/shared/configuration-property.
3030
import { RouterStub } from '../testing/router.stub';
3131
import { CookieService } from '../../core/services/cookie.service';
3232
import { CookieServiceMock } from '../mocks/cookie.service.mock';
33+
import { NotificationsService } from '../notifications/notifications.service';
34+
import { NotificationsServiceStub } from '../testing/notifications-service.stub';
3335

3436
describe('LogInComponent', () => {
3537

@@ -50,6 +52,7 @@ describe('LogInComponent', () => {
5052
let authorizationService: AuthorizationDataService;
5153
let authService: any;
5254
let configurationDataService: ConfigurationDataService;
55+
let notificationService: NotificationsServiceStub;
5356

5457
beforeEach(waitForAsync(() => {
5558
hardRedirectService = jasmine.createSpyObj('hardRedirectService', {
@@ -72,6 +75,7 @@ describe('LogInComponent', () => {
7275
]
7376
}))
7477
});
78+
notificationService = new NotificationsServiceStub();
7579

7680
// refine the test module by declaring the test component
7781
void TestBed.configureTestingModule({
@@ -102,6 +106,7 @@ describe('LogInComponent', () => {
102106
provideMockStore({ initialState }),
103107
{ provide: ThemeService, useValue: getMockThemeService() },
104108
{ provide: CookieService, useClass: CookieServiceMock },
109+
{ provide: NotificationsService, useValue: notificationService },
105110
LogInComponent
106111
],
107112
schemas: [

src/app/shared/log-in/methods/password/log-in-password.component.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
2525
import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model';
2626
import { CookieService } from '../../../../core/services/cookie.service';
2727
import { CookieServiceMock } from '../../../mocks/cookie.service.mock';
28+
import { NotificationsService } from '../../../notifications/notifications.service';
29+
import { NotificationsServiceStub } from '../../../testing/notifications-service.stub';
2830

2931
describe('LogInPasswordComponent', () => {
3032
const uiUrl = 'localhost:4000';
@@ -36,6 +38,7 @@ describe('LogInPasswordComponent', () => {
3638
let hardRedirectService: HardRedirectService;
3739
let authService: any;
3840
let configurationDataService: ConfigurationDataService;
41+
let notificationService: NotificationsServiceStub;
3942

4043
beforeEach(() => {
4144
hardRedirectService = jasmine.createSpyObj('hardRedirectService', {
@@ -68,6 +71,7 @@ describe('LogInPasswordComponent', () => {
6871
]
6972
}))
7073
});
74+
notificationService = new NotificationsServiceStub();
7175

7276
});
7377

@@ -102,6 +106,7 @@ describe('LogInPasswordComponent', () => {
102106
} },
103107
{ provide: Router, useValue: new RouterMock() },
104108
{ provide: CookieService, useClass: CookieServiceMock },
109+
{ provide: NotificationsService, useValue: notificationService },
105110
provideMockStore({ initialState }),
106111
],
107112
schemas: [

src/app/shared/log-in/methods/password/log-in-password.component.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { AuthMethodType } from '../../../../core/auth/models/auth.method-type';
1616
import { renderAuthMethodFor } from '../log-in.methods-decorator';
1717
import { AuthMethod } from '../../../../core/auth/models/auth.method';
1818
import { AuthService } from '../../../../core/auth/auth.service';
19-
import { HardRedirectService } from '../../../../core/services/hard-redirect.service';
2019
import { CoreState } from '../../../../core/core-state.model';
2120
import { getForgotPasswordRoute, getRegisterRoute } from '../../../../app-routing-paths';
2221
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
@@ -26,6 +25,11 @@ import { getBaseUrl } from '../../../clarin-shared-util';
2625
import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model';
2726
import { ConfigurationDataService } from '../../../../core/data/configuration-data.service';
2827
import { CookieService } from '../../../../core/services/cookie.service';
28+
import { NotificationsService } from '../../../notifications/notifications.service';
29+
import { TranslateService } from '@ngx-translate/core';
30+
import { NotificationOptions } from '../../../notifications/models/notification-options.model';
31+
import { HELP_DESK_PROPERTY } from '../../../../item-page/tombstone/tombstone.component';
32+
import { getFirstSucceededRemoteDataPayload } from '../../../../core/shared/operators';
2933

3034
export const SHOW_DISCOJUICE_POPUP_CACHE_NAME = 'SHOW_DISCOJUICE_POPUP';
3135
/**
@@ -96,14 +100,15 @@ export class LogInPasswordComponent implements OnInit {
96100
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
97101
@Inject('isStandalonePage') public isStandalonePage: boolean,
98102
private authService: AuthService,
99-
private hardRedirectService: HardRedirectService,
100103
private formBuilder: UntypedFormBuilder,
101104
protected store: Store<CoreState>,
102105
protected authorizationService: AuthorizationDataService,
103106
private route: ActivatedRoute,
104107
protected router: Router,
105108
protected configurationService: ConfigurationDataService,
106109
protected storage: CookieService,
110+
private notificationService: NotificationsService,
111+
private translateService: TranslateService
107112
) {
108113
this.authMethod = injectedAuthMethodModel;
109114
}
@@ -113,6 +118,7 @@ export class LogInPasswordComponent implements OnInit {
113118
* @method ngOnInit
114119
*/
115120
public async ngOnInit() {
121+
this.checkIfHasLoginError();
116122
this.initializeDiscoJuiceCache();
117123
this.redirectUrl = '';
118124
// set formGroup
@@ -155,6 +161,23 @@ export class LogInPasswordComponent implements OnInit {
155161
return getForgotPasswordRoute();
156162
}
157163

164+
private checkIfHasLoginError() {
165+
const loginError = this.route.snapshot.queryParams?.error;
166+
if (loginError !== 'shibboleth-authentication-failed') {
167+
return;
168+
}
169+
170+
// It is a Shibboleth authentication error
171+
// Load the help desk email from the server
172+
const helpDeskEmail$ = this.configurationService.findByPropertyName(HELP_DESK_PROPERTY);
173+
helpDeskEmail$.pipe(getFirstSucceededRemoteDataPayload())
174+
.subscribe((helpDeskEmailCfg) => {
175+
this.notificationService.error(this.translateService.instant('login.auth.failed.shibboleth.title'),
176+
this.translateService.instant('login.auth.failed.shibboleth.message',
177+
{ email: helpDeskEmailCfg?.values?.[0] }), new NotificationOptions(-1, true));
178+
});
179+
}
180+
158181
/**
159182
* Set up redirect URL. It could be loaded from the `authorizationService.getRedirectUrl()` or from the url.
160183
*/

src/assets/i18n/cs.json5

+4
Original file line numberDiff line numberDiff line change
@@ -3797,6 +3797,10 @@
37973797
"login.form.new-user": "Jste nový uživatel? Klikněte zde pro registraci.",
37983798
// "login.form.or-divider": "or",
37993799
"login.form.or-divider": "nebo",
3800+
// "login.auth.failed.shibboleth.title": "Shibboleth authentication failed",
3801+
"login.auth.failed.shibboleth.title": "Přihlášení pomocí Shibboleth selhalo",
3802+
// "login.auth.failed.shibboleth.message": "Authentication failed because your IdP did not send the required Shibboleth headers. Please contact the Help Desk by email: {{ email }} .",
3803+
"login.auth.failed.shibboleth.message": "Přihlášení selhalo, protože vaše IDP neposlal požadované hlavičky Shibboleth. Kontaktujte prosím poradnu emailem: {{ email }} .",
38003804
// "login.form.oidc": "Log in with OIDC",
38013805
"login.form.oidc": "Přihlásit se pomocí OIDC",
38023806
// "login.form.orcid": "Log in with ORCID",

src/assets/i18n/en.json5

+4
Original file line numberDiff line numberDiff line change
@@ -3191,6 +3191,10 @@
31913191

31923192
"login.form.or-divider": "or",
31933193

3194+
"login.auth.failed.shibboleth.title": "Shibboleth authentication failed",
3195+
3196+
"login.auth.failed.shibboleth.message": "Authentication failed because your IDP did not send the required Shibboleth headers. Please contact the Help Desk by email: {{ email }} .",
3197+
31943198
"login.title": "Login",
31953199

31963200
"login.breadcrumbs": "Login",

0 commit comments

Comments
 (0)