This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create endpoint for user storage provider (#138)
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_synchronizationresult | ||
*/ | ||
|
||
export default interface SynchronizationResultRepresentation { | ||
ignored?: boolean; | ||
added?: number; | ||
updated?: number; | ||
removed?: number; | ||
failed?: number; | ||
status?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {KeycloakAdminClient} from '../client'; | ||
import SynchronizationResultRepresentation from '../defs/synchronizationResultRepresentation'; | ||
import Resource from './resource'; | ||
|
||
type ActionType = 'triggerFullSync' | 'triggerChangedUsersSync'; | ||
type DirectionType = 'fedToKeycloak' | 'keycloakToFed'; | ||
type NameResponse = { | ||
id: string; | ||
name: string; | ||
}; | ||
|
||
export class UserStorageProvider extends Resource<{realm?: string}> { | ||
public name = this.makeRequest<{id: string}, NameResponse>({ | ||
method: 'GET', | ||
path: '/{id}/name', | ||
urlParamKeys: ['id'], | ||
}); | ||
|
||
public removeImportedUsers = this.makeRequest<{id: string}, void>({ | ||
method: 'POST', | ||
path: '/{id}/remove-imported-users', | ||
urlParamKeys: ['id'], | ||
}); | ||
|
||
public sync = this.makeRequest< | ||
{id: string; action?: ActionType}, | ||
SynchronizationResultRepresentation | ||
>({ | ||
method: 'POST', | ||
path: '/{id}/sync', | ||
urlParamKeys: ['id'], | ||
queryParamKeys: ['action'], | ||
}); | ||
|
||
public unlinkUsers = this.makeRequest<{id: string}, void>({ | ||
method: 'POST', | ||
path: '/{id}/unlink-users', | ||
urlParamKeys: ['id'], | ||
}); | ||
|
||
public mappersSync = this.makeRequest< | ||
{id: string; parentId: string; direction?: DirectionType}, | ||
SynchronizationResultRepresentation | ||
>({ | ||
method: 'POST', | ||
path: '/{parentId}/mappers/{id}/sync', | ||
urlParamKeys: ['id', 'parentId'], | ||
queryParamKeys: ['direction'], | ||
}); | ||
|
||
constructor(client: KeycloakAdminClient) { | ||
super(client, { | ||
path: '/admin/realms/{realm}/user-storage', | ||
getUrlParams: () => ({ | ||
realm: client.realmName, | ||
}), | ||
getBaseUrl: () => client.baseUrl, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// tslint:disable:no-unused-expression | ||
import * as chai from 'chai'; | ||
import {KeycloakAdminClient} from '../src/client'; | ||
import {credentials} from './constants'; | ||
import faker from 'faker'; | ||
|
||
import ComponentRepresentation from '../src/defs/componentRepresentation'; | ||
|
||
const expect = chai.expect; | ||
|
||
describe('Users federation provider', () => { | ||
let kcAdminClient: KeycloakAdminClient; | ||
let currentUserFed: ComponentRepresentation; | ||
|
||
before(async () => { | ||
kcAdminClient = new KeycloakAdminClient(); | ||
await kcAdminClient.auth(credentials); | ||
|
||
const name = faker.internet.userName(); | ||
currentUserFed = await kcAdminClient.components.create({ | ||
name, | ||
parentId: 'master', | ||
providerId: 'ldap', | ||
providerType: 'org.keycloak.storage.UserStorageProvider', | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await kcAdminClient.components.del({ | ||
id: currentUserFed.id, | ||
}); | ||
}); | ||
|
||
it('list storage provider', async () => { | ||
const name = await kcAdminClient.userStorageProvider.name({ | ||
id: currentUserFed.id, | ||
}); | ||
expect(name).to.be.ok; | ||
}); | ||
|
||
it('remove imported users', async () => { | ||
await kcAdminClient.userStorageProvider.removeImportedUsers({ | ||
id: currentUserFed.id, | ||
}); | ||
}); | ||
|
||
it('unlink users', async () => { | ||
await kcAdminClient.userStorageProvider.unlinkUsers({ | ||
id: currentUserFed.id, | ||
}); | ||
}); | ||
}); |