This commit implement feature KEYCLOAK-7337

* return requester

when returnNames=true

* return requesterName
* return owernName
This commit is contained in:
Federico M. Facca 2018-05-11 21:00:18 +02:00
parent eb8257a52e
commit 5cbe595fe3
3 changed files with 38 additions and 4 deletions

View file

@ -28,6 +28,9 @@ public class PermissionTicketRepresentation {
private boolean granted; private boolean granted;
private String scopeName; private String scopeName;
private String resourceName; private String resourceName;
private String requester;
private String ownerName;
private String requesterName;
public String getId() { public String getId() {
return id; return id;
@ -84,4 +87,28 @@ public class PermissionTicketRepresentation {
public String getResourceName() { public String getResourceName() {
return resourceName; return resourceName;
} }
public void setRequesterName(String requesterName) {
this.requesterName = requesterName;
}
public String getRequesterName() {
return requesterName;
}
public void setRequester(String requester) {
this.requester = requester;
}
public String getRequester() {
return requester;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public String getOwnerName() {
return ownerName;
}
} }

View file

@ -848,16 +848,17 @@ public class ModelToRepresentation {
return resource; return resource;
} }
public static PermissionTicketRepresentation toRepresentation(PermissionTicket ticket) { public static PermissionTicketRepresentation toRepresentation(PermissionTicket ticket, AuthorizationProvider authorization) {
return toRepresentation(ticket, false); return toRepresentation(ticket, authorization, false);
} }
public static PermissionTicketRepresentation toRepresentation(PermissionTicket ticket, boolean returnNames) { public static PermissionTicketRepresentation toRepresentation(PermissionTicket ticket, AuthorizationProvider authorization, boolean returnNames) {
PermissionTicketRepresentation representation = new PermissionTicketRepresentation(); PermissionTicketRepresentation representation = new PermissionTicketRepresentation();
representation.setId(ticket.getId()); representation.setId(ticket.getId());
representation.setGranted(ticket.isGranted()); representation.setGranted(ticket.isGranted());
representation.setOwner(ticket.getOwner()); representation.setOwner(ticket.getOwner());
representation.setRequester(ticket.getRequester());
Resource resource = ticket.getResource(); Resource resource = ticket.getResource();
@ -865,6 +866,12 @@ public class ModelToRepresentation {
if (returnNames) { if (returnNames) {
representation.setResourceName(resource.getName()); representation.setResourceName(resource.getName());
KeycloakSession keycloakSession = authorization.getKeycloakSession();
RealmModel realm = authorization.getRealm();
UserModel owner = keycloakSession.users().getUserById(ticket.getOwner(), realm);
UserModel requester = keycloakSession.users().getUserById(ticket.getRequester(), realm);
representation.setRequesterName(requester.getUsername());
representation.setOwnerName(owner.getUsername());
} }
Scope scope = ticket.getScope(); Scope scope = ticket.getScope();

View file

@ -138,7 +138,7 @@ public class PermissionService extends AbstractPermissionService {
return Response.ok().entity(permissionTicketStore.find(filters, resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : Constants.DEFAULT_MAX_RESULTS) return Response.ok().entity(permissionTicketStore.find(filters, resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : Constants.DEFAULT_MAX_RESULTS)
.stream() .stream()
.map(permissionTicket -> ModelToRepresentation.toRepresentation(permissionTicket, returnNames == null ? false : returnNames)) .map(permissionTicket -> ModelToRepresentation.toRepresentation(permissionTicket, authorization, returnNames == null ? false : returnNames))
.collect(Collectors.toList())) .collect(Collectors.toList()))
.build(); .build();
} }