Skip to content

Commit 5a27198

Browse files
Mattia Vianellivins01-4science
authored andcommitted
Merged in task/dspace-cris-2024_02_x/DSC-2565 (pull request DSpace#3794)
DSC-2565 Refactor standard login Approved-by: Andrea Barbasso
2 parents ef0ab58 + eacfba3 commit 5a27198

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

src/app/app-routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ export const APP_ROUTES: Route[] = [
182182
canActivate: [authenticatedGuard, endUserAgreementCurrentUserGuard],
183183
},
184184
{
185-
path: 'standard-login',
185+
path: 'admin-only-login',
186186
loadChildren: () => import('./login-page/login-page-routes').then((m) => m.ROUTES),
187187
data: {
188188
isBackDoor: true,
189189
},
190-
canMatch: [() => !environment.auth.disableStandardLogin],
190+
canMatch: [() => environment.auth.isPasswordLoginEnabledForAdminsOnly],
191191
},
192192
{
193193
path: 'login',

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ describe('LogInComponent', () => {
154154
expect(result).toEqual([{ authMethodType: AuthMethodType.Password, position: 1 }]);
155155
});
156156

157-
it('does not exclude password method when standard login is disabled', () => {
157+
it('does not exclude password method when isPasswordLoginEnabledForAdminsOnly is disabled', () => {
158158
const authMethods = [
159159
{ authMethodType: AuthMethodType.Password, position: 1 },
160160
{ authMethodType: AuthMethodType.Shibboleth, position: 2 },
161161
];
162162
component.excludedAuthMethod = undefined;
163-
const result = component.filterAndSortAuthMethods(authMethods, false, true);
163+
const result = component.filterAndSortAuthMethods(authMethods, false, false);
164164
expect(result).toEqual([
165165
{ authMethodType: AuthMethodType.Password, position: 1 },
166166
{ authMethodType: AuthMethodType.Shibboleth, position: 2 },
@@ -175,8 +175,9 @@ describe('LogInComponent', () => {
175175
];
176176
const isBackdoor = false;
177177
component.excludedAuthMethod = AuthMethodType.Ip;
178-
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor);
178+
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor, false);
179179
expect(result).toEqual([
180+
{ authMethodType: AuthMethodType.Password, position: 1 },
180181
{ authMethodType: AuthMethodType.Shibboleth, position: 3 },
181182
]);
182183
});
@@ -188,9 +189,10 @@ describe('LogInComponent', () => {
188189
];
189190
const isBackdoor = false;
190191
component.excludedAuthMethod = undefined;
191-
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor);
192+
const result = component.filterAndSortAuthMethods(authMethods, isBackdoor, false);
192193
expect(result).toEqual([
193194
{ authMethodType: AuthMethodType.Shibboleth, position: 1 },
195+
{ authMethodType: AuthMethodType.Password, position: 2 },
194196
]);
195197
});
196198
});

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { TranslateModule } from '@ngx-translate/core';
2222
import uniqBy from 'lodash/uniqBy';
2323
import {
24+
combineLatest,
2425
combineLatestWith,
2526
map,
2627
Observable,
@@ -133,7 +134,7 @@ export class LogInComponent implements OnInit, OnDestroy {
133134
filter(routeData => !!routeData),
134135
map(data => data.isBackDoor),
135136
)),
136-
map(([methods, isBackdoor]) => this.filterAndSortAuthMethods(methods, isBackdoor, environment.auth.disableStandardLogin)),
137+
map(([methods, isBackdoor]) => this.filterAndSortAuthMethods(methods, isBackdoor, environment.auth.isPasswordLoginEnabledForAdminsOnly)),
137138
// ignore the ip authentication method when it's returned by the backend
138139
map((authMethods: AuthMethod[]) => uniqBy(authMethods.filter(a => a.authMethodType !== AuthMethodType.Ip), 'authMethodType')),
139140
);
@@ -154,20 +155,23 @@ export class LogInComponent implements OnInit, OnDestroy {
154155
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration);
155156

156157
this.canForgot$ = this.authorizationService.isAuthorized(FeatureID.EPersonForgotPassword).pipe(shareReplay({ refCount: false, bufferSize: 1 }));
157-
this.canShowDivider$ = this.canRegister$.pipe(
158-
combineLatestWith(this.canForgot$),
159-
map(([canRegister, canForgot]) => (canRegister || canForgot) && (!environment.auth.disableStandardLogin || this.isStandalonePage)),
158+
this.canShowDivider$ = combineLatest([
159+
this.canRegister$,
160+
this.canForgot$,
161+
this.route.data,
162+
]).pipe(
163+
map(([canRegister, canForgot, routeData]) => (canRegister || canForgot) && !routeData?.isBackDoor),
160164
filter(Boolean),
161165
);
162166
}
163167

164-
filterAndSortAuthMethods(authMethods: AuthMethod[], isBackdoor: boolean, isStandardLoginDisabled = false): AuthMethod[] {
168+
filterAndSortAuthMethods(authMethods: AuthMethod[], isBackdoor: boolean, isPasswordLoginEnabledForAdminsOnly = false): AuthMethod[] {
165169
return authMethods.filter((authMethod: AuthMethod) => {
166170
const methodComparison = (authM) => {
167171
if (isBackdoor) {
168172
return authM.authMethodType === AuthMethodType.Password;
169173
}
170-
if (!isStandardLoginDisabled) {
174+
if (isPasswordLoginEnabledForAdminsOnly) {
171175
return authM.authMethodType !== AuthMethodType.Password;
172176
}
173177
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
@@ -147,7 +147,7 @@ export class DefaultAppConfig implements AppConfig {
147147
// This is independent from the idle warning.
148148
timeLeftBeforeTokenRefresh: 2 * 60 * 1000, // 2 minutes
149149
},
150-
disableStandardLogin: true, // Enable the standard login form
150+
isPasswordLoginEnabledForAdminsOnly: false, // Enable the standard login form
151151
};
152152

153153
// Form settings

src/environments/environment.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const environment: BuildConfig = {
115115
// This is independent from the idle warning.
116116
timeLeftBeforeTokenRefresh: 20000, // 20 sec
117117
},
118-
disableStandardLogin: false,
118+
isPasswordLoginEnabledForAdminsOnly: true,
119119
},
120120

121121
// Form settings

0 commit comments

Comments
 (0)