[KEYCLOAK-8768] - Policy evaluation tool failing when client is used and identity.getId is called

This commit is contained in:
Pedro Igor committed 2018-11-14 19:16:41 -02:00
1 parent e391328b5d
commit f5ae76d8e3
1 file changed
+32 -1
@@ -209,6 +209,25 @@ public class PolicyEvaluationService {
}
}
@Override
public String getId() {
if (userSession != null) {
return super.getId();
}
String issuedFor = accessToken.getIssuedFor();
if (issuedFor != null) {
UserModel serviceAccount = keycloakSession.users().getServiceAccount(realm.getClientByClientId(issuedFor));
if (serviceAccount != null) {
return serviceAccount.getId();
}
}
return null;
}
}
private CloseableKeycloakIdentity createIdentity(PolicyEvaluationRequest representation) {
@@ -251,7 +270,19 @@ public class PolicyEvaluationService {
accessToken = new AccessToken();
accessToken.subject(representation.getUserId());
accessToken.issuedFor(representation.getClientId());
ClientModel client = null;
String clientId = representation.getClientId();
if (clientId != null) {
client = realm.getClientById(clientId);
}
if (client == null) {
client = realm.getClientById(resourceServer.getId());
}
accessToken.issuedFor(client.getClientId());
accessToken.audience(client.getId());
accessToken.issuer(Urls.realmIssuer(keycloakSession.getContext().getUri().getBaseUri(), realm.getName()));
accessToken.setRealmAccess(new AccessToken.Access());