Merge pull request #5338 from Alfresco/dev-eromano-ADF-4980

[ADF-4980] Fix app prefix
This commit is contained in:
mergify[bot] 2019-12-20 15:46:27 +00:00 committed by GitHub
commit 50f8e58314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 11 deletions

View File

@ -61,6 +61,11 @@ In order to achieve this, you will only need to set your app identifier under th
**Important note** **Important note**
This identifier must be unique to the app to guarantee that it has its own storage. This identifier must be unique to the app to guarantee that it has its own storage.
### SSO storagePrefix related scenario
The storagePrefix can allow you to login with multiple user in the same browser only if:
- Or You don't use the implicit flow
- Or You use implicit flow you use different AIMS instances for any app
## See also ## See also
- [Cookie service](cookie.service.md) - [Cookie service](cookie.service.md)

View File

@ -208,7 +208,7 @@ describe('Login component', () => {
await loginPage.clickSettingsIcon(); await loginPage.clickSettingsIcon();
await settingsPage.setProviderEcmBpm(); await settingsPage.setProviderEcmBpm();
await loginPage.login(adminUserModel.id, adminUserModel.password); await loginPage.login(adminUserModel.id, adminUserModel.password);
await browser.executeScript('window.localStorage.removeItem("ticket-ECM");'); await browser.executeScript('window.localStorage.removeItem("ADF_ticket-ECM");');
await BrowserActions.getUrl(browser.params.testConfig.adf.url + '/files'); await BrowserActions.getUrl(browser.params.testConfig.adf.url + '/files');
await loginPage.waitForElements(); await loginPage.waitForElements();
}); });
@ -228,7 +228,7 @@ describe('Login component', () => {
await loginPage.clickSettingsIcon(); await loginPage.clickSettingsIcon();
await settingsPage.setProviderEcmBpm(); await settingsPage.setProviderEcmBpm();
await loginPage.login(adminUserModel.id, adminUserModel.password); await loginPage.login(adminUserModel.id, adminUserModel.password);
await browser.executeScript('window.localStorage.removeItem("ticket-BPM");'); await browser.executeScript('window.localStorage.removeItem("ADF_ticket-BPM");');
await BrowserActions.getUrl(browser.params.testConfig.adf.url + '/activiti'); await BrowserActions.getUrl(browser.params.testConfig.adf.url + '/activiti');
await loginPage.waitForElements(); await loginPage.waitForElements();
}); });

View File

@ -134,6 +134,7 @@ export class AlfrescoApiService {
contextRoot: this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM), contextRoot: this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM),
disableCsrf: this.appConfig.get<boolean>(AppConfigValues.DISABLECSRF), disableCsrf: this.appConfig.get<boolean>(AppConfigValues.DISABLECSRF),
withCredentials: this.appConfig.get<boolean>(AppConfigValues.AUTH_WITH_CREDENTIALS, false), withCredentials: this.appConfig.get<boolean>(AppConfigValues.AUTH_WITH_CREDENTIALS, false),
domainPrefix : this.appConfig.get<string>(AppConfigValues.STORAGE_PREFIX),
oauth2: oauth oauth2: oauth
}); });

View File

@ -41,15 +41,15 @@ export class AuthGuard extends AuthGuardBase {
} }
ticketChange(event: StorageEvent) { ticketChange(event: StorageEvent) {
if (event.key === 'ticket-ECM' && event.newValue !== event.oldValue) { if (event.key.includes('ticket-ECM') && event.newValue !== event.oldValue) {
this.ticketChangeRedirect(event, 'ECM'); this.ticketChangeRedirect(event, 'ECM');
} }
if (event.key === 'ticket-BPM' && event.newValue !== event.oldValue) { if (event.key.includes('ticket-BPM') && event.newValue !== event.oldValue) {
this.ticketChangeRedirect(event, 'BPM'); this.ticketChangeRedirect(event, 'BPM');
} }
if (event.key === JwtHelperService.USER_ACCESS_TOKEN && if (event.key.includes(JwtHelperService.USER_ACCESS_TOKEN) &&
this.jwtHelperService.getValueFromToken(event.newValue, JwtHelperService.USER_PREFERRED_USERNAME) !== this.jwtHelperService.getValueFromToken(event.newValue, JwtHelperService.USER_PREFERRED_USERNAME) !==
this.jwtHelperService.getValueFromToken(event.oldValue, JwtHelperService.USER_PREFERRED_USERNAME)) { this.jwtHelperService.getValueFromToken(event.oldValue, JwtHelperService.USER_PREFERRED_USERNAME)) {
this.ticketChangeRedirect(event, 'ALL'); this.ticketChangeRedirect(event, 'ALL');

View File

@ -26,6 +26,7 @@ import { UserRepresentation } from '@alfresco/js-api';
import { map, catchError, tap } from 'rxjs/operators'; import { map, catchError, tap } from 'rxjs/operators';
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
import { JwtHelperService } from './jwt-helper.service'; import { JwtHelperService } from './jwt-helper.service';
import { StorageService } from './storage.service';
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME'; const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30; const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30;
@ -43,6 +44,7 @@ export class AuthenticationService {
constructor( constructor(
private appConfig: AppConfigService, private appConfig: AppConfigService,
private storageService: StorageService,
private alfrescoApi: AlfrescoApiService, private alfrescoApi: AlfrescoApiService,
private cookie: CookieService, private cookie: CookieService,
private logService: LogService) { private logService: LogService) {
@ -292,7 +294,7 @@ export class AuthenticationService {
* @returns Auth token string * @returns Auth token string
*/ */
getToken(): string { getToken(): string {
return localStorage.getItem(JwtHelperService.USER_ACCESS_TOKEN); return this.storageService.getItem(JwtHelperService.USER_ACCESS_TOKEN);
} }
/** /**

View File

@ -16,6 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { StorageService } from './storage.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -31,7 +32,7 @@ export class JwtHelperService {
static RESOURCE_ACCESS = 'resource_access'; static RESOURCE_ACCESS = 'resource_access';
static USER_PREFERRED_USERNAME = 'preferred_username'; static USER_PREFERRED_USERNAME = 'preferred_username';
constructor() { constructor(private storageService: StorageService) {
} }
/** /**
@ -89,12 +90,12 @@ export class JwtHelperService {
* @returns access token * @returns access token
*/ */
getAccessToken(): string { getAccessToken(): string {
return localStorage.getItem(JwtHelperService.USER_ACCESS_TOKEN); return this.storageService.getItem(JwtHelperService.USER_ACCESS_TOKEN);
} }
/** /**
* Gets a named value from the user access token. * Gets a named value from the user access token.
* @param key accessToken * @param accessToken your SSO access token where the value is encode
* @param key Key name of the field to retrieve * @param key Key name of the field to retrieve
* @returns Value from the token * @returns Value from the token
*/ */

View File

@ -27,8 +27,8 @@ describe('NoTaskDetailsTemplateDirective', () => {
let authService: AuthenticationService; let authService: AuthenticationService;
beforeEach(() => { beforeEach(() => {
authService = new AuthenticationService(null, null, null, null); authService = new AuthenticationService(null, null, null, null, null);
spyOn(authService, 'getBpmLoggedUser').and.returnValue(of({ email: 'fake-email'})); spyOn(authService, 'getBpmLoggedUser').and.returnValue(of({ email: 'fake-email' }));
detailsComponent = new TaskDetailsComponent(null, authService, null, null, null, null); detailsComponent = new TaskDetailsComponent(null, authService, null, null, null, null);
component = new NoTaskDetailsTemplateDirective(detailsComponent); component = new NoTaskDetailsTemplateDirective(detailsComponent);
}); });