Skip to content

BC-11531 Switch to service account auth fow.#6355

Open
CeEv wants to merge 9 commits into
mainfrom
BC-11531-support-jwt
Open

BC-11531 Switch to service account auth fow.#6355
CeEv wants to merge 9 commits into
mainfrom
BC-11531-support-jwt

Conversation

@CeEv

@CeEv CeEv commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

Links to Tickets or other pull requests

Changes

Approval for review

  • DEV: If api was changed - generate-client:server was executed in vue frontend and changes were tested and put in a PR with the same branch name.
  • QA: In addition to review, the code has been manually tested (if manual testing is possible)
  • All points were discussed with the ticket creator, support-team or product owner. The code upholds all quality guidelines from the PR-template.

@CeEv CeEv self-assigned this Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the dedicated SHD API module/endpoints and relocates “create support JWT” functionality into the Authentication/Login API flow, adding the necessary DTOs and updating unit + API tests accordingly. It also adjusts the authorization rules to allow authorization checks against User entities (not only UserDo).

Changes:

  • Removed the entire shd module API (module/controller/UC/DTOs/mappers + API tests) and unregistered it from the server app module.
  • Added POST /login/support-jwt to LoginController, backed by LoginUc.getSupportLoginData(...), plus unit and API tests.
  • Updated UserRule to support both User and UserDo as authorizable objects.

Reviewed changes

Copilot reviewed 16 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/server/src/modules/shd/shd.api.module.ts Removed SHD API module registration (deleted).
apps/server/src/modules/shd/index.ts SHD module barrel removed (deleted).
apps/server/src/modules/shd/api/shd.uc.ts Removed SHD use-case for support JWT generation (deleted).
apps/server/src/modules/shd/api/shd.controller.ts Removed SHD controller endpoint (deleted).
apps/server/src/modules/shd/api/mapper/login-response.mapper.ts Removed SHD login response mapper (deleted).
apps/server/src/modules/shd/api/mapper/index.ts Removed SHD mapper barrel (deleted).
apps/server/src/modules/shd/api/index.ts Removed SHD API barrel exports (deleted).
apps/server/src/modules/shd/api/dto/login.response.ts Removed SHD login response DTO (deleted).
apps/server/src/modules/shd/api/dto/index.ts Removed SHD DTO barrel exports (deleted).
apps/server/src/modules/shd/api/api-tests/shd.api.spec.ts Removed SHD API integration tests (deleted).
apps/server/src/modules/server/server.app.module.ts Unregistered ShdApiModule from server module list.
apps/server/src/modules/authorization-rules/rules/user.rule.ts Extended UserRule to handle User entities in addition to UserDo.
apps/server/src/modules/authentication/uc/login.uc.ts Added getSupportLoginData(...) and authorization check for support JWT generation.
apps/server/src/modules/authentication/uc/login.uc.spec.ts Added unit tests for getSupportLoginData(...).
apps/server/src/modules/authentication/controllers/login.controller.ts Added POST support-jwt endpoint under login controller.
apps/server/src/modules/authentication/controllers/dto/target-user-id.params.ts Added DTO for request body validation (IsMongoId).
apps/server/src/modules/authentication/controllers/dto/index.ts Exported the new TargetUserIdParams DTO.
apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts Added API tests covering /support-jwt scenarios.
apps/server/src/modules/authentication/authentication-api.module.ts Imported AuthorizationModule to satisfy AuthorizationService dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to +63
public async getSupportLoginData(targetUserId: EntityId, supportUserId: EntityId): Promise<string> {
// target user should be better fetch over user service, but is not possible because of circular dependency, so we fetch it over authorization service
const [supportUser, targetUser] = await Promise.all([
this.authorizationService.getUserWithPermissions(supportUserId),
this.authorizationService.getUserWithPermissions(targetUserId),
]);

const authContext = AuthorizationContextBuilder.write([
Permission.CREATE_SUPPORT_JWT,
Permission.CAN_EXECUTE_INSTANCE_OPERATIONS,
]);
this.authorizationService.checkPermission(supportUser, targetUser, authContext);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true.
Using authorization over instance for this case was a miss implementation. CAN_EXECUTE_INSTANCE_OPERATION is not connected to the context object instance.
The permission enable execution outside of the given context, in this case user. But enforce that also user write access must be exists.
Setting CAN_EXECUTE_INSTANCE_OPERATION inside of the uc too, enforce that a normal user that can have write access to it self, cant create a support JWT. Only user with the additional permission.

Comment thread apps/server/src/modules/authentication/uc/login.uc.spec.ts Outdated
Comment thread apps/server/src/modules/authorization-rules/rules/user.rule.ts Outdated
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants