Skip to content

Commit

Permalink
Adds type bounding to Resource
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 20, 2024
1 parent 448307b commit d9f5262
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.accesscontrol.resources.testplugins;

import org.opensearch.accesscontrol.resources.Resource;
import org.opensearch.accesscontrol.resources.ResourceService;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.lifecycle.Lifecycle;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void stop() {}

}

public static class TestResource {
public static class TestResource implements Resource {
public String id;
public String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.accesscontrol.resources;

/**
* Marker interface for all resources
*/
public interface Resource {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchException;
import org.opensearch.accesscontrol.resources.Resource;
import org.opensearch.action.search.ClearScrollRequest;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
Expand Down Expand Up @@ -66,7 +67,7 @@ public DefaultResourceAccessControlPlugin(Client client, ThreadPool threadPool)
* @return Set of resource ids
*/
@Override
public <T> Set<T> getAccessibleResourcesForCurrentUser(String resourceIndex, Class<T> clazz) {
public <T extends Resource> Set<T> getAccessibleResourcesForCurrentUser(String resourceIndex, Class<T> clazz) {
final Set<T> documents = new HashSet<>();
final TimeValue scrollTimeout = TimeValue.timeValueMinutes(1);
String scrollId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.plugins;

import org.opensearch.accesscontrol.resources.EntityType;
import org.opensearch.accesscontrol.resources.Resource;
import org.opensearch.accesscontrol.resources.ResourceSharing;
import org.opensearch.accesscontrol.resources.ShareWith;

Expand All @@ -27,10 +28,10 @@ public interface ResourceAccessControlPlugin {
/**
* Returns all accessible resources for current user for a given plugin index.
* @param resourceIndex index where the resource exists
* @param clazz class of the resource. Required to parse the resource object retrieved from resourceIndex
* @param clazz class of the resource. Required to parse the resource object retrieved from resourceIndex. Must be a type of {@link Resource}
* @return set of {@link ResourceSharing} items accessible by current user.
*/
default <T> Set<T> getAccessibleResourcesForCurrentUser(String resourceIndex, Class<T> clazz) {
default <T extends Resource> Set<T> getAccessibleResourcesForCurrentUser(String resourceIndex, Class<T> clazz) {
return Set.of();
}

Expand Down

0 comments on commit d9f5262

Please sign in to comment.