[ADF-4665] [ADF] - Application is refreshed when you have two instances of application opened (#4849)

* refactoring getValueFromToken and fix user token refresh

* refactoring getValueFromToken and fix user token refresh

* refactoring getValueFromToken and fix user token refres

* fix unit test
This commit is contained in:
Eugenio Romano 2019-06-14 16:02:12 +01:00 committed by GitHub
parent 4733bc7d3b
commit f47cebc0a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 94 additions and 93 deletions

View File

@ -61,7 +61,7 @@ jobs:
- stage: Update children projects dependency #Update children projects dependency - stage: Update children projects dependency #Update children projects dependency
name: Update Related Project name: Update Related Project
if: tag =~ .*beta.* if: tag =~ .*beta.*
script: ./scripts/update-project.sh script: ./scripts/travis/update-children.sh
- stage: e2e Test - stage: e2e Test
name: core name: core
script: ./scripts/travis/e2e/core-e2e.sh script: ./scripts/travis/e2e/core-e2e.sh

View File

@ -39,7 +39,7 @@ Manages task filters.
- **getUsername**(): `string`<br/> - **getUsername**(): `string`<br/>
Gets the username field from the access token. Gets the username field from the access token.
- **Returns** `string` - Username string - **Returns** `string` - Username string
- **getValueFromToken**(key: `string`)<br/> - **getValueFromLocalAccessToken**(key: `string`)<br/>
Gets a named value from the access token. Gets a named value from the access token.
- _key:_ `string` - Key name of the value - _key:_ `string` - Key name of the value
- **updateFilter**(filter: [`TaskFilterCloudModel`](../../../lib/process-services-cloud/src/lib/task/task-filters/models/filter-cloud.model.ts))<br/> - **updateFilter**(filter: [`TaskFilterCloudModel`](../../../lib/process-services-cloud/src/lib/task/task-filters/models/filter-cloud.model.ts))<br/>

View File

@ -21,12 +21,10 @@ import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module'; import { CoreTestingModule } from '../testing/core.testing.module';
import { AuthGuardSsoRoleService } from './auth-guard-sso-role.service'; import { AuthGuardSsoRoleService } from './auth-guard-sso-role.service';
import { JwtHelperService } from './jwt-helper.service'; import { JwtHelperService } from './jwt-helper.service';
import { StorageService } from './storage.service';
describe('Auth Guard SSO role service', () => { describe('Auth Guard SSO role service', () => {
let authGuard: AuthGuardSsoRoleService; let authGuard: AuthGuardSsoRoleService;
let storageService: StorageService;
let jwtHelperService: JwtHelperService; let jwtHelperService: JwtHelperService;
let routerService: Router; let routerService: Router;
@ -36,14 +34,13 @@ describe('Auth Guard SSO role service', () => {
beforeEach(() => { beforeEach(() => {
localStorage.clear(); localStorage.clear();
storageService = TestBed.get(StorageService);
authGuard = TestBed.get(AuthGuardSsoRoleService); authGuard = TestBed.get(AuthGuardSsoRoleService);
jwtHelperService = TestBed.get(JwtHelperService); jwtHelperService = TestBed.get(JwtHelperService);
routerService = TestBed.get(Router); routerService = TestBed.get(Router);
}); });
it('Should canActivate be true if the Role is present int the JWT token', async(() => { it('Should canActivate be true if the Role is present int the JWT token', async(() => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1'] } }); spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1'] } });
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot(); const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
@ -53,7 +50,7 @@ describe('Auth Guard SSO role service', () => {
})); }));
it('Should canActivate be false if the Role is not present int the JWT token', async(() => { it('Should canActivate be false if the Role is not present int the JWT token', async(() => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role3'] } }); spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role3'] } });
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot(); const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
@ -63,7 +60,7 @@ describe('Auth Guard SSO role service', () => {
})); }));
it('Should not redirect if canActivate is', async(() => { it('Should not redirect if canActivate is', async(() => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1'] } }); spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1'] } });
spyOn(routerService, 'navigate').and.stub(); spyOn(routerService, 'navigate').and.stub();
@ -75,7 +72,7 @@ describe('Auth Guard SSO role service', () => {
})); }));
it('Should canActivate return false if the data Role to check is empty', async(() => { it('Should canActivate return false if the data Role to check is empty', async(() => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1', 'role3'] } }); spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1', 'role3'] } });
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot(); const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
@ -84,7 +81,7 @@ describe('Auth Guard SSO role service', () => {
})); }));
it('Should canActivate return false if the realm_access is not present', async(() => { it('Should canActivate return false if the realm_access is not present', async(() => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({}); spyOn(jwtHelperService, 'decodeToken').and.returnValue({});
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot(); const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
@ -93,7 +90,7 @@ describe('Auth Guard SSO role service', () => {
})); }));
it('Should redirect to the redirectURL if canActivate is false and redirectUrl is in data', async(() => { it('Should redirect to the redirectURL if canActivate is false and redirectUrl is in data', async(() => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({}); spyOn(jwtHelperService, 'decodeToken').and.returnValue({});
spyOn(routerService, 'navigate').and.stub(); spyOn(routerService, 'navigate').and.stub();
@ -105,7 +102,7 @@ describe('Auth Guard SSO role service', () => {
})); }));
it('Should not redirect if canActivate is false and redirectUrl is not in data', async(() => { it('Should not redirect if canActivate is false and redirectUrl is not in data', async(() => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({}); spyOn(jwtHelperService, 'decodeToken').and.returnValue({});
spyOn(routerService, 'navigate').and.stub(); spyOn(routerService, 'navigate').and.stub();
@ -140,7 +137,7 @@ describe('Auth Guard SSO role service', () => {
it('Should canActivate be true if both Real Role and Client Role are present int the JWT token', () => { it('Should canActivate be true if both Real Role and Client Role are present int the JWT token', () => {
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot(); const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ spyOn(jwtHelperService, 'decodeToken').and.returnValue({
'realm_access': { roles: ['role1'] }, 'realm_access': { roles: ['role1'] },
@ -155,7 +152,7 @@ describe('Auth Guard SSO role service', () => {
it('Should canActivate be false if the Client Role is not present int the JWT token with the correct role', () => { it('Should canActivate be false if the Client Role is not present int the JWT token with the correct role', () => {
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot(); const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ spyOn(jwtHelperService, 'decodeToken').and.returnValue({
'realm_access': { roles: ['role1'] }, 'realm_access': { roles: ['role1'] },
@ -171,7 +168,7 @@ describe('Auth Guard SSO role service', () => {
describe('ClientRole ', () => { describe('ClientRole ', () => {
it('Should be true if the resource_access contains the single role', () => { it('Should be true if the resource_access contains the single role', () => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue( spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{ {
@ -183,7 +180,7 @@ describe('Auth Guard SSO role service', () => {
}); });
it('Should be true if the resource_access contains at least one of the roles', () => { it('Should be true if the resource_access contains at least one of the roles', () => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue( spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{ {
@ -195,7 +192,7 @@ describe('Auth Guard SSO role service', () => {
}); });
it('Should be false if the resource_access does not contain the role', () => { it('Should be false if the resource_access does not contain the role', () => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue( spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{ {
'resource_access': { fakeapp: { roles: ['role3'] } } 'resource_access': { fakeapp: { roles: ['role3'] } }
@ -205,7 +202,7 @@ describe('Auth Guard SSO role service', () => {
}); });
it('Should be false if the resource_access does not contain the client role related to the app', () => { it('Should be false if the resource_access does not contain the client role related to the app', () => {
spyOn(storageService, 'getItem').and.returnValue('my-access_token'); spyOn(localStorage, 'getItem').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue( spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{ {
'resource_access': { anotherfakeapp: { roles: ['role1'] } } 'resource_access': { anotherfakeapp: { roles: ['role1'] } }

View File

@ -56,19 +56,19 @@ export class AuthGuardSsoRoleService implements CanActivate {
} }
getRealmRoles(): string[] { getRealmRoles(): string[] {
const access = this.getValueFromToken<any>('realm_access'); const access = this.jwtHelperService.getValueFromLocalAccessToken<any>('realm_access');
const roles = access ? access['roles'] : []; const roles = access ? access['roles'] : [];
return roles; return roles;
} }
getClientRoles(client: string): string[] { getClientRoles(client: string): string[] {
const clientRole = this.getValueFromToken<any>('resource_access')[client]; const clientRole = this.jwtHelperService.getValueFromLocalAccessToken<any>('resource_access')[client];
const roles = clientRole ? clientRole['roles'] : []; const roles = clientRole ? clientRole['roles'] : [];
return roles; return roles;
} }
getAccessToken(): string { getAccessToken(): string {
return this.storageService.getItem('access_token'); return this.storageService.getItem(JwtHelperService.USER_ACCESS_TOKEN);
} }
hasRealmRole(role: string): boolean { hasRealmRole(role: string): boolean {
@ -104,14 +104,4 @@ export class AuthGuardSsoRoleService implements CanActivate {
} }
return hasRole; return hasRole;
} }
getValueFromToken<T>(key: string): T {
let value;
const accessToken = this.getAccessToken();
if (accessToken) {
const tokenPayload = this.jwtHelperService.decodeToken(accessToken);
value = tokenPayload[key];
}
return <T> value;
}
} }

View File

@ -21,6 +21,7 @@ import { AuthenticationService } from './authentication.service';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { AppConfigService } from '../app-config/app-config.service'; import { AppConfigService } from '../app-config/app-config.service';
import { AuthGuardBase } from './auth-guard-base'; import { AuthGuardBase } from './auth-guard-base';
import { JwtHelperService } from './jwt-helper.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -29,7 +30,8 @@ export class AuthGuard extends AuthGuardBase {
ticketChangeBind: any; ticketChangeBind: any;
constructor(authenticationService: AuthenticationService, constructor(private jwtHelperService: JwtHelperService,
authenticationService: AuthenticationService,
router: Router, router: Router,
appConfigService: AppConfigService) { appConfigService: AppConfigService) {
super(authenticationService, router, appConfigService); super(authenticationService, router, appConfigService);
@ -47,7 +49,9 @@ export class AuthGuard extends AuthGuardBase {
this.ticketChangeRedirect(event, 'BPM'); this.ticketChangeRedirect(event, 'BPM');
} }
if (event.key === 'id_token' && event.newValue !== event.oldValue) { if (event.key === 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, 'ALL');
} }
} }

View File

@ -25,6 +25,7 @@ import { AppConfigService, AppConfigValues } from '../app-config/app-config.serv
import { UserRepresentation } from '@alfresco/js-api'; 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';
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;
@ -290,7 +291,7 @@ export class AuthenticationService {
* @returns Auth token string * @returns Auth token string
*/ */
getToken(): string { getToken(): string {
return localStorage.getItem('access_token'); return localStorage.getItem(JwtHelperService.USER_ACCESS_TOKEN);
} }
/** /**

View File

@ -22,7 +22,15 @@ import { Injectable } from '@angular/core';
}) })
export class JwtHelperService { export class JwtHelperService {
constructor() {} static USER_NAME = 'name';
static FAMILY_NAME = 'family_name';
static GIVEN_NAME = 'given_name';
static USER_EMAIL = 'email';
static USER_ACCESS_TOKEN = 'access_token';
static USER_PREFERRED_USERNAME = 'preferred_username';
constructor() {
}
/** /**
* Decodes a JSON web token into a JS object. * Decodes a JSON web token into a JS object.
@ -64,4 +72,29 @@ export class JwtHelperService {
} }
return decodeURIComponent(escape(window.atob(output))); return decodeURIComponent(escape(window.atob(output)));
} }
/**
* Gets a named value from the user access token.
* @param key Key name of the field to retrieve
* @returns Value from the token
*/
getValueFromLocalAccessToken<T>(key: string): T {
const accessToken = localStorage.getItem(JwtHelperService.USER_ACCESS_TOKEN);
return this.getValueFromToken(accessToken, key);
}
/**
* Gets a named value from the user access token.
* @param key accessToken
* @param key Key name of the field to retrieve
* @returns Value from the token
*/
getValueFromToken<T>(accessToken: string, key: string): T {
let value;
if (accessToken) {
const tokenPayload = this.decodeToken(accessToken);
value = tokenPayload[key];
}
return <T> value;
}
} }

View File

@ -30,16 +30,9 @@ import { IdentityRoleModel } from '../models/identity-role.model';
}) })
export class IdentityUserService { export class IdentityUserService {
static USER_NAME = 'name';
static FAMILY_NAME = 'family_name';
static GIVEN_NAME = 'given_name';
static USER_EMAIL = 'email';
static USER_ACCESS_TOKEN = 'access_token';
static USER_PREFERRED_USERNAME = 'preferred_username';
constructor( constructor(
private helper: JwtHelperService, private jwtHelperService: JwtHelperService,
private apiService: AlfrescoApiService, private alfrescoApiService: AlfrescoApiService,
private appConfigService: AppConfigService) { } private appConfigService: AppConfigService) { }
/** /**
@ -47,29 +40,14 @@ export class IdentityUserService {
* @returns The user's details * @returns The user's details
*/ */
getCurrentUserInfo(): IdentityUserModel { getCurrentUserInfo(): IdentityUserModel {
const familyName = this.getValueFromToken<string>(IdentityUserService.FAMILY_NAME); const familyName = this.jwtHelperService.getValueFromLocalAccessToken<string>(JwtHelperService.FAMILY_NAME);
const givenName = this.getValueFromToken<string>(IdentityUserService.GIVEN_NAME); const givenName = this.jwtHelperService.getValueFromLocalAccessToken<string>(JwtHelperService.GIVEN_NAME);
const email = this.getValueFromToken<string>(IdentityUserService.USER_EMAIL); const email = this.jwtHelperService.getValueFromLocalAccessToken<string>(JwtHelperService.USER_EMAIL);
const username = this.getValueFromToken<string>(IdentityUserService.USER_PREFERRED_USERNAME); const username = this.jwtHelperService.getValueFromLocalAccessToken<string>(JwtHelperService.USER_PREFERRED_USERNAME);
const user = { firstName: givenName, lastName: familyName, email: email, username: username }; const user = { firstName: givenName, lastName: familyName, email: email, username: username };
return new IdentityUserModel(user); return new IdentityUserModel(user);
} }
/**
* Gets a named value from the user access token.
* @param key Key name of the field to retrieve
* @returns Value from the token
*/
getValueFromToken<T>(key: string): T {
let value;
const token = localStorage.getItem(IdentityUserService.USER_ACCESS_TOKEN);
if (token) {
const tokenPayload = this.helper.decodeToken(token);
value = tokenPayload[key];
}
return <T> value;
}
/** /**
* Find users based on search input. * Find users based on search input.
* @param search Search query string * @param search Search query string
@ -83,7 +61,7 @@ export class IdentityUserService {
const httpMethod = 'GET', pathParams = {}, queryParams = { search: search }, bodyParam = {}, headerParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = { search: search }, bodyParam = {}, headerParams = {},
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
return (from(this.apiService.getInstance().oauth2Auth.callCustomApi( return (from(this.alfrescoApiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams, url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam, headerParams, formParams, bodyParam,
contentTypes, accepts, Object, null, null) contentTypes, accepts, Object, null, null)
@ -103,7 +81,7 @@ export class IdentityUserService {
const httpMethod = 'GET', pathParams = {}, queryParams = { username: username }, bodyParam = {}, headerParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = { username: username }, bodyParam = {}, headerParams = {},
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
return (from(this.apiService.getInstance().oauth2Auth.callCustomApi( return (from(this.alfrescoApiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams, url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam, headerParams, formParams, bodyParam,
contentTypes, accepts, Object, null, null) contentTypes, accepts, Object, null, null)
@ -123,7 +101,7 @@ export class IdentityUserService {
const httpMethod = 'GET', pathParams = {}, queryParams = { email: email }, bodyParam = {}, headerParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = { email: email }, bodyParam = {}, headerParams = {},
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
return (from(this.apiService.getInstance().oauth2Auth.callCustomApi( return (from(this.alfrescoApiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams, url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam, headerParams, formParams, bodyParam,
contentTypes, accepts, Object, null, null) contentTypes, accepts, Object, null, null)
@ -143,7 +121,7 @@ export class IdentityUserService {
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
return (from(this.apiService.getInstance().oauth2Auth.callCustomApi( return (from(this.alfrescoApiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams, url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam, headerParams, formParams, bodyParam,
contentTypes, accepts, Object, null, null) contentTypes, accepts, Object, null, null)
@ -161,7 +139,7 @@ export class IdentityUserService {
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
return from(this.apiService.getInstance().oauth2Auth.callCustomApi( return from(this.alfrescoApiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams, url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam, headerParams, formParams, bodyParam,
contentTypes, accepts, Object, null, null) contentTypes, accepts, Object, null, null)
@ -222,7 +200,7 @@ export class IdentityUserService {
const url = this.buildGetClientsUrl(); const url = this.buildGetClientsUrl();
const httpMethod = 'GET', pathParams = {}, queryParams = { clientId: applicationName }, bodyParam = {}, headerParams = {}, formParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = { clientId: applicationName }, bodyParam = {}, headerParams = {}, formParams = {},
contentTypes = ['application/json'], accepts = ['application/json']; contentTypes = ['application/json'], accepts = ['application/json'];
return from(this.apiService.getInstance() return from(this.alfrescoApiService.getInstance()
.oauth2Auth.callCustomApi(url, httpMethod, pathParams, queryParams, headerParams, .oauth2Auth.callCustomApi(url, httpMethod, pathParams, queryParams, headerParams,
formParams, bodyParam, contentTypes, formParams, bodyParam, contentTypes,
accepts, Object, null, null) accepts, Object, null, null)
@ -272,7 +250,7 @@ export class IdentityUserService {
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
formParams = {}, authNames = [], contentTypes = ['application/json'], accepts = ['application/json']; formParams = {}, authNames = [], contentTypes = ['application/json'], accepts = ['application/json'];
return from(this.apiService.getInstance().oauth2Auth.callCustomApi( return from(this.alfrescoApiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams, url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam, authNames, headerParams, formParams, bodyParam, authNames,
contentTypes, accepts, null, null) contentTypes, accepts, null, null)
@ -293,7 +271,7 @@ export class IdentityUserService {
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {}, const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
return from(this.apiService.getInstance().oauth2Auth.callCustomApi( return from(this.alfrescoApiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams, url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam, headerParams, formParams, bodyParam,
contentTypes, accepts, Object, null, null) contentTypes, accepts, Object, null, null)

View File

@ -19,13 +19,14 @@ import { StorageService, JwtHelperService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs'; import { Observable, BehaviorSubject } from 'rxjs';
import { TaskFilterCloudModel } from '../models/filter-cloud.model'; import { TaskFilterCloudModel } from '../models/filter-cloud.model';
@Injectable() @Injectable()
export class TaskFilterCloudService { export class TaskFilterCloudService {
private filtersSubject: BehaviorSubject<TaskFilterCloudModel[]>; private filtersSubject: BehaviorSubject<TaskFilterCloudModel[]>;
filters$: Observable<TaskFilterCloudModel[]>; filters$: Observable<TaskFilterCloudModel[]>;
constructor(private storage: StorageService, private jwtService: JwtHelperService) { constructor(private storage: StorageService, private jwtHelperService: JwtHelperService) {
this.filtersSubject = new BehaviorSubject([]); this.filtersSubject = new BehaviorSubject([]);
this.filters$ = this.filtersSubject.asObservable(); this.filters$ = this.filtersSubject.asObservable();
} }
@ -135,22 +136,7 @@ export class TaskFilterCloudService {
* @returns Username string * @returns Username string
*/ */
getUsername(): string { getUsername(): string {
return this.getValueFromToken<string>('preferred_username'); return this.jwtHelperService.getValueFromLocalAccessToken<string>(JwtHelperService.USER_PREFERRED_USERNAME);
}
/**
* Gets a named value from the access token.
* @param key Key name of the value
* @returns The value data
*/
getValueFromToken<T>(key: string): T {
let value;
const token = localStorage.getItem('access_token');
if (token) {
const tokenPayload = this.jwtService.decodeToken(token);
value = tokenPayload[key];
}
return <T> value;
} }
/** /**

22
package-lock.json generated
View File

@ -6504,7 +6504,8 @@
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
}, },
"fsevents": { "fsevents": {
"version": "1.2.7", "version": "1.2.7",
@ -7202,6 +7203,7 @@
"version": "7.1.3", "version": "7.1.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
"dev": true,
"requires": { "requires": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
"inflight": "^1.0.4", "inflight": "^1.0.4",
@ -8240,6 +8242,7 @@
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": { "requires": {
"once": "^1.3.0", "once": "^1.3.0",
"wrappy": "1" "wrappy": "1"
@ -8348,7 +8351,8 @@
"interpret": { "interpret": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz", "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz",
"integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==" "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==",
"dev": true
}, },
"invariant": { "invariant": {
"version": "2.2.4", "version": "2.2.4",
@ -10851,6 +10855,7 @@
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -11986,6 +11991,7 @@
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -12466,7 +12472,8 @@
"path-is-absolute": { "path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
}, },
"path-is-inside": { "path-is-inside": {
"version": "1.0.2", "version": "1.0.2",
@ -12483,7 +12490,8 @@
"path-parse": { "path-parse": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"dev": true
}, },
"path-to-regexp": { "path-to-regexp": {
"version": "0.1.7", "version": "0.1.7",
@ -13742,6 +13750,7 @@
"version": "0.6.2", "version": "0.6.2",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
"integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
"dev": true,
"requires": { "requires": {
"resolve": "^1.1.6" "resolve": "^1.1.6"
} }
@ -14060,6 +14069,7 @@
"version": "1.10.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz",
"integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==",
"dev": true,
"requires": { "requires": {
"path-parse": "^1.0.6" "path-parse": "^1.0.6"
} }
@ -14891,6 +14901,7 @@
"version": "0.8.3", "version": "0.8.3",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz",
"integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==", "integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==",
"dev": true,
"requires": { "requires": {
"glob": "^7.0.0", "glob": "^7.0.0",
"interpret": "^1.0.0", "interpret": "^1.0.0",
@ -18593,7 +18604,8 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
}, },
"write": { "write": {
"version": "1.0.3", "version": "1.0.3",