|
26 | 26 | import java.util.List;
|
27 | 27 | import java.util.Map;
|
28 | 28 |
|
29 |
| -import org.opensearch.OpenSearchSecurityException; |
| 29 | +import org.opensearch.OpenSearchStatusException; |
30 | 30 | import org.opensearch.OpenSearchWrapperException;
|
31 | 31 | import org.opensearch.ResourceAlreadyExistsException;
|
32 | 32 | import org.opensearch.ResourceNotFoundException;
|
@@ -195,7 +195,10 @@ public void createInteraction(
|
195 | 195 | listener.onFailure(e);
|
196 | 196 | }
|
197 | 197 | } else {
|
198 |
| - throw new OpenSearchSecurityException("User [" + user + "] does not have access to conversation " + conversationId); |
| 198 | + throw new OpenSearchStatusException( |
| 199 | + "User [" + user + "] does not have access to conversation " + conversationId, |
| 200 | + RestStatus.UNAUTHORIZED |
| 201 | + ); |
199 | 202 | }
|
200 | 203 | }, e -> { listener.onFailure(e); }));
|
201 | 204 | } else {
|
@@ -271,7 +274,10 @@ public void getInteractions(String conversationId, int from, int maxResults, Act
|
271 | 274 | .getThreadContext()
|
272 | 275 | .getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT);
|
273 | 276 | String user = User.parse(userstr) == null ? ActionConstants.DEFAULT_USERNAME_FOR_ERRORS : User.parse(userstr).getName();
|
274 |
| - throw new OpenSearchSecurityException("User [" + user + "] does not have access to conversation " + conversationId); |
| 277 | + throw new OpenSearchStatusException( |
| 278 | + "User [" + user + "] does not have access to conversation " + conversationId, |
| 279 | + RestStatus.UNAUTHORIZED |
| 280 | + ); |
275 | 281 | }
|
276 | 282 | }, e -> { listener.onFailure(e); });
|
277 | 283 | conversationMetaIndex.checkAccess(conversationId, accessListener);
|
@@ -355,7 +361,10 @@ public void getTraces(String interactionId, int from, int maxResults, ActionList
|
355 | 361 | String user = User.parse(userstr) == null
|
356 | 362 | ? ActionConstants.DEFAULT_USERNAME_FOR_ERRORS
|
357 | 363 | : User.parse(userstr).getName();
|
358 |
| - throw new OpenSearchSecurityException("User [" + user + "] does not have access to interaction " + interactionId); |
| 364 | + throw new OpenSearchStatusException( |
| 365 | + "User [" + user + "] does not have access to interaction " + interactionId, |
| 366 | + RestStatus.UNAUTHORIZED |
| 367 | + ); |
359 | 368 | }
|
360 | 369 | }, e -> { listener.onFailure(e); });
|
361 | 370 | conversationMetaIndex.checkAccess(conversationId, accessListener);
|
@@ -485,7 +494,10 @@ public void deleteConversation(String conversationId, ActionListener<Boolean> li
|
485 | 494 | if (access) {
|
486 | 495 | getAllInteractions(conversationId, resultsAtATime, searchListener);
|
487 | 496 | } else {
|
488 |
| - throw new OpenSearchSecurityException("User [" + user + "] does not have access to conversation " + conversationId); |
| 497 | + throw new OpenSearchStatusException( |
| 498 | + "User [" + user + "] does not have access to conversation " + conversationId, |
| 499 | + RestStatus.UNAUTHORIZED |
| 500 | + ); |
489 | 501 | }
|
490 | 502 | }, e -> { listener.onFailure(e); });
|
491 | 503 | conversationMetaIndex.checkAccess(conversationId, accessListener);
|
@@ -531,7 +543,10 @@ public void searchInteractions(String conversationId, SearchRequest request, Act
|
531 | 543 | .getThreadContext()
|
532 | 544 | .getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT);
|
533 | 545 | String user = User.parse(userstr) == null ? ActionConstants.DEFAULT_USERNAME_FOR_ERRORS : User.parse(userstr).getName();
|
534 |
| - throw new OpenSearchSecurityException("User [" + user + "] does not have access to conversation " + conversationId); |
| 546 | + throw new OpenSearchStatusException( |
| 547 | + "User [" + user + "] does not have access to conversation " + conversationId, |
| 548 | + RestStatus.UNAUTHORIZED |
| 549 | + ); |
535 | 550 | }
|
536 | 551 | }, e -> { listener.onFailure(e); }));
|
537 | 552 | }
|
@@ -615,7 +630,10 @@ public void updateInteraction(String interactionId, UpdateRequest updateRequest,
|
615 | 630 | String user = User.parse(userstr) == null
|
616 | 631 | ? ActionConstants.DEFAULT_USERNAME_FOR_ERRORS
|
617 | 632 | : User.parse(userstr).getName();
|
618 |
| - throw new OpenSearchSecurityException("User [" + user + "] does not have access to interaction " + interactionId); |
| 633 | + throw new OpenSearchStatusException( |
| 634 | + "User [" + user + "] does not have access to interaction " + interactionId, |
| 635 | + RestStatus.UNAUTHORIZED |
| 636 | + ); |
619 | 637 | }
|
620 | 638 | }, e -> { listener.onFailure(e); });
|
621 | 639 | conversationMetaIndex.checkAccess(conversationId, accessListener);
|
@@ -652,7 +670,10 @@ private void checkInteractionPermission(String interactionId, Interaction intera
|
652 | 670 | .getThreadContext()
|
653 | 671 | .getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT);
|
654 | 672 | String user = User.parse(userstr) == null ? ActionConstants.DEFAULT_USERNAME_FOR_ERRORS : User.parse(userstr).getName();
|
655 |
| - throw new OpenSearchSecurityException("User [" + user + "] does not have access to interaction " + interactionId); |
| 673 | + throw new OpenSearchStatusException( |
| 674 | + "User [" + user + "] does not have access to interaction " + interactionId, |
| 675 | + RestStatus.UNAUTHORIZED |
| 676 | + ); |
656 | 677 | }
|
657 | 678 | }, e -> { internalListener.onFailure(e); });
|
658 | 679 | conversationMetaIndex.checkAccess(conversationId, accessListener);
|
|
0 commit comments