diff --git a/src/app/+login-page/login-page.component.ts b/src/app/+login-page/login-page.component.ts index 0a249022d5..23f7efff73 100644 --- a/src/app/+login-page/login-page.component.ts +++ b/src/app/+login-page/login-page.component.ts @@ -10,7 +10,7 @@ import { AddAuthenticationMessageAction, AuthenticatedAction, AuthenticationSuccessAction, - ResetAuthenticationMessagesAction, SetIsStandalonePageInAuthMethodsAction + ResetAuthenticationMessagesAction } from '../core/auth/auth.actions'; import { hasValue, isNotEmpty } from '../shared/empty.util'; import { AuthTokenInfo } from '../core/auth/models/auth-token-info.model'; diff --git a/src/app/core/auth/auth.actions.ts b/src/app/core/auth/auth.actions.ts index 5913347c4c..650ecc511e 100644 --- a/src/app/core/auth/auth.actions.ts +++ b/src/app/core/auth/auth.actions.ts @@ -23,7 +23,6 @@ export const AuthActionTypes = { RETRIEVE_AUTH_METHODS: type('dspace/auth/RETRIEVE_AUTH_METHODS'), RETRIEVE_AUTH_METHODS_SUCCESS: type('dspace/auth/RETRIEVE_AUTH_METHODS_SUCCESS'), RETRIEVE_AUTH_METHODS_ERROR: type('dspace/auth/RETRIEVE_AUTH_METHODS_ERROR'), - SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS: type('dspace/auth/SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS'), REDIRECT_TOKEN_EXPIRED: type('dspace/auth/REDIRECT_TOKEN_EXPIRED'), REDIRECT_AUTHENTICATION_REQUIRED: type('dspace/auth/REDIRECT_AUTHENTICATION_REQUIRED'), REFRESH_TOKEN: type('dspace/auth/REFRESH_TOKEN'), @@ -366,23 +365,18 @@ export class RetrieveAuthMethodsSuccessAction implements Action { } } -/** - * Check if token is already present upon initial load. - * @class CheckAuthenticationTokenAction - * @implements {Action} - */ export class RetrieveAuthMethodsErrorAction implements Action { public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR; } -export class SetIsStandalonePageInAuthMethodsAction implements Action { +/*export class SetIsStandalonePageInAuthMethodsAction implements Action { type: string = AuthActionTypes.SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS; payload: boolean; constructor(isStandAlonePage: boolean) { this.payload = isStandAlonePage; } -} +}*/ /** * Change the redirect url. @@ -423,5 +417,4 @@ export type AuthActions | ResetAuthenticationMessagesAction | RetrieveAuthMethodsAction | RetrieveAuthMethodsSuccessAction - | SetIsStandalonePageInAuthMethodsAction | RetrieveAuthMethodsErrorAction; diff --git a/src/app/core/auth/auth.effects.ts b/src/app/core/auth/auth.effects.ts index 11fa0601c8..6af8a7f55e 100644 --- a/src/app/core/auth/auth.effects.ts +++ b/src/app/core/auth/auth.effects.ts @@ -28,9 +28,8 @@ import { RegistrationErrorAction, RegistrationSuccessAction, RetrieveAuthMethodsAction, - RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsSuccessAction, - GetJWTafterShibbLoginAction, StartShibbolethAuthenticationAction + GetJWTafterShibbLoginAction, StartShibbolethAuthenticationAction, RetrieveAuthMethodsErrorAction } from './auth.actions'; import { EPerson } from '../eperson/models/eperson.model'; import { AuthStatus } from './models/auth-status.model'; @@ -76,79 +75,79 @@ export class AuthEffects { @Effect() public authenticateSuccess$: Observable = this.actions$.pipe( - ofType(AuthActionTypes.AUTHENTICATE_SUCCESS), - tap((action: AuthenticationSuccessAction) => this.authService.storeToken(action.payload)), - map((action: AuthenticationSuccessAction) => new AuthenticatedAction(action.payload)) - ); + ofType(AuthActionTypes.AUTHENTICATE_SUCCESS), + tap((action: AuthenticationSuccessAction) => this.authService.storeToken(action.payload)), + map((action: AuthenticationSuccessAction) => new AuthenticatedAction(action.payload)) + ); @Effect() public authenticated$: Observable = this.actions$.pipe( - ofType(AuthActionTypes.AUTHENTICATED), - switchMap((action: AuthenticatedAction) => { - return this.authService.authenticatedUser(action.payload).pipe( - map((user: EPerson) => new AuthenticatedSuccessAction((user !== null), action.payload, user)), - catchError((error) => observableOf(new AuthenticatedErrorAction(error))),); - }) - ); + ofType(AuthActionTypes.AUTHENTICATED), + switchMap((action: AuthenticatedAction) => { + return this.authService.authenticatedUser(action.payload).pipe( + map((user: EPerson) => new AuthenticatedSuccessAction((user !== null), action.payload, user)), + catchError((error) => observableOf(new AuthenticatedErrorAction(error))),); + }) + ); // It means "reacts to this action but don't send another" - @Effect({ dispatch: false }) + @Effect({dispatch: false}) public authenticatedError$: Observable = this.actions$.pipe( - ofType(AuthActionTypes.AUTHENTICATED_ERROR), - tap((action: LogOutSuccessAction) => this.authService.removeToken()) - ); + ofType(AuthActionTypes.AUTHENTICATED_ERROR), + tap((action: LogOutSuccessAction) => this.authService.removeToken()) + ); @Effect() public checkToken$: Observable = this.actions$.pipe(ofType(AuthActionTypes.CHECK_AUTHENTICATION_TOKEN), - switchMap(() => { - return this.authService.hasValidAuthenticationToken().pipe( - map((token: AuthTokenInfo) => new AuthenticatedAction(token)), - catchError((error) => observableOf(new CheckAuthenticationTokenErrorAction())) - ); - }) - ); + switchMap(() => { + return this.authService.hasValidAuthenticationToken().pipe( + map((token: AuthTokenInfo) => new AuthenticatedAction(token)), + catchError((error) => observableOf(new CheckAuthenticationTokenErrorAction())) + ); + }) + ); @Effect() public checkTokenError$: Observable = this.actions$ .pipe( - ofType(AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_ERROR), - map(() => new RetrieveAuthMethodsAction()) + ofType(AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_ERROR), + map(() => new RetrieveAuthMethodsAction()) ) @Effect() public createUser$: Observable = this.actions$.pipe( - ofType(AuthActionTypes.REGISTRATION), - debounceTime(500), // to remove when functionality is implemented - switchMap((action: RegistrationAction) => { - return this.authService.create(action.payload).pipe( - map((user: EPerson) => new RegistrationSuccessAction(user)), - catchError((error) => observableOf(new RegistrationErrorAction(error))) - ); - }) - ); + ofType(AuthActionTypes.REGISTRATION), + debounceTime(500), // to remove when functionality is implemented + switchMap((action: RegistrationAction) => { + return this.authService.create(action.payload).pipe( + map((user: EPerson) => new RegistrationSuccessAction(user)), + catchError((error) => observableOf(new RegistrationErrorAction(error))) + ); + }) + ); @Effect() public refreshToken$: Observable = this.actions$.pipe(ofType(AuthActionTypes.REFRESH_TOKEN), - switchMap((action: RefreshTokenAction) => { - return this.authService.refreshAuthenticationToken(action.payload).pipe( - map((token: AuthTokenInfo) => new RefreshTokenSuccessAction(token)), - catchError((error) => observableOf(new RefreshTokenErrorAction())) - ); - }) - ); + switchMap((action: RefreshTokenAction) => { + return this.authService.refreshAuthenticationToken(action.payload).pipe( + map((token: AuthTokenInfo) => new RefreshTokenSuccessAction(token)), + catchError((error) => observableOf(new RefreshTokenErrorAction())) + ); + }) + ); // It means "reacts to this action but don't send another" - @Effect({ dispatch: false }) + @Effect({dispatch: false}) public refreshTokenSuccess$: Observable = this.actions$.pipe( - ofType(AuthActionTypes.REFRESH_TOKEN_SUCCESS), - tap((action: RefreshTokenSuccessAction) => this.authService.replaceToken(action.payload)) - ); + ofType(AuthActionTypes.REFRESH_TOKEN_SUCCESS), + tap((action: RefreshTokenSuccessAction) => this.authService.replaceToken(action.payload)) + ); /** * When the store is rehydrated in the browser, * clear a possible invalid token or authentication errors */ - @Effect({ dispatch: false }) + @Effect({dispatch: false}) public clearInvalidTokenOnRehydrate$: Observable = this.actions$.pipe( ofType(StoreActionTypes.REHYDRATE), switchMap(() => { @@ -173,7 +172,7 @@ export class AuthEffects { }) ); - @Effect({ dispatch: false }) + @Effect({dispatch: false}) public logOutSuccess$: Observable = this.actions$ .pipe(ofType(AuthActionTypes.LOG_OUT_SUCCESS), tap(() => this.authService.removeToken()), @@ -181,14 +180,14 @@ export class AuthEffects { tap(() => this.authService.refreshAfterLogout()) ); - @Effect({ dispatch: false }) + @Effect({dispatch: false}) public redirectToLogin$: Observable = this.actions$ .pipe(ofType(AuthActionTypes.REDIRECT_AUTHENTICATION_REQUIRED), tap(() => this.authService.removeToken()), tap(() => this.authService.redirectToLogin()) ); - @Effect({ dispatch: false }) + @Effect({dispatch: false}) public redirectToLoginTokenExpired$: Observable = this.actions$ .pipe( ofType(AuthActionTypes.REDIRECT_TOKEN_EXPIRED), @@ -201,12 +200,12 @@ export class AuthEffects { .pipe( ofType(AuthActionTypes.RETRIEVE_AUTH_METHODS), switchMap(() => { - return this.authService.retrieveAuthMethods() - .pipe( - map((location: any) => new RetrieveAuthMethodsSuccessAction(location)), - catchError((error) => observableOf(new RetrieveAuthMethodsErrorAction())) - ) - }) + return this.authService.retrieveAuthMethods() + .pipe( + map((location: any) => new RetrieveAuthMethodsSuccessAction(location)), + catchError((error) => observableOf(new RetrieveAuthMethodsErrorAction())) + ) + }) ) /** diff --git a/src/app/core/auth/auth.reducer.ts b/src/app/core/auth/auth.reducer.ts index a7882dd912..dee57279fc 100644 --- a/src/app/core/auth/auth.reducer.ts +++ b/src/app/core/auth/auth.reducer.ts @@ -8,7 +8,7 @@ import { LogOutErrorAction, RedirectWhenAuthenticationIsRequiredAction, RedirectWhenTokenExpiredAction, - RefreshTokenSuccessAction, RetrieveAuthMethodsSuccessAction, SetIsStandalonePageInAuthMethodsAction, + RefreshTokenSuccessAction, RetrieveAuthMethodsSuccessAction, SetRedirectUrlAction } from './auth.actions'; // import models @@ -220,7 +220,7 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut authMethods: (action as RetrieveAuthMethodsSuccessAction).payload }); - case AuthActionTypes.SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS: +/* case AuthActionTypes.SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS: const authMethods: AuthMethodModel[] = state.authMethods; const newAuthMethods: AuthMethodModel[] = new Array(); const isStandAlonePage: boolean = (action as SetIsStandalonePageInAuthMethodsAction).payload; @@ -228,7 +228,7 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut const newAuthMethod = new AuthMethodModel(authMethod.authMethodType, authMethod.location, isStandAlonePage); newAuthMethods.push(newAuthMethod); } - return Object.assign({}, state, {authMethods: newAuthMethods}); + return Object.assign({}, state, {authMethods: newAuthMethods});*/ case AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR: return Object.assign({}, state, { diff --git a/src/app/core/auth/models/auth-method.model.ts b/src/app/core/auth/models/auth-method.model.ts index 81cb5f6777..3d94afe6b8 100644 --- a/src/app/core/auth/models/auth-method.model.ts +++ b/src/app/core/auth/models/auth-method.model.ts @@ -4,9 +4,9 @@ import { ShibbConstants } from '../../../+login-page/shibbolethTargetPage/const/ export class AuthMethodModel { authMethodType: AuthMethodType; location?: string; - isStandalonePage? = true; + // isStandalonePage? = true; - constructor(authMethodName: string, location?: string, isStandAlonePage?: boolean) { + constructor(authMethodName: string, location?: string) { switch (authMethodName) { case 'ip': { this.authMethodType = AuthMethodType.Ip; diff --git a/src/app/shared/log-in/container/login-container.component.ts b/src/app/shared/log-in/container/login-container.component.ts index 11b8a0d8de..eb713abacb 100644 --- a/src/app/shared/log-in/container/login-container.component.ts +++ b/src/app/shared/log-in/container/login-container.component.ts @@ -4,7 +4,6 @@ import { Store } from '@ngrx/store'; import { CoreState } from '../../../core/core.reducers'; import { AuthMethodModel } from '../../../core/auth/models/auth-method.model'; - /** * This component represents a section that contains the submission license form. */ @@ -47,8 +46,7 @@ export class LoginContainerComponent implements OnInit { * Find the correct component based on the AuthMethod's type */ getAuthMethodContent(): string { - console.log('Trying to render login component for type: ', this.authMethodModel.authMethodType); - return rendersAuthMethodType(this.authMethodModel.authMethodType) + return rendersAuthMethodType(this.authMethodModel.authMethodType) } } diff --git a/src/app/shared/log-in/log-in.component.ts b/src/app/shared/log-in/log-in.component.ts index 026fe8d867..e7e5faa824 100644 --- a/src/app/shared/log-in/log-in.component.ts +++ b/src/app/shared/log-in/log-in.component.ts @@ -6,7 +6,6 @@ import { getAuthenticationMethods, isAuthenticated, isAuthenticationLoading } fr import { CoreState } from '../../core/core.reducers'; import { filter, takeWhile, } from 'rxjs/operators'; import { AuthService } from '../../core/auth/auth.service'; -import { SetIsStandalonePageInAuthMethodsAction } from '../../core/auth/auth.actions'; @Component({ selector: 'ds-log-in', @@ -46,7 +45,7 @@ export class LogInComponent implements OnInit, OnDestroy { ngOnInit(): void { - this.store.dispatch(new SetIsStandalonePageInAuthMethodsAction(this.isStandalonePage)); + // this.store.dispatch(new SetIsStandalonePageInAuthMethodsAction(this.isStandalonePage)); this.authMethodData = this.store.pipe( select(getAuthenticationMethods), diff --git a/src/app/shared/log-in/methods/password/log-in-password.component.html b/src/app/shared/log-in/methods/password/log-in-password.component.html index c9a76b5930..f49ceff575 100644 --- a/src/app/shared/log-in/methods/password/log-in-password.component.html +++ b/src/app/shared/log-in/methods/password/log-in-password.component.html @@ -1,4 +1,3 @@ -
diff --git a/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts b/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts index 197398a933..27f5156605 100644 --- a/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts +++ b/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts @@ -10,7 +10,7 @@ import { AuthMethodModel } from '../../../../core/auth/models/auth-method.model' import { FormBuilder } from '@angular/forms'; import { select, Store } from '@ngrx/store'; import { CoreState } from '../../../../core/core.reducers'; -import { StartShibbolethAuthenticationAction } from '../../../../core/auth/auth.actions'; +import { SetRedirectUrlAction, StartShibbolethAuthenticationAction } from '../../../../core/auth/auth.actions'; import { Observable } from 'rxjs'; import { isAuthenticated, @@ -58,6 +58,7 @@ export class LogInShibbolethComponent implements OnInit { } submit() { + this.store.dispatch(new SetRedirectUrlAction('/mytest/url')); this.store.dispatch(new StartShibbolethAuthenticationAction(this.authMethodModel)); // https://host/Shibboleth.sso/Login?target=https://host/shibboleth window.location.href = this.injectedAuthMethodModel.location;