|
11 | 11 |
|
12 | 12 | package org.opensearch.security.resource;
|
13 | 13 |
|
14 |
| -import java.io.IOException; |
15 |
| - |
16 | 14 | import org.opensearch.OpenSearchException;
|
17 | 15 | import org.opensearch.ResourceNotFoundException;
|
18 |
| -import org.opensearch.action.get.GetRequest; |
19 |
| -import org.opensearch.action.get.GetResponse; |
20 | 16 | import org.opensearch.action.search.SearchRequest;
|
21 | 17 | import org.opensearch.action.search.SearchResponse;
|
22 | 18 | import org.opensearch.client.Client;
|
23 | 19 | import org.opensearch.common.util.concurrent.ThreadContext;
|
24 |
| -import org.opensearch.common.xcontent.LoggingDeprecationHandler; |
25 |
| -import org.opensearch.common.xcontent.XContentHelper; |
26 |
| -import org.opensearch.common.xcontent.XContentType; |
27 | 20 | import org.opensearch.core.action.ActionListener;
|
28 |
| -import org.opensearch.core.xcontent.NamedXContentRegistry; |
29 |
| -import org.opensearch.core.xcontent.XContentParser; |
30 | 21 | import org.opensearch.index.query.BoolQueryBuilder;
|
31 | 22 | import org.opensearch.index.query.QueryBuilders;
|
32 | 23 | import org.opensearch.search.SearchHit;
|
33 | 24 | import org.opensearch.search.builder.SearchSourceBuilder;
|
34 | 25 | import org.opensearch.security.rest.resource.ShareWith;
|
35 | 26 | import org.opensearch.security.spi.Resource;
|
36 |
| -import org.opensearch.security.spi.ResourceParser; |
37 | 27 | import org.opensearch.security.spi.ResourceSharingService;
|
38 | 28 | import org.opensearch.security.support.ConfigConstants;
|
39 | 29 | import org.opensearch.security.support.WildcardMatcher;
|
|
44 | 34 | public class SecurityResourceSharingService<T extends Resource> implements ResourceSharingService<T> {
|
45 | 35 | private final Client client;
|
46 | 36 | private final String resourceIndex;
|
47 |
| - private final ResourceParser<T> resourceParser; |
48 |
| - private final NamedXContentRegistry xContentRegistry; |
49 | 37 |
|
50 |
| - public SecurityResourceSharingService( |
51 |
| - Client client, |
52 |
| - String resourceIndex, |
53 |
| - ResourceParser<T> resourceParser, |
54 |
| - NamedXContentRegistry xContentRegistry |
55 |
| - ) { |
| 38 | + public SecurityResourceSharingService(Client client, String resourceIndex) { |
56 | 39 | this.client = client;
|
57 | 40 | this.resourceIndex = resourceIndex;
|
58 |
| - this.resourceParser = resourceParser; |
59 |
| - this.xContentRegistry = xContentRegistry; |
60 | 41 | }
|
61 | 42 |
|
62 | 43 | private boolean hasPermissionsFor(User authenticatedUser, ResourceSharingEntry sharedWith) {
|
@@ -122,34 +103,4 @@ public void onFailure(Exception e) {
|
122 | 103 | client.search(searchRequest, searchListener);
|
123 | 104 | }
|
124 | 105 | }
|
125 |
| - |
126 |
| - private void finishGetResourceIfUserIsAllowed(String resourceId, ActionListener<T> getResourceListener) { |
127 |
| - try (ThreadContext.StoredContext ignore = client.threadPool().getThreadContext().stashContext()) { |
128 |
| - GetRequest gr = new GetRequest(resourceIndex); |
129 |
| - gr.id(resourceId); |
130 |
| - ActionListener<GetResponse> getListener = new ActionListener<>() { |
131 |
| - @Override |
132 |
| - public void onResponse(GetResponse getResponse) { |
133 |
| - try { |
134 |
| - XContentParser parser = XContentHelper.createParser( |
135 |
| - xContentRegistry, |
136 |
| - LoggingDeprecationHandler.INSTANCE, |
137 |
| - getResponse.getSourceAsBytesRef(), |
138 |
| - XContentType.JSON |
139 |
| - ); |
140 |
| - T resource = resourceParser.parse(parser, getResponse.getId()); |
141 |
| - getResourceListener.onResponse(resource); |
142 |
| - } catch (IOException e) { |
143 |
| - throw new OpenSearchException("Caught exception while loading resources: " + e.getMessage()); |
144 |
| - } |
145 |
| - } |
146 |
| - |
147 |
| - @Override |
148 |
| - public void onFailure(Exception e) { |
149 |
| - getResourceListener.onFailure(new OpenSearchException("Caught exception while loading resources: " + e.getMessage())); |
150 |
| - } |
151 |
| - }; |
152 |
| - client.get(gr, getListener); |
153 |
| - } |
154 |
| - } |
155 | 106 | }
|
0 commit comments