Skip to content

Commit 32a9314

Browse files
Mattia Vianellivins01-4science
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2565 (pull request DSpace#3795)
DSC-2565 Refactor standard login Approved-by: Andrea Barbasso
2 parents ae770ce + aa1a430 commit 32a9314

7 files changed

Lines changed: 25 additions & 19 deletions

File tree

config/config.example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ auth:
133133
# This is independent from the idle warning.
134134
timeLeftBeforeTokenRefresh: 120000 # 2 minutes
135135
# Standard login enabled
136-
disableStandardLogin: false
136+
isPasswordLoginEnabledForAdminsOnly: false
137137

138138
# Form settings
139139
form:

src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ import {
179179
canActivate: [GenericAdministratorGuard, EndUserAgreementCurrentUserGuard]
180180
},
181181
{
182-
path: 'standard-login',
182+
path: 'admin-only-login',
183183
loadChildren: () => import('./login-page/login-page.module').then((m) => m.LoginPageModule),
184184
data: {
185185
isBackDoor: true,
186186
},
187-
canMatch: [() => !environment.auth.disableStandardLogin],
187+
canMatch: [() => environment.auth.isPasswordLoginEnabledForAdminsOnly],
188188
},
189189
{
190190
path: 'login',

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ describe('LogInComponent', () => {
143143
expect(result).toEqual([{ authMethodType: AuthMethodType.Password, position: 1 }]);
144144
});
145145

146-
it('does not exclude password method when standard login is disabled', () => {
146+
it('does not exclude password method when isPasswordLoginEnabledForAdminsOnly is disabled', () => {
147147
const authMethods = [
148148
{ authMethodType: AuthMethodType.Password, position: 1 },
149149
{ authMethodType: AuthMethodType.Shibboleth, position: 2 },
150150
];
151151
component.excludedAuthMethod = undefined;
152-
const result = component.filterAndSortAuthMethods(authMethods, false, true);
152+
const result = component.filterAndSortAuthMethods(authMethods, false, false);
153153
expect(result).toEqual([
154154
{ authMethodType: AuthMethodType.Password, position: 1 },
155155
{ authMethodType: AuthMethodType.Shibboleth, position: 2 },
@@ -164,8 +164,9 @@ describe('LogInComponent', () => {
164164
];
165165
const isBackdoor = false;
166166
component.excludedAuthMethod = AuthMethodType.Ip;
167-
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor);
167+
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor, false);
168168
expect(result).toEqual([
169+
{ authMethodType: AuthMethodType.Password, position: 1 },
169170
{ authMethodType: AuthMethodType.Shibboleth, position: 3 }
170171
]);
171172
});
@@ -177,9 +178,10 @@ describe('LogInComponent', () => {
177178
];
178179
const isBackdoor = false;
179180
component.excludedAuthMethod = undefined;
180-
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor);
181+
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor, false);
181182
expect(result).toEqual([
182-
{ authMethodType: AuthMethodType.Shibboleth, position: 1 }
183+
{ authMethodType: AuthMethodType.Shibboleth, position: 1 },
184+
{ authMethodType: AuthMethodType.Password, position: 2 }
183185
]);
184186
});
185187
});

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit } from '@angular/core';
22
import { filter, map, shareReplay } from 'rxjs/operators';
3+
import { combineLatest } from 'rxjs';
34
import { select, Store } from '@ngrx/store';
45
import { AuthMethod } from '../../core/auth/models/auth.method';
56
import {
@@ -98,7 +99,7 @@ export class LogInComponent implements OnInit, OnDestroy {
9899
filter(routeData => !!routeData),
99100
map(data => data.isBackDoor),
100101
)),
101-
map(([methods, isBackdoor]) => this.filterAndSortAuthMethods(methods, isBackdoor, environment.auth.disableStandardLogin)),
102+
map(([methods, isBackdoor]) => this.filterAndSortAuthMethods(methods, isBackdoor, environment.auth.isPasswordLoginEnabledForAdminsOnly)),
102103
// ignore the ip authentication method when it's returned by the backend
103104
map((authMethods: AuthMethod[]) => uniqBy(authMethods.filter(a => a.authMethodType !== AuthMethodType.Ip), 'authMethodType'))
104105
);
@@ -118,21 +119,24 @@ export class LogInComponent implements OnInit, OnDestroy {
118119

119120
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration);
120121

121-
this.canForgot$ = this.authorizationService.isAuthorized(FeatureID.EPersonForgotPassword).pipe(shareReplay(1));
122-
this.canShowDivider$ = this.canRegister$.pipe(
123-
combineLatestWith(this.canForgot$),
124-
map(([canRegister, canForgot]) => (canRegister || canForgot) && (!environment.auth.disableStandardLogin || this.isStandalonePage)),
125-
filter(Boolean)
122+
this.canForgot$ = this.authorizationService.isAuthorized(FeatureID.EPersonForgotPassword).pipe(shareReplay({ refCount: false, bufferSize: 1 }));
123+
this.canShowDivider$ = combineLatest([
124+
this.canRegister$,
125+
this.canForgot$,
126+
this.route.data
127+
]).pipe(
128+
map(([canRegister, canForgot, routeData]) => (canRegister || canForgot) && !routeData?.isBackDoor),
129+
filter(Boolean),
126130
);
127131
}
128132

129-
filterAndSortAuthMethods(authMethods: AuthMethod[], isBackdoor: boolean, isStandardLoginDisabled = false): AuthMethod[] {
133+
filterAndSortAuthMethods(authMethods: AuthMethod[], isBackdoor: boolean, isPasswordLoginEnabledForAdminsOnly = false): AuthMethod[] {
130134
return authMethods.filter((authMethod: AuthMethod) => {
131135
const methodComparison = (authM) => {
132136
if (isBackdoor) {
133137
return authM.authMethodType === AuthMethodType.Password;
134138
}
135-
if (!isStandardLoginDisabled) {
139+
if (isPasswordLoginEnabledForAdminsOnly) {
136140
return authM.authMethodType !== AuthMethodType.Password;
137141
}
138142
return true;

src/config/auth-config.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export interface AuthConfig extends Config {
2222
};
2323

2424
// Whether the standard login form should be enabled.
25-
disableStandardLogin?: boolean;
25+
isPasswordLoginEnabledForAdminsOnly?: boolean;
2626
}

src/config/default-app-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class DefaultAppConfig implements AppConfig {
136136
// This is independent from the idle warning.
137137
timeLeftBeforeTokenRefresh: 2 * 60 * 1000 // 2 minutes
138138
},
139-
disableStandardLogin: true, // Enable the standard login form
139+
isPasswordLoginEnabledForAdminsOnly: false, // Enable the standard login form
140140
};
141141

142142
// Form settings

src/environments/environment.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const environment: BuildConfig = {
9797
// This is independent from the idle warning.
9898
timeLeftBeforeTokenRefresh: 20000, // 20 sec
9999
},
100-
disableStandardLogin: false,
100+
isPasswordLoginEnabledForAdminsOnly: true,
101101
},
102102

103103
// Form settings

0 commit comments

Comments
 (0)