mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-21636] Fix redirect URL for viewer (#6564)
* fix redirect URL for viewer * fix unit fix login SSO show when user is logged in * update js-api * remove protractor change
This commit is contained in:
@@ -150,20 +150,21 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
this.initFormFieldsDefault();
|
||||
this.initFormFieldsMessages();
|
||||
|
||||
if (this.authService.isOauth()) {
|
||||
const oauth: OauthConfigModel = this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null);
|
||||
if (oauth && oauth.implicitFlow) {
|
||||
this.implicitFlow = true;
|
||||
}
|
||||
|
||||
if (oauth && oauth.silentLogin && !this.authService.isLoggedIn()) {
|
||||
this.alfrescoApiService.getInstance().oauth2Auth.implicitLogin();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.authService.isLoggedIn()) {
|
||||
this.router.navigate([this.successRoute]);
|
||||
} else {
|
||||
|
||||
if (this.authService.isOauth()) {
|
||||
const oauth: OauthConfigModel = this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null);
|
||||
if (oauth && oauth.implicitFlow) {
|
||||
this.implicitFlow = true;
|
||||
}
|
||||
|
||||
if (oauth && oauth.silentLogin) {
|
||||
this.alfrescoApiService.getInstance().oauth2Auth.implicitLogin();
|
||||
}
|
||||
}
|
||||
|
||||
this.route.queryParams.subscribe((params: Params) => {
|
||||
const url = params['redirectUrl'];
|
||||
const provider = this.appConfig.get<string>(AppConfigValues.PROVIDERS);
|
||||
|
@@ -50,7 +50,6 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
|
||||
private storageService: StorageService
|
||||
) {
|
||||
}
|
||||
ls;
|
||||
|
||||
abstract checkLogin(
|
||||
activeRoute: ActivatedRouteSnapshot,
|
||||
@@ -63,11 +62,14 @@ ls;
|
||||
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
|
||||
const redirectFragment = this.storageService.getItem('loginFragment');
|
||||
|
||||
if (this.authenticationService.isLoggedIn() || this.withCredentials) {
|
||||
if (redirectFragment) {
|
||||
|
||||
if (redirectFragment && this.getLoginRoute() !== redirectFragment) {
|
||||
this.storageService.removeItem('loginFragment');
|
||||
return this.router.createUrlTree([redirectFragment]);
|
||||
this.redirectToUrl(redirectFragment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -86,24 +88,32 @@ ls;
|
||||
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
return this.canActivate(route, state);
|
||||
}
|
||||
protected redirectToUrl(provider: string, url: string) {
|
||||
const pathToLogin = `/${this.getLoginRoute()}`;
|
||||
|
||||
protected redirectToUrl(url: string) {
|
||||
let urlToRedirect;
|
||||
|
||||
this.dialog.closeAll();
|
||||
|
||||
if (!this.authenticationService.isOauth()) {
|
||||
this.authenticationService.setRedirect({ provider, url });
|
||||
if (!this.authenticationService.isLoggedIn()) {
|
||||
const pathToLogin = `/${this.getLoginRoute()}`;
|
||||
|
||||
urlToRedirect = `${pathToLogin}?redirectUrl=${url}`;
|
||||
this.router.navigateByUrl(urlToRedirect);
|
||||
} else if (this.getOauthConfig().silentLogin && !this.authenticationService.isPublicUrl()) {
|
||||
this.authenticationService.ssoImplicitLogin();
|
||||
if (!this.authenticationService.isOauth()) {
|
||||
this.authenticationService.setRedirect({
|
||||
provider: this.getProvider(),
|
||||
url
|
||||
});
|
||||
|
||||
urlToRedirect = `${pathToLogin}?redirectUrl=${url}`;
|
||||
this.router.navigateByUrl(urlToRedirect);
|
||||
} else if (this.getOauthConfig().silentLogin && !this.authenticationService.isPublicUrl()) {
|
||||
this.authenticationService.ssoImplicitLogin();
|
||||
} else {
|
||||
urlToRedirect = pathToLogin;
|
||||
this.router.navigateByUrl(urlToRedirect);
|
||||
}
|
||||
} else {
|
||||
urlToRedirect = pathToLogin;
|
||||
this.router.navigateByUrl(urlToRedirect);
|
||||
this.router.navigateByUrl(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected getOauthConfig(): OauthConfigModel {
|
||||
@@ -126,6 +136,16 @@ ls;
|
||||
);
|
||||
}
|
||||
|
||||
protected getProvider(): string {
|
||||
return (
|
||||
this.appConfigService &&
|
||||
this.appConfigService.get<string>(
|
||||
AppConfigValues.PROVIDERS,
|
||||
'ALL'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected isOAuthWithoutSilentLogin(): boolean {
|
||||
const oauth = this.appConfigService.get<OauthConfigModel>(
|
||||
AppConfigValues.OAUTHCONFIG,
|
||||
|
@@ -64,7 +64,8 @@ describe('AuthGuardService BPM', () => {
|
||||
redirectUri: '/',
|
||||
clientId: 'activiti',
|
||||
publicUrl: 'settings',
|
||||
scope: 'openid'
|
||||
scope: 'openid',
|
||||
provider: 'BPM'
|
||||
};
|
||||
|
||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'abc'};
|
||||
|
@@ -40,7 +40,7 @@ export class AuthGuardBpm extends AuthGuardBase {
|
||||
if (this.authenticationService.isBpmLoggedIn() || this.withCredentials) {
|
||||
return true;
|
||||
}
|
||||
this.redirectToUrl('BPM', redirectUrl);
|
||||
this.redirectToUrl(redirectUrl);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ export class AuthGuardEcm extends AuthGuardBase {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.redirectToUrl('ECM', redirectUrl);
|
||||
this.redirectToUrl(redirectUrl);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@@ -23,12 +23,14 @@ import { AuthenticationService } from './authentication.service';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { StorageService } from './storage.service';
|
||||
|
||||
describe('AuthGuardService', () => {
|
||||
let state;
|
||||
let authService: AuthenticationService;
|
||||
let router: Router;
|
||||
let authGuard: AuthGuard;
|
||||
let storageService: StorageService;
|
||||
let appConfigService: AppConfigService;
|
||||
|
||||
setupTestBed({
|
||||
@@ -48,6 +50,7 @@ describe('AuthGuardService', () => {
|
||||
|
||||
appConfigService.config.auth = {};
|
||||
appConfigService.config.oauth2 = {};
|
||||
storageService = TestBed.inject(StorageService);
|
||||
});
|
||||
|
||||
it('if the alfresco js api is logged in should canActivate be true', async(async () => {
|
||||
@@ -76,6 +79,18 @@ describe('AuthGuardService', () => {
|
||||
expect(await authGuard.canActivate(null, route)).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should not redirect to login', async(async () => {
|
||||
storageService.setItem('loginFragment', 'login');
|
||||
|
||||
spyOn(router, 'navigateByUrl').and.stub();
|
||||
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||
appConfigService.config.oauth2.silentLogin = false;
|
||||
|
||||
expect(await authGuard.canActivate(null, state)).toBeTruthy();
|
||||
expect(router.navigateByUrl).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should redirect url if the User is NOT logged in and isOAuthWithoutSilentLogin', async(async () => {
|
||||
spyOn(router, 'navigateByUrl').and.stub();
|
||||
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||
@@ -124,6 +139,7 @@ describe('AuthGuardService', () => {
|
||||
it('should set redirect url with query params', async(async () => {
|
||||
state.url = 'some-url;q=query';
|
||||
appConfigService.config.loginRoute = 'login';
|
||||
appConfigService.config.provider = 'ALL';
|
||||
|
||||
spyOn(router, 'navigateByUrl');
|
||||
spyOn(authService, 'setRedirect');
|
||||
|
@@ -45,23 +45,23 @@ export class AuthGuard extends AuthGuardBase {
|
||||
|
||||
ticketChange(event: StorageEvent) {
|
||||
if (event.key.includes('ticket-ECM') && event.newValue !== event.oldValue) {
|
||||
this.ticketChangeRedirect(event, 'ECM');
|
||||
this.ticketChangeRedirect(event);
|
||||
}
|
||||
|
||||
if (event.key.includes('ticket-BPM') && event.newValue !== event.oldValue) {
|
||||
this.ticketChangeRedirect(event, 'BPM');
|
||||
this.ticketChangeRedirect(event);
|
||||
}
|
||||
|
||||
if (event.key.endsWith(JwtHelperService.USER_ACCESS_TOKEN) &&
|
||||
this.jwtHelperService.getValueFromToken(event.newValue, JwtHelperService.USER_PREFERRED_USERNAME) !==
|
||||
this.jwtHelperService.getValueFromToken(event.oldValue, JwtHelperService.USER_PREFERRED_USERNAME)) {
|
||||
this.ticketChangeRedirect(event, 'ALL');
|
||||
this.ticketChangeRedirect(event);
|
||||
}
|
||||
}
|
||||
|
||||
private ticketChangeRedirect(event: StorageEvent, provider: string) {
|
||||
private ticketChangeRedirect(event: StorageEvent) {
|
||||
if (!event.newValue) {
|
||||
this.redirectToUrl(provider, this.router.url);
|
||||
this.redirectToUrl(this.router.url);
|
||||
} else {
|
||||
window.location.reload();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export class AuthGuard extends AuthGuardBase {
|
||||
if (this.authenticationService.isLoggedIn() || this.withCredentials) {
|
||||
return true;
|
||||
}
|
||||
this.redirectToUrl('ALL', redirectUrl);
|
||||
this.redirectToUrl( redirectUrl);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
54
package-lock.json
generated
54
package-lock.json
generated
@@ -5,9 +5,9 @@
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@alfresco/js-api": {
|
||||
"version": "4.3.0-61350fee919fbeb2b6c949621161b6b076d44133",
|
||||
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-4.3.0-61350fee919fbeb2b6c949621161b6b076d44133.tgz",
|
||||
"integrity": "sha512-Q6oStMDxWU5psD4UnRBB1ri8Md5A+SgI8fNx3l7RkcEvSJvU3p1cfJe/2BfM4wJK1AU6NHFUdWAH6z2EAA8K/A==",
|
||||
"version": "4.3.0-f117dba26d7c31cb56a6cf40eb84dff89a174971",
|
||||
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-4.3.0-f117dba26d7c31cb56a6cf40eb84dff89a174971.tgz",
|
||||
"integrity": "sha512-aNDqBYpfRVem1UivNWW0VAO+e8JZIo7ATTsf+MrIWWkM+2JiKKc+ByG8uj5HjGt0KekwlZh/tXbAwbNHvpo+PA==",
|
||||
"requires": {
|
||||
"event-emitter": "^0.3.5",
|
||||
"minimatch": "3.0.4",
|
||||
@@ -9308,12 +9308,6 @@
|
||||
"color-name": "~1.1.4"
|
||||
}
|
||||
},
|
||||
"commander": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz",
|
||||
"integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==",
|
||||
"dev": true
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz",
|
||||
@@ -17134,12 +17128,6 @@
|
||||
"integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==",
|
||||
"dev": true
|
||||
},
|
||||
"commander": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz",
|
||||
"integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==",
|
||||
"dev": true
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz",
|
||||
@@ -26097,9 +26085,9 @@
|
||||
}
|
||||
},
|
||||
"typedoc": {
|
||||
"version": "0.20.16",
|
||||
"resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.20.16.tgz",
|
||||
"integrity": "sha512-xqIL8lT6ZE3QpP0GN30ckeTR05NSEkrP2pXQlNhC0OFkbvnjqJtDUcWSmCO15BuYyu4qsEbZT+tKYFEAt9Jxew==",
|
||||
"version": "0.20.14",
|
||||
"resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.20.14.tgz",
|
||||
"integrity": "sha512-9bsZp5/qkl+gDSv9DRvHbfbY8Sr0tD8fKx7hNIvcluxeAFzBCEo9o0qDCdLUZw+/axbfd9TaqHvSuCVRu+YH6Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"colors": "^1.4.0",
|
||||
@@ -26112,19 +26100,19 @@
|
||||
"progress": "^2.0.3",
|
||||
"shelljs": "^0.8.4",
|
||||
"shiki": "^0.2.7",
|
||||
"typedoc-default-themes": "^0.12.4"
|
||||
"typedoc-default-themes": "0.12.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs-extra": {
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
|
||||
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz",
|
||||
"integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"at-least-node": "^1.0.0",
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^2.0.0"
|
||||
"universalify": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"jsonfile": {
|
||||
@@ -26135,20 +26123,28 @@
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6",
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",
|
||||
"integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"typedoc-default-themes": {
|
||||
"version": "0.12.4",
|
||||
"resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.12.4.tgz",
|
||||
"integrity": "sha512-EZiXBUpogsYWe0dLgy47J8yRZCd+HAn9woGzO28XJxxSCSwZRYGKeQiw1KjyIcm3cBtLWUXiPD5+Bgx24GgZjg==",
|
||||
"version": "0.12.1",
|
||||
"resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.12.1.tgz",
|
||||
"integrity": "sha512-6PEvV+/kWAJeUwEtrKgIsZQSbybW5DGCr6s2mMjHsDplpgN8iBHI52UbA+2C+c2TMCxBNMK9TMS6pdeIdwsLSw==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
|
@@ -71,7 +71,7 @@
|
||||
"process services-cloud"
|
||||
],
|
||||
"dependencies": {
|
||||
"@alfresco/js-api": "4.3.0-61350fee919fbeb2b6c949621161b6b076d44133",
|
||||
"@alfresco/js-api": "^4.3.0-f117dba26d7c31cb56a6cf40eb84dff89a174971",
|
||||
"@angular/animations": "^10.0.4",
|
||||
"@angular/cdk": "10.1.3",
|
||||
"@angular/common": "^10.0.4",
|
||||
@@ -170,7 +170,7 @@
|
||||
"ts-node": "^9.0.0",
|
||||
"tsconfig-paths": "^3.9.0",
|
||||
"tslint": "6.1.3",
|
||||
"typedoc": "^0.20.16",
|
||||
"typedoc": "^0.20.14",
|
||||
"typescript": "3.9.7",
|
||||
"unist-util-select": "^3.0.2",
|
||||
"webpack-cli": "^3.3.12"
|
||||
|
Reference in New Issue
Block a user