From d0d0af17b9d56ad06874ec513f0baac9001d7a59 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 3 Jan 2022 10:49:45 +0100 Subject: [PATCH] added support for associated policies also fixed type of find permissions --- src/resources/clients.ts | 25 ++++++++++++++++++++----- test/clients.spec.ts | 19 ++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/resources/clients.ts b/src/resources/clients.ts index 17e5650e..2cae0119 100644 --- a/src/resources/clients.ts +++ b/src/resources/clients.ts @@ -17,15 +17,18 @@ import KeyStoreConfig from '../defs/keystoreConfig'; import ResourceServerRepresentation from '../defs/resourceServerRepresentation'; import ScopeRepresentation from '../defs/scopeRepresentation'; -export interface ClientQuery { +export interface PaginatedQuery { first?: number; max?: number; +} + +export interface ClientQuery extends PaginatedQuery { clientId?: string; viewableOnly?: boolean; search?: boolean; } -export interface PolicyQuery { +export interface PolicyQuery extends PaginatedQuery { id?: string; name?: string; type?: string; @@ -34,8 +37,6 @@ export interface PolicyQuery { permission?: string; owner?: string; fields?: string; - first?: number; - max?: number; } export class Clients extends Resource<{realm?: string}> { @@ -729,7 +730,12 @@ export class Clients extends Resource<{realm?: string}> { * Permissions */ public findPermissions = this.makeRequest< - {id: string; name: string}, + { + id: string; + name?: string; + resource?: string; + scope?: string; + } & PaginatedQuery, PolicyRepresentation[] >({ method: 'GET', @@ -793,6 +799,15 @@ export class Clients extends Resource<{realm?: string}> { urlParamKeys: ['id', 'permissionId'], }); + public getAssociatedPolicies = this.makeRequest< + {id: string; permissionId: string}, + PolicyRepresentation[] + >({ + method: 'GET', + path: '/{id}/authz/resource-server/policy/{permissionId}/associatedPolicies', + urlParamKeys: ['id', 'permissionId'], + }); + public getOfflineSessionCount = this.makeRequest< {id: string}, {count: number} diff --git a/test/clients.spec.ts b/test/clients.spec.ts index fe5c7071..1e42610b 100644 --- a/test/clients.spec.ts +++ b/test/clients.spec.ts @@ -1218,7 +1218,14 @@ describe('Clients', () => { scopes: scopes.map((scope) => scope.id!), }, ); - expect(permission).to.be.ok; + + const p = await kcAdminClient.clients.findPermissions({ + id: currentClient.id!, + name: permissionConfig.name, + }); + + expect(p.length).to.be.eq(1); + expect(p[0].logic).to.be.eq(permissionConfig.logic); }); it('get associated scopes for permission', async () => { @@ -1231,6 +1238,16 @@ describe('Clients', () => { ); }); + it('get associated policies for permission', async () => { + const result = await kcAdminClient.clients.getAssociatedPolicies({ + id: currentClient.id!, + permissionId: permission.id!, + }); + + expect(result.length).to.be.eq(1); + expect(result[0].id).to.be.eq(policy.id); + }); + it('get associated resources for permission', async () => { const result = await kcAdminClient.clients.getAssociatedResources({ id: currentClient.id!,