Skip to content

Commit

Permalink
Updates Revoke request
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 5, 2024
1 parent 46960ea commit bc67926
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ public class RevokeResourceAccessRequest extends ActionRequest {

private final String resourceId;
private final Map<EntityType, List<String>> revokeAccess;
private final List<String> scopes;

public RevokeResourceAccessRequest(String resourceId, Map<EntityType, List<String>> revokeAccess) {
public RevokeResourceAccessRequest(String resourceId, Map<EntityType, List<String>> revokeAccess, List<String> scopes) {
this.resourceId = resourceId;
this.revokeAccess = revokeAccess;
this.scopes = scopes;
}

public RevokeResourceAccessRequest(StreamInput in) throws IOException {
this.resourceId = in.readString();
this.revokeAccess = in.readMap(input -> EntityType.valueOf(input.readString()), StreamInput::readStringList);
this.scopes = in.readStringList();
}

@Override
Expand All @@ -41,6 +44,7 @@ public void writeTo(final StreamOutput out) throws IOException {
(streamOutput, entityType) -> streamOutput.writeString(entityType.name()),
StreamOutput::writeStringCollection
);
out.writeStringCollection(scopes);
}

@Override
Expand All @@ -55,4 +59,8 @@ public String getResourceId() {
public Map<EntityType, List<String>> getRevokeAccess() {
return revokeAccess;
}

public List<String> getScopes() {
return scopes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli

String resourceId = (String) source.get("resource_id");
@SuppressWarnings("unchecked")
Map<String, List<String>> revokeSource = (Map<String, List<String>>) source.get("revoke");
Map<String, List<String>> revokeSource = (Map<String, List<String>>) source.get("entities");
Map<EntityType, List<String>> revoke = revokeSource.entrySet().stream().collect(Collectors.toMap(entry -> {
try {
return EntityType.fromValue(entry.getKey());
Expand All @@ -57,8 +57,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
);
}
}, Map.Entry::getValue));

final RevokeResourceAccessRequest revokeResourceAccessRequest = new RevokeResourceAccessRequest(resourceId, revoke);
@SuppressWarnings("unchecked")
List<String> scopes = source.containsKey("scopes") ? (List<String>) source.get("scopes") : List.of();
final RevokeResourceAccessRequest revokeResourceAccessRequest = new RevokeResourceAccessRequest(resourceId, revoke, scopes);
return channel -> client.executeLocally(
RevokeResourceAccessAction.INSTANCE,
revokeResourceAccessRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void revokeAccess(RevokeResourceAccessRequest request) {
try {
ResourceService rs = SampleResourcePlugin.GuiceHolder.getResourceService();
ResourceSharing revoke = rs.getResourceAccessControlPlugin()
.revokeAccess(request.getResourceId(), RESOURCE_INDEX_NAME, request.getRevokeAccess());
.revokeAccess(request.getResourceId(), RESOURCE_INDEX_NAME, request.getRevokeAccess(), request.getScopes());
log.info("Revoked resource access for resource: {} with {}", request.getResourceId(), revoke.toString());
} catch (Exception e) {
log.info("Failed to revoke access for resource {}", request.getResourceId(), e);
Expand Down

0 comments on commit bc67926

Please sign in to comment.