Revert "[CSTPER-144] Fixed issue with authorization request encountered while logging-in with external idp"

This reverts commit 73a9fe16
This commit is contained in:
Giuseppe Digilio
2021-07-19 17:54:02 +02:00
parent 98cecd3e84
commit fbde0cbad9
8 changed files with 48 additions and 206 deletions

View File

@@ -294,13 +294,10 @@ export class ResetAuthenticationMessagesAction implements Action {
export class RetrieveAuthMethodsAction implements Action { export class RetrieveAuthMethodsAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS; public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS;
payload: { payload: AuthStatus;
status: AuthStatus;
blocking: boolean;
};
constructor(status: AuthStatus, blocking: boolean) { constructor(authStatus: AuthStatus) {
this.payload = { status, blocking }; this.payload = authStatus;
} }
} }
@@ -311,14 +308,10 @@ export class RetrieveAuthMethodsAction implements Action {
*/ */
export class RetrieveAuthMethodsSuccessAction implements Action { export class RetrieveAuthMethodsSuccessAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_SUCCESS; public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_SUCCESS;
payload: AuthMethod[];
payload: { constructor(authMethods: AuthMethod[] ) {
authMethods: AuthMethod[]; this.payload = authMethods;
blocking: boolean;
};
constructor(authMethods: AuthMethod[], blocking: boolean ) {
this.payload = { authMethods, blocking };
} }
} }
@@ -329,12 +322,6 @@ export class RetrieveAuthMethodsSuccessAction implements Action {
*/ */
export class RetrieveAuthMethodsErrorAction implements Action { export class RetrieveAuthMethodsErrorAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR; public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR;
payload: boolean;
constructor(blocking: boolean) {
this.payload = blocking;
}
} }
/** /**

View File

@@ -43,12 +43,10 @@ describe('AuthEffects', () => {
let initialState; let initialState;
let token; let token;
let store: MockStore<AppState>; let store: MockStore<AppState>;
let authStatus;
function init() { function init() {
authServiceStub = new AuthServiceStub(); authServiceStub = new AuthServiceStub();
token = authServiceStub.getToken(); token = authServiceStub.getToken();
authStatus = Object.assign(new AuthStatus(), {});
initialState = { initialState = {
core: { core: {
auth: { auth: {
@@ -219,41 +217,19 @@ describe('AuthEffects', () => {
expect(authEffects.checkTokenCookie$).toBeObservable(expected); expect(authEffects.checkTokenCookie$).toBeObservable(expected);
}); });
describe('on CSR', () => {
it('should return a RETRIEVE_AUTH_METHODS action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action when authenticated is false', () => { it('should return a RETRIEVE_AUTH_METHODS action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action when authenticated is false', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue( spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(
observableOf( observableOf(
{ authenticated: false }) { authenticated: false })
); );
spyOn((authEffects as any).authService, 'getRetrieveAuthMethodsAction').and.returnValue(
new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus, false)
);
actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE } }); actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE } });
const expected = cold('--b-', { b: new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus, false) }); const expected = cold('--b-', { b: new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus) });
expect(authEffects.checkTokenCookie$).toBeObservable(expected); expect(authEffects.checkTokenCookie$).toBeObservable(expected);
}); });
}); });
describe('on SSR', () => {
it('should return a RETRIEVE_AUTH_METHODS action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action when authenticated is false', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(
observableOf(
{ authenticated: false })
);
spyOn((authEffects as any).authService, 'getRetrieveAuthMethodsAction').and.returnValue(
new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus, true)
);
actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE } });
const expected = cold('--b-', { b: new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus, true) });
expect(authEffects.checkTokenCookie$).toBeObservable(expected);
});
});
});
describe('when check token failed', () => { describe('when check token failed', () => {
it('should return a AUTHENTICATED_ERROR action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action', () => { it('should return a AUTHENTICATED_ERROR action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(observableThrow(new Error('Message Error test'))); spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(observableThrow(new Error('Message Error test')));
@@ -383,17 +359,11 @@ describe('AuthEffects', () => {
describe('retrieveMethods$', () => { describe('retrieveMethods$', () => {
describe('on CSR', () => {
describe('when retrieve authentication methods succeeded', () => { describe('when retrieve authentication methods succeeded', () => {
it('should return a RETRIEVE_AUTH_METHODS_SUCCESS action in response to a RETRIEVE_AUTH_METHODS action', () => { it('should return a RETRIEVE_AUTH_METHODS_SUCCESS action in response to a RETRIEVE_AUTH_METHODS action', () => {
actions = hot('--a-', { a: actions = hot('--a-', { a: { type: AuthActionTypes.RETRIEVE_AUTH_METHODS } });
{
type: AuthActionTypes.RETRIEVE_AUTH_METHODS,
payload: { status: authStatus, blocking: false}
}
});
const expected = cold('--b-', { b: new RetrieveAuthMethodsSuccessAction(authMethodsMock, false) }); const expected = cold('--b-', { b: new RetrieveAuthMethodsSuccessAction(authMethodsMock) });
expect(authEffects.retrieveMethods$).toBeObservable(expected); expect(authEffects.retrieveMethods$).toBeObservable(expected);
}); });
@@ -403,56 +373,15 @@ describe('AuthEffects', () => {
it('should return a RETRIEVE_AUTH_METHODS_ERROR action in response to a RETRIEVE_AUTH_METHODS action', () => { it('should return a RETRIEVE_AUTH_METHODS_ERROR action in response to a RETRIEVE_AUTH_METHODS action', () => {
spyOn((authEffects as any).authService, 'retrieveAuthMethodsFromAuthStatus').and.returnValue(observableThrow('')); spyOn((authEffects as any).authService, 'retrieveAuthMethodsFromAuthStatus').and.returnValue(observableThrow(''));
actions = hot('--a-', { a: actions = hot('--a-', { a: { type: AuthActionTypes.RETRIEVE_AUTH_METHODS } });
{
type: AuthActionTypes.RETRIEVE_AUTH_METHODS,
payload: { status: authStatus, blocking: false}
}
});
const expected = cold('--b-', { b: new RetrieveAuthMethodsErrorAction(false) }); const expected = cold('--b-', { b: new RetrieveAuthMethodsErrorAction() });
expect(authEffects.retrieveMethods$).toBeObservable(expected); expect(authEffects.retrieveMethods$).toBeObservable(expected);
}); });
}); });
}); });
describe('on SSR', () => {
describe('when retrieve authentication methods succeeded', () => {
it('should return a RETRIEVE_AUTH_METHODS_SUCCESS action in response to a RETRIEVE_AUTH_METHODS action', () => {
actions = hot('--a-', { a:
{
type: AuthActionTypes.RETRIEVE_AUTH_METHODS,
payload: { status: authStatus, blocking: true}
}
});
const expected = cold('--b-', { b: new RetrieveAuthMethodsSuccessAction(authMethodsMock, true) });
expect(authEffects.retrieveMethods$).toBeObservable(expected);
});
});
describe('when retrieve authentication methods failed', () => {
it('should return a RETRIEVE_AUTH_METHODS_ERROR action in response to a RETRIEVE_AUTH_METHODS action', () => {
spyOn((authEffects as any).authService, 'retrieveAuthMethodsFromAuthStatus').and.returnValue(observableThrow(''));
actions = hot('--a-', { a:
{
type: AuthActionTypes.RETRIEVE_AUTH_METHODS,
payload: { status: authStatus, blocking: true}
}
});
const expected = cold('--b-', { b: new RetrieveAuthMethodsErrorAction(true) });
expect(authEffects.retrieveMethods$).toBeObservable(expected);
});
});
});
});
describe('clearInvalidTokenOnRehydrate$', () => { describe('clearInvalidTokenOnRehydrate$', () => {
beforeEach(() => { beforeEach(() => {

View File

@@ -1,13 +1,14 @@
import { Injectable, NgZone } from '@angular/core'; import { Injectable, NgZone } from '@angular/core';
import { import {
asyncScheduler,
combineLatest as observableCombineLatest, combineLatest as observableCombineLatest,
Observable, Observable,
of as observableOf, of as observableOf,
timer, queueScheduler,
asyncScheduler, queueScheduler timer
} from 'rxjs'; } from 'rxjs';
import { catchError, filter, map, switchMap, take, tap, observeOn } from 'rxjs/operators'; import { catchError, filter, map, observeOn, switchMap, take, tap } from 'rxjs/operators';
// import @ngrx // import @ngrx
import { Actions, Effect, ofType } from '@ngrx/effects'; import { Actions, Effect, ofType } from '@ngrx/effects';
import { Action, select, Store } from '@ngrx/store'; import { Action, select, Store } from '@ngrx/store';
@@ -43,7 +44,8 @@ import {
RetrieveAuthMethodsAction, RetrieveAuthMethodsAction,
RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsErrorAction,
RetrieveAuthMethodsSuccessAction, RetrieveAuthMethodsSuccessAction,
RetrieveTokenAction, SetUserAsIdleAction RetrieveTokenAction,
SetUserAsIdleAction
} from './auth.actions'; } from './auth.actions';
import { hasValue } from '../../shared/empty.util'; import { hasValue } from '../../shared/empty.util';
import { environment } from '../../../environments/environment'; import { environment } from '../../../environments/environment';
@@ -161,7 +163,7 @@ export class AuthEffects {
if (response.authenticated) { if (response.authenticated) {
return new RetrieveTokenAction(); return new RetrieveTokenAction();
} else { } else {
return this.authService.getRetrieveAuthMethodsAction(response); return new RetrieveAuthMethodsAction(response);
} }
}), }),
catchError((error) => observableOf(new AuthenticatedErrorAction(error))) catchError((error) => observableOf(new AuthenticatedErrorAction(error)))
@@ -250,10 +252,10 @@ export class AuthEffects {
.pipe( .pipe(
ofType(AuthActionTypes.RETRIEVE_AUTH_METHODS), ofType(AuthActionTypes.RETRIEVE_AUTH_METHODS),
switchMap((action: RetrieveAuthMethodsAction) => { switchMap((action: RetrieveAuthMethodsAction) => {
return this.authService.retrieveAuthMethodsFromAuthStatus(action.payload.status) return this.authService.retrieveAuthMethodsFromAuthStatus(action.payload)
.pipe( .pipe(
map((authMethodModels: AuthMethod[]) => new RetrieveAuthMethodsSuccessAction(authMethodModels, action.payload.blocking)), map((authMethodModels: AuthMethod[]) => new RetrieveAuthMethodsSuccessAction(authMethodModels)),
catchError((error) => observableOf(new RetrieveAuthMethodsErrorAction(action.payload.blocking))) catchError((error) => observableOf(new RetrieveAuthMethodsErrorAction()))
); );
}) })
); );

View File

@@ -23,7 +23,9 @@ import {
RetrieveAuthMethodsAction, RetrieveAuthMethodsAction,
RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsErrorAction,
RetrieveAuthMethodsSuccessAction, RetrieveAuthMethodsSuccessAction,
SetRedirectUrlAction, SetUserAsIdleAction, UnsetUserAsIdleAction SetRedirectUrlAction,
SetUserAsIdleAction,
UnsetUserAsIdleAction
} from './auth.actions'; } from './auth.actions';
import { AuthTokenInfo } from './models/auth-token-info.model'; import { AuthTokenInfo } from './models/auth-token-info.model';
import { EPersonMock } from '../../shared/testing/eperson.mock'; import { EPersonMock } from '../../shared/testing/eperson.mock';
@@ -551,7 +553,7 @@ describe('authReducer', () => {
authMethods: [], authMethods: [],
idle: false idle: false
}; };
const action = new RetrieveAuthMethodsAction(new AuthStatus(), true); const action = new RetrieveAuthMethodsAction(new AuthStatus());
const newState = authReducer(initialState, action); const newState = authReducer(initialState, action);
state = { state = {
authenticated: false, authenticated: false,
@@ -577,7 +579,7 @@ describe('authReducer', () => {
new AuthMethod(AuthMethodType.Password), new AuthMethod(AuthMethodType.Password),
new AuthMethod(AuthMethodType.Shibboleth, 'location') new AuthMethod(AuthMethodType.Shibboleth, 'location')
]; ];
const action = new RetrieveAuthMethodsSuccessAction(authMethods, false); const action = new RetrieveAuthMethodsSuccessAction(authMethods);
const newState = authReducer(initialState, action); const newState = authReducer(initialState, action);
state = { state = {
authenticated: false, authenticated: false,
@@ -590,33 +592,7 @@ describe('authReducer', () => {
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
it('should properly set the state, in response to a RETRIEVE_AUTH_METHODS_SUCCESS action with blocking as true', () => { it('should properly set the state, in response to a RETRIEVE_AUTH_METHODS_ERROR action', () => {
initialState = {
authenticated: false,
loaded: false,
blocking: true,
loading: true,
authMethods: [],
idle: false
};
const authMethods = [
new AuthMethod(AuthMethodType.Password),
new AuthMethod(AuthMethodType.Shibboleth, 'location')
];
const action = new RetrieveAuthMethodsSuccessAction(authMethods, true);
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
blocking: true,
loading: false,
authMethods: authMethods,
idle: false
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a RETRIEVE_AUTH_METHODS_ERROR action ', () => {
initialState = { initialState = {
authenticated: false, authenticated: false,
loaded: false, loaded: false,
@@ -626,7 +602,7 @@ describe('authReducer', () => {
idle: false idle: false
}; };
const action = new RetrieveAuthMethodsErrorAction(false); const action = new RetrieveAuthMethodsErrorAction();
const newState = authReducer(initialState, action); const newState = authReducer(initialState, action);
state = { state = {
authenticated: false, authenticated: false,
@@ -680,27 +656,4 @@ describe('authReducer', () => {
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
it('should properly set the state, in response to a RETRIEVE_AUTH_METHODS_ERROR action with blocking as true', () => {
initialState = {
authenticated: false,
loaded: false,
blocking: true,
loading: true,
authMethods: [],
idle: false
};
const action = new RetrieveAuthMethodsErrorAction(true);
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
blocking: true,
loading: false,
authMethods: [new AuthMethod(AuthMethodType.Password)],
idle: false
};
expect(newState).toEqual(state);
});
}); });

View File

@@ -10,7 +10,6 @@ import {
RedirectWhenTokenExpiredAction, RedirectWhenTokenExpiredAction,
RefreshTokenSuccessAction, RefreshTokenSuccessAction,
RetrieveAuthenticatedEpersonSuccessAction, RetrieveAuthenticatedEpersonSuccessAction,
RetrieveAuthMethodsErrorAction,
RetrieveAuthMethodsSuccessAction, RetrieveAuthMethodsSuccessAction,
SetRedirectUrlAction SetRedirectUrlAction
} from './auth.actions'; } from './auth.actions';
@@ -217,14 +216,14 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut
case AuthActionTypes.RETRIEVE_AUTH_METHODS_SUCCESS: case AuthActionTypes.RETRIEVE_AUTH_METHODS_SUCCESS:
return Object.assign({}, state, { return Object.assign({}, state, {
loading: false, loading: false,
blocking: (action as RetrieveAuthMethodsSuccessAction).payload.blocking, blocking: false,
authMethods: (action as RetrieveAuthMethodsSuccessAction).payload.authMethods authMethods: (action as RetrieveAuthMethodsSuccessAction).payload
}); });
case AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR: case AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR:
return Object.assign({}, state, { return Object.assign({}, state, {
loading: false, loading: false,
blocking: (action as RetrieveAuthMethodsErrorAction).payload, blocking: false,
authMethods: [new AuthMethod(AuthMethodType.Password)] authMethods: [new AuthMethod(AuthMethodType.Password)]
}); });

View File

@@ -34,9 +34,9 @@ import {
} from './selectors'; } from './selectors';
import { AppState } from '../../app.reducer'; import { AppState } from '../../app.reducer';
import { import {
CheckAuthenticationTokenAction, RefreshTokenAction, CheckAuthenticationTokenAction,
RefreshTokenAction,
ResetAuthenticationMessagesAction, ResetAuthenticationMessagesAction,
RetrieveAuthMethodsAction,
SetRedirectUrlAction, SetRedirectUrlAction,
SetUserAsIdleAction, SetUserAsIdleAction,
UnsetUserAsIdleAction UnsetUserAsIdleAction
@@ -573,15 +573,6 @@ export class AuthService {
); );
} }
/**
* Return a new instance of RetrieveAuthMethodsAction
*
* @param authStatus The auth status
*/
getRetrieveAuthMethodsAction(authStatus: AuthStatus): RetrieveAuthMethodsAction {
return new RetrieveAuthMethodsAction(authStatus, false);
}
/** /**
* Determines if current user is idle * Determines if current user is idle
* @returns {Observable<boolean>} * @returns {Observable<boolean>}

View File

@@ -4,13 +4,12 @@ import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { isNotEmpty, hasValue } from '../../shared/empty.util'; import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { HttpOptions } from '../dspace-rest/dspace-rest.service'; import { HttpOptions } from '../dspace-rest/dspace-rest.service';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { AuthStatus } from './models/auth-status.model'; import { AuthStatus } from './models/auth-status.model';
import { AuthTokenInfo } from './models/auth-token-info.model'; import { AuthTokenInfo } from './models/auth-token-info.model';
import { RemoteData } from '../data/remote-data'; import { RemoteData } from '../data/remote-data';
import { RetrieveAuthMethodsAction } from './auth.actions';
/** /**
* The auth service. * The auth service.
@@ -61,13 +60,4 @@ export class ServerAuthService extends AuthService {
map((rd: RemoteData<AuthStatus>) => Object.assign(new AuthStatus(), rd.payload)) map((rd: RemoteData<AuthStatus>) => Object.assign(new AuthStatus(), rd.payload))
); );
} }
/**
* Return a new instance of RetrieveAuthMethodsAction
*
* @param authStatus The auth status
*/
getRetrieveAuthMethodsAction(authStatus: AuthStatus): RetrieveAuthMethodsAction {
return new RetrieveAuthMethodsAction(authStatus, true);
}
} }

View File

@@ -6,7 +6,6 @@ import { EPerson } from '../../core/eperson/models/eperson.model';
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils'; import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
import { AuthMethod } from '../../core/auth/models/auth.method'; import { AuthMethod } from '../../core/auth/models/auth.method';
import { hasValue } from '../empty.util'; import { hasValue } from '../empty.util';
import { RetrieveAuthMethodsAction } from '../../core/auth/auth.actions';
export const authMethodsMock = [ export const authMethodsMock = [
new AuthMethod('password'), new AuthMethod('password'),
@@ -167,12 +166,4 @@ export class AuthServiceStub {
clearRedirectUrl() { clearRedirectUrl() {
return; return;
} }
public replaceToken(token: AuthTokenInfo) {
return token;
}
getRetrieveAuthMethodsAction(authStatus: AuthStatus): RetrieveAuthMethodsAction {
return;
}
} }