Skip to content

Commit e38b67e

Browse files
Updates exception types in client and root project
Signed-off-by: Darshit Chanpura <[email protected]>
1 parent 52f4ac5 commit e38b67e

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

client/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected void doExecute(Task task, DeleteResourceRequest request, ActionListene
4949
SampleResourceScope.PUBLIC.value(),
5050
ActionListener.wrap(isAuthorized -> {
5151
if (!isAuthorized) {
52-
listener.onFailure(new ResourceSharingException("Current user is not authorized to delete resource: " + resourceId));
52+
listener.onFailure(new UnauthorizedResourceAccessException("Current user is not authorized to delete resource: " + resourceId));
5353
return;
5454
}
5555

client/src/main/java/org/opensearch/security/client/resources/ResourceSharingNodeClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.opensearch.security.resources.rest.ResourceAccessRequest;
2222
import org.opensearch.security.resources.rest.ResourceAccessResponse;
2323
import org.opensearch.security.spi.resources.ShareableResource;
24-
import org.opensearch.security.spi.resources.exceptions.ResourceSharingException;
24+
import org.opensearch.security.spi.resources.exceptions.ResourceSharingFeatureDisabledException;
2525
import org.opensearch.security.spi.resources.sharing.ResourceSharing;
2626
import org.opensearch.security.support.ConfigConstants;
2727
import org.opensearch.transport.client.Client;
@@ -159,7 +159,7 @@ private boolean isResourceAccessControlOrSecurityPluginDisabled(String disabledM
159159
String message = (isSecurityDisabled ? "Security Plugin" : "Resource Access Control feature") + " is disabled.";
160160

161161
log.warn("{} {}", message, disabledMessage);
162-
listener.onFailure(new ResourceSharingException(message + " " + disabledMessage, RestStatus.NOT_IMPLEMENTED));
162+
listener.onFailure(new ResourceSharingFeatureDisabledException(message + " " + disabledMessage, RestStatus.NOT_IMPLEMENTED));
163163
return true;
164164
}
165165
return false;

src/main/java/org/opensearch/security/resources/ResourceAccessHandler.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import org.opensearch.security.configuration.AdminDNs;
2727
import org.opensearch.security.spi.resources.ShareableResource;
2828
import org.opensearch.security.spi.resources.ShareableResourceParser;
29+
import org.opensearch.security.spi.resources.exceptions.ResourceNotFoundException;
2930
import org.opensearch.security.spi.resources.exceptions.ResourceSharingException;
31+
import org.opensearch.security.spi.resources.exceptions.UnauthenticatedResourceAccessException;
32+
import org.opensearch.security.spi.resources.exceptions.UnauthorizedResourceAccessException;
3033
import org.opensearch.security.spi.resources.sharing.Recipient;
3134
import org.opensearch.security.spi.resources.sharing.RecipientType;
3235
import org.opensearch.security.spi.resources.sharing.RecipientTypeRegistry;
@@ -250,7 +253,7 @@ public void hasPermission(String resourceId, String resourceIndex, Set<String> s
250253
if (document == null) {
251254
LOGGER.warn("ShareableResource '{}' not found in index '{}'", resourceId, resourceIndex);
252255
listener.onFailure(
253-
new ResourceSharingException("ShareableResource " + resourceId + " not found in index " + resourceIndex)
256+
new ResourceNotFoundException("ShareableResource " + resourceId + " not found in index " + resourceIndex)
254257
);
255258
return;
256259
}
@@ -299,7 +302,9 @@ public void shareWith(String resourceId, String resourceIndex, ShareWith shareWi
299302

300303
if (user == null) {
301304
LOGGER.warn("No authenticated user found. Failed to share resource {}", resourceId);
302-
listener.onFailure(new ResourceSharingException("No authenticated user found. Failed to share resource " + resourceId));
305+
listener.onFailure(
306+
new UnauthenticatedResourceAccessException("No authenticated user found. Failed to share resource " + resourceId)
307+
);
303308
return;
304309
}
305310

@@ -349,7 +354,7 @@ public void revokeAccess(
349354
if (user == null) {
350355
LOGGER.warn("No authenticated user found. Failed to revoker access to resource {}", resourceId);
351356
listener.onFailure(
352-
new ResourceSharingException("No authenticated user found. Failed to revoke access to resource {}" + resourceId)
357+
new UnauthorizedResourceAccessException("No authenticated user found. Failed to revoke access to resource {}" + resourceId)
353358
);
354359
return;
355360
}
@@ -407,7 +412,7 @@ public void deleteAllResourceSharingRecordsForCurrentUser(ActionListener<Boolean
407412
final User user = (userSubject == null) ? null : userSubject.getUser();
408413

409414
if (user == null) {
410-
listener.onFailure(new ResourceSharingException("No authenticated user available."));
415+
listener.onFailure(new UnauthenticatedResourceAccessException("No authenticated user available."));
411416
return;
412417
}
413418

src/main/java/org/opensearch/security/resources/ResourceSharingIndexHandler.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.opensearch.security.spi.resources.ShareableResource;
6868
import org.opensearch.security.spi.resources.ShareableResourceParser;
6969
import org.opensearch.security.spi.resources.exceptions.ResourceSharingException;
70+
import org.opensearch.security.spi.resources.exceptions.UnauthorizedResourceAccessException;
7071
import org.opensearch.security.spi.resources.sharing.CreatedBy;
7172
import org.opensearch.security.spi.resources.sharing.RecipientType;
7273
import org.opensearch.security.spi.resources.sharing.ResourceSharing;
@@ -763,7 +764,9 @@ public void updateResourceSharingInfo(
763764

764765
LOGGER.error("User {} is not authorized to share resource {}", requestUserName, resourceId);
765766
listener.onFailure(
766-
new ResourceSharingException("User " + requestUserName + " is not authorized to share resource " + resourceId)
767+
new UnauthorizedResourceAccessException(
768+
"User " + requestUserName + " is not authorized to share resource " + resourceId
769+
)
767770
);
768771
}
769772

@@ -912,7 +915,7 @@ public void revokeAccess(
912915
// Only admin or the creator of the resource is currently allowed to revoke access
913916
if (!isAdmin && currentSharingInfo != null && !currentSharingInfo.getCreatedBy().getCreator().equals(requestUserName)) {
914917
listener.onFailure(
915-
new ResourceSharingException(
918+
new UnauthorizedResourceAccessException(
916919
"User " + requestUserName + " is not authorized to revoke access to resource " + resourceId
917920
)
918921
);

src/main/java/org/opensearch/security/resources/rest/ResourceAccessTransportAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.opensearch.core.action.ActionListener;
1919
import org.opensearch.indices.SystemIndices;
2020
import org.opensearch.security.resources.ResourceAccessHandler;
21-
import org.opensearch.security.spi.resources.exceptions.ResourceSharingException;
21+
import org.opensearch.security.spi.resources.exceptions.ResourceNonSystemIndexException;
2222
import org.opensearch.security.spi.resources.sharing.RecipientType;
2323
import org.opensearch.security.spi.resources.sharing.RecipientTypeRegistry;
2424
import org.opensearch.tasks.Task;
@@ -51,7 +51,7 @@ protected void doExecute(Task task, ResourceAccessRequest request, ActionListene
5151
// verify that the request if for a system index
5252
if (!this.systemIndices.isSystemIndex(request.getResourceIndex())) {
5353
actionListener.onFailure(
54-
new ResourceSharingException("Resource index '" + request.getResourceIndex() + "' is not a system index.")
54+
new ResourceNonSystemIndexException("Resource index '" + request.getResourceIndex() + "' is not a system index.")
5555
);
5656
return;
5757
}

0 commit comments

Comments
 (0)