From cb5453c7cb15f58da6e93f569ca49588c66141c2 Mon Sep 17 00:00:00 2001 From: DPDS93CT Date: Mon, 16 Oct 2023 11:58:07 +0200 Subject: [PATCH] adjust realm names: realm and client-id for admin renamed --- config/config.dev.json | 8 ++++---- config/config.test.json | 8 ++++---- src/frontend/frontend.module.ts | 6 +++--- src/health/health.controller.spec.ts | 10 +++++----- .../domain/keycloak-admin-client.service.ts | 6 +++--- src/modules/ui-backend/domain/login.service.ts | 4 ++-- .../ui-backend/domain/new-login.service.ts | 4 ++-- src/shared/config/config.loader.spec.ts | 16 ++++++++-------- src/shared/config/keycloak.config.ts | 10 +++++----- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/config/config.dev.json b/config/config.dev.json index 66b113396..936a4f4fb 100644 --- a/config/config.dev.json +++ b/config/config.dev.json @@ -11,9 +11,9 @@ }, "KEYCLOAK": { "BASE_URL": "http://127.0.0.1:8080", - "REALM_NAME": "master", - "CLIENT_ID": "admin-cli", - "SCHULPORTAL_REALM_NAME": "schulportal", - "SCHULPORTAL_CLIENT_ID": "schulportal" + "ADMIN_REALM_NAME": "master", + "ADMIN_CLIENT_ID": "admin-cli", + "REALM_NAME": "schulportal", + "CLIENT_ID": "schulportal" } } diff --git a/config/config.test.json b/config/config.test.json index 9515936ae..8f2fb1186 100644 --- a/config/config.test.json +++ b/config/config.test.json @@ -11,9 +11,9 @@ }, "KEYCLOAK": { "BASE_URL": "http://127.0.0.1:8080", - "REALM_NAME": "master", - "CLIENT_ID": "admin-cli", - "SCHULPORTAL_REALM_NAME": "schulportal", - "SCHULPORTAL_CLIENT_ID": "schulportal" + "ADMIN_REALM_NAME": "master", + "ADMIN_CLIENT_ID": "admin-cli", + "REALM_NAME": "schulportal", + "CLIENT_ID": "schulportal" } } diff --git a/src/frontend/frontend.module.ts b/src/frontend/frontend.module.ts index 21692031c..f631b6aac 100644 --- a/src/frontend/frontend.module.ts +++ b/src/frontend/frontend.module.ts @@ -42,9 +42,9 @@ import { mappingErrorHandler } from '../shared/error/mapping.error.js'; return { authServerUrl: keycloakConfig.BASE_URL, - realm: keycloakConfig.REALM_NAME, - clientId: keycloakConfig.CLIENT_ID, - secret: keycloakConfig.SECRET, + realm: keycloakConfig.ADMIN_REALM_NAME, + clientId: keycloakConfig.ADMIN_CLIENT_ID, + secret: keycloakConfig.ADMIN_SECRET, }; }, inject: [ConfigService], diff --git a/src/health/health.controller.spec.ts b/src/health/health.controller.spec.ts index 9b304d75a..123c04e46 100644 --- a/src/health/health.controller.spec.ts +++ b/src/health/health.controller.spec.ts @@ -20,12 +20,12 @@ describe('HealthController', () => { let entityManager: SqlEntityManager; let httpHealthIndicator: DeepMocked; const keycloakConfig: KeycloakConfig = { - CLIENT_ID: '', - SECRET: '', - REALM_NAME: '', + ADMIN_CLIENT_ID: '', + ADMIN_SECRET: '', + ADMIN_REALM_NAME: '', BASE_URL: 'http://keycloak.test', - SCHULPORTAL_REALM_NAME: '', - SCHULPORTAL_CLIENT_ID: '', + REALM_NAME: '', + CLIENT_ID: '', }; let configService: DeepMocked; diff --git a/src/modules/keycloak-administration/domain/keycloak-admin-client.service.ts b/src/modules/keycloak-administration/domain/keycloak-admin-client.service.ts index 8a4a6b217..17311ede4 100644 --- a/src/modules/keycloak-administration/domain/keycloak-admin-client.service.ts +++ b/src/modules/keycloak-administration/domain/keycloak-admin-client.service.ts @@ -18,7 +18,7 @@ export class KeycloakAdministrationService { this.kcAdminClient.setConfig({ baseUrl: this.kcConfig.BASE_URL, - realmName: this.kcConfig.REALM_NAME, + realmName: this.kcConfig.ADMIN_REALM_NAME, }); } @@ -45,8 +45,8 @@ export class KeycloakAdministrationService { try { const credentials: Credentials = { grantType: 'client_credentials', - clientId: this.kcConfig.CLIENT_ID, - clientSecret: this.kcConfig.SECRET, + clientId: this.kcConfig.ADMIN_CLIENT_ID, + clientSecret: this.kcConfig.ADMIN_SECRET, }; await this.kcAdminClient.auth(credentials); diff --git a/src/modules/ui-backend/domain/login.service.ts b/src/modules/ui-backend/domain/login.service.ts index 085880e76..d71a58302 100644 --- a/src/modules/ui-backend/domain/login.service.ts +++ b/src/modules/ui-backend/domain/login.service.ts @@ -17,10 +17,10 @@ export class LoginService { public async getTokenForUser(username: string, password: string): Promise { try { const keycloakIssuer: Issuer = await Issuer.discover( - this.kcConfig.BASE_URL + '/realms/' + this.kcConfig.SCHULPORTAL_REALM_NAME, + this.kcConfig.BASE_URL + '/realms/' + this.kcConfig.REALM_NAME, ); const client: Client = new keycloakIssuer.Client({ - client_id: this.kcConfig.SCHULPORTAL_CLIENT_ID, + client_id: this.kcConfig.CLIENT_ID, token_endpoint_auth_method: 'none', }); return await client.grant({ diff --git a/src/modules/ui-backend/domain/new-login.service.ts b/src/modules/ui-backend/domain/new-login.service.ts index c630d3fb2..f2c5ec4af 100644 --- a/src/modules/ui-backend/domain/new-login.service.ts +++ b/src/modules/ui-backend/domain/new-login.service.ts @@ -12,7 +12,7 @@ export class NewLoginService { this.kcConfig = this.config.getOrThrow('KEYCLOAK'); this.kcAdminClient.setConfig({ baseUrl: this.kcConfig.BASE_URL, - realmName: this.kcConfig.SCHULPORTAL_REALM_NAME, + realmName: this.kcConfig.REALM_NAME, }); } @@ -20,7 +20,7 @@ export class NewLoginService { try { const credentials: Credentials = { grantType: 'password', - clientId: this.kcConfig.SCHULPORTAL_CLIENT_ID, + clientId: this.kcConfig.CLIENT_ID, username: username, password: password, }; diff --git a/src/shared/config/config.loader.spec.ts b/src/shared/config/config.loader.spec.ts index 41fec39ba..7388d5589 100644 --- a/src/shared/config/config.loader.spec.ts +++ b/src/shared/config/config.loader.spec.ts @@ -38,16 +38,16 @@ describe('configloader', () => { }, KEYCLOAK: { BASE_URL: 'localhost:8080', - CLIENT_ID: 'admin-cli', - REALM_NAME: 'master', - SCHULPORTAL_REALM_NAME: 'schulportal', - SCHULPORTAL_CLIENT_ID: 'schulportal', + ADMIN_CLIENT_ID: 'admin-cli', + ADMIN_REALM_NAME: 'master', + REALM_NAME: 'schulportal', + CLIENT_ID: 'schulportal', }, }; const secrets: DeepPartial = { DB: { SECRET: 'SuperSecretSecret' }, - KEYCLOAK: { SECRET: 'ClientSecret' }, + KEYCLOAK: { ADMIN_SECRET: 'ClientSecret' }, }; beforeAll(() => { @@ -82,10 +82,10 @@ describe('configloader', () => { }, KEYCLOAK: { BASE_URL: '', - CLIENT_ID: '', + ADMIN_CLIENT_ID: '', + ADMIN_REALM_NAME: '', REALM_NAME: '', - SCHULPORTAL_REALM_NAME: '', - SCHULPORTAL_CLIENT_ID: '', + CLIENT_ID: '', }, }; diff --git a/src/shared/config/keycloak.config.ts b/src/shared/config/keycloak.config.ts index 7422977da..07911a5ce 100644 --- a/src/shared/config/keycloak.config.ts +++ b/src/shared/config/keycloak.config.ts @@ -7,21 +7,21 @@ export class KeycloakConfig { @IsString() @IsNotEmpty() - public readonly REALM_NAME!: string; + public readonly ADMIN_REALM_NAME!: string; @IsString() @IsNotEmpty() - public readonly CLIENT_ID!: string; + public readonly ADMIN_CLIENT_ID!: string; @IsString() @IsNotEmpty() - public readonly SECRET!: string; + public readonly ADMIN_SECRET!: string; @IsString() @IsNotEmpty() - public readonly SCHULPORTAL_REALM_NAME!: string; + public readonly REALM_NAME!: string; @IsString() @IsNotEmpty() - public readonly SCHULPORTAL_CLIENT_ID!: string; + public readonly CLIENT_ID!: string; }