8000 fix for service account role management in admin v2 by edewit · Pull Request #48166 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

fix for service account role management in admin v2 - #48166

Merged
edewit merged 12 commits into
keycloak:mainfrom
edewit:issue-47966
May 21, 2026
Merged

edewit merged 12 commits into
keycloak:mainfrom
edewit:issue-47966

Conversation

@edewit
@edewit edewit commented Apr 16, 2026
Copy link
Copy Markdown
Contributor

fixes: #47966
Signed-off-by: Erik Jan de Wit erikjan.dewit@gmail.com

vmuzikar
vmuzikar previously approved these changes Apr 23, 2026
@vmuzikar vmuzikar 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.

LGTM, thanks @edewit.

This got me thinking that we don't support assigning roles from other clients. Created #48429 for that.

@vmuzikar
Copy link
Copy Markdown
Contributor

@edewit Can you please rebase?

@edewit
edewit commented Apr 27, 2026
Copy link
Copy Markdown
Contributor Author

rebased

@vmuzikar
Copy link
Copy Markdown
Contributor

@edewit Can you please fix the build failures?

@vmuzikar
Copy link
Copy Markdown
Contributor

@edewit Could you please check the failing test?

@vmuzikar
8000 Copy link
Copy Markdown
Contributor

@edewit Spotless is failing.

@edewit
edewit commented Apr 29, 2026
Copy link
Copy Markdown
Contributor Author

done

@vmuzikar
vmuzikar requested a review from Pepo48 May 6, 2026 15:31
@vmuzikar
vmuzikar commented May 6, 2026
Copy link
Copy Markdown
Contributor

@edewit Can you rebase once more please?

@vmuzikar vmuzikar self-assigned this May 7, 2026
@edewit
edewit commented May 11, 2026
Copy link
Copy Markdown
Contributor Author

done

@vmuzikar
Copy link
Copy Markdown
Contributor

@edewit Thanks but build still seem to fail.

@edewit
edewit force-pushed the issue-47966 branch 3 times, most recently from 468945b to 7ae6374 Compare May 12, 2026 07:29
@Pepo48 Pepo48 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.

@edewit thanks for the PR! Now when DefaultClientService no longer needs RealmAdminResource, shouldn't the realmAdminResource field be cleaned up from DefaultClientsApi and DefaultAdminApi? It's stored but never read and DefaultAdminApi constructs a full RealmsAdminResource + TokenManager on every request just to discard them.

See here what I mean: edewit#16

Comment on lines 325 to 326
fireAdminEvent(alreadyExists ? OperationType.UPDATE : OperationType.CREATE, mapper.fromModel(model));
return new CreateOrUpdateResult(mapper.fromModel(model), !alreadyExists);
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.

Suggested change
var representation = mapper.fromModel(model);
fireAdminEvent(alreadyExists ? OperationType.UPDATE : OperationType.CREATE, representation);
return new CreateOrUpdateResult(representation, !alreadyExists);

I just wanted to point out that mapper.fromModel(model) is called twice here. I already reported this on #47029 (comment) for NewClientService but it was marked as expected. Just leaving it here for a reference as we need to revisit it.

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.

This is wrongly applied - the fireAdminEvent call on line is left in place still. Regardless, I wanted to just point this out, not fix it - as I said above, I was told that this is expected and it will be solved rather globally in #46553.

edewit added 4 commits May 18, 2026 10:30
fixes: keycloak#47966
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
edewit and others added 3 commits May 18, 2026 10:30
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
…minApi

Signed-off-by: Peter Zaoral <pzaoral@redhat.com>
…ent/DefaultClientService.java

Co-authored-by: Peter Zaoral <pepo48@gmail.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>
@vmuzikar
Copy link
Copy Markdown
Contributor

Tests failed.

edewit added 3 commits May 18, 2026 13:09
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
@Pepo48 Pepo48 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.

Erik, thanks! I quickly went through it again as more commits have been added since my last check. Specifically the one, where you fixed the context. I think we are missing an NPE check there. This follows how v1 handles it in services/resources/admin/RealmsAdminResource.java (line 212). Without it, a request to /admin/api/nonexistent-realm/clients/v2 returns a 500 instead of 404.

Other than that LGTM.

edewit and others added 2 commits May 20, 2026 17:32
…pi/DefaultAdminApi.java

Co-authored-by: Peter Zaoral <pepo48@gmail.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>
…pi/DefaultAdminApi.java

Co-authored-by: Peter Zaoral <pepo48@gmail.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>
@edewit
edewit enabled auto-merge (squash) May 21, 2026 06:21
@edewit
edewit merged commit 27262be into keycloak:main May 21, 2026
96 of 98 checks passed
@stianst stianst mentioned this pull request Jun 1, 2026
@edewit
edewit deleted the issue-47966 branch June 11, 2026 09:03
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
* fix for service account role management in admin v2

fixes: keycloak#47966
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* fixed merge error

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* fix test

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* fixed build error

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* fixed tests

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* Remove unused RealmAdminResource from DefaultClientsApi and DefaultAdminApi

Signed-off-by: Peter Zaoral <pzaoral@redhat.com>

* Update rest/admin-v2/services/src/main/java/org/keycloak/services/client/DefaultClientService.java

Co-authored-by: Peter Zaoral <pepo48@gmail.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* also update the context

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* fix merge error

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* revert change

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* Update rest/admin-v2/services/src/main/java/org/keycloak/rest/admin/api/DefaultAdminApi.java

Co-authored-by: Peter Zaoral <pepo48@gmail.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update rest/admin-v2/services/src/main/java/org/keycloak/rest/admin/api/DefaultAdminApi.java

Co-authored-by: Peter Zaoral <pepo48@gmail.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

---------

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Peter Zaoral <pzaoral@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>
Co-authored-by: Peter Zaoral <pzaoral@redhat.com>
Co-authored-by: Peter Zaoral <pepo48@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client admin v2 API: service account role management fails for client roles

3 participants

0