diff --git a/services/src/main/java/org/keycloak/authorization/common/KeycloakIdentity.java b/services/src/main/java/org/keycloak/authorization/common/KeycloakIdentity.java index 2ea5144413..5db71a2da0 100644 --- a/services/src/main/java/org/keycloak/authorization/common/KeycloakIdentity.java +++ b/services/src/main/java/org/keycloak/authorization/common/KeycloakIdentity.java @@ -150,7 +150,7 @@ public class KeycloakIdentity implements Identity { ClientModel clientModel = getTargetClient(); UserModel clientUser = null; - if (clientModel != null) { + if (clientModel != null && clientModel.isServiceAccountsEnabled()) { clientUser = this.keycloakSession.users().getServiceAccount(clientModel); } @@ -225,7 +225,7 @@ public class KeycloakIdentity implements Identity { ClientModel clientModel = getTargetClient(); UserModel clientUser = null; - if (clientModel != null) { + if (clientModel != null && clientModel.isServiceAccountsEnabled()) { clientUser = this.keycloakSession.users().getServiceAccount(clientModel); }