|
14 | 14 | import static org.opensearch.ad.constant.ADCommonMessages.FAIL_TO_CREATE_DETECTOR;
|
15 | 15 | import static org.opensearch.ad.constant.ADCommonMessages.FAIL_TO_UPDATE_DETECTOR;
|
16 | 16 | import static org.opensearch.ad.settings.AnomalyDetectorSettings.AD_FILTER_BY_BACKEND_ROLES;
|
17 |
| -import static org.opensearch.timeseries.util.ParseUtils.checkFilterByBackendRoles; |
18 |
| -import static org.opensearch.timeseries.util.ParseUtils.getConfig; |
| 17 | +import static org.opensearch.timeseries.util.ParseUtils.*; |
19 | 18 | import static org.opensearch.timeseries.util.RestHandlerUtils.wrapRestActionListener;
|
20 | 19 |
|
21 | 20 | import java.util.List;
|
|
45 | 44 | import org.opensearch.rest.RestRequest;
|
46 | 45 | import org.opensearch.search.builder.SearchSourceBuilder;
|
47 | 46 | import org.opensearch.tasks.Task;
|
48 |
| -import org.opensearch.timeseries.common.exception.TimeSeriesException; |
49 | 47 | import org.opensearch.timeseries.feature.SearchFeatureDao;
|
50 | 48 | import org.opensearch.timeseries.function.ExecutorFunction;
|
51 | 49 | import org.opensearch.timeseries.util.ParseUtils;
|
@@ -100,48 +98,25 @@ protected void doExecute(Task task, IndexAnomalyDetectorRequest request, ActionL
|
100 | 98 | String errorMessage = method == RestRequest.Method.PUT ? FAIL_TO_UPDATE_DETECTOR : FAIL_TO_CREATE_DETECTOR;
|
101 | 99 | ActionListener<IndexAnomalyDetectorResponse> listener = wrapRestActionListener(actionListener, errorMessage);
|
102 | 100 | try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
|
103 |
| - resolveUserAndExecute(user, detectorId, method, listener, (detector) -> adExecute(request, user, detector, context, listener)); |
| 101 | + resolveUserAndExecute(detectorId, method, listener, (detector) -> adExecute(request, user, detector, context, listener)); |
104 | 102 | } catch (Exception e) {
|
105 | 103 | LOG.error(e);
|
106 | 104 | listener.onFailure(e);
|
107 | 105 | }
|
108 | 106 | }
|
109 | 107 |
|
110 | 108 | private void resolveUserAndExecute(
|
111 |
| - User requestedUser, |
112 | 109 | String detectorId,
|
113 | 110 | RestRequest.Method method,
|
114 | 111 | ActionListener<IndexAnomalyDetectorResponse> listener,
|
115 | 112 | Consumer<AnomalyDetector> function
|
116 | 113 | ) {
|
117 | 114 | try {
|
118 |
| - // Check if user has backend roles |
119 |
| - // When filter by is enabled, block users creating/updating detectors who do not have backend roles. |
120 |
| - if (filterByEnabled) { |
121 |
| - String error = checkFilterByBackendRoles(requestedUser); |
122 |
| - if (error != null) { |
123 |
| - listener.onFailure(new TimeSeriesException(error)); |
124 |
| - return; |
125 |
| - } |
126 |
| - } |
| 115 | + |
127 | 116 | if (method == RestRequest.Method.PUT) {
|
128 |
| - // requestedUser == null means security is disabled or user is superadmin. In this case we don't need to |
129 |
| - // check if request user have access to the detector or not. But we still need to get current detector for |
130 |
| - // this case, so we can keep current detector's user data. |
131 |
| - boolean filterByBackendRole = requestedUser == null ? false : filterByEnabled; |
132 | 117 | // Update detector request, check if user has permissions to update the detector
|
133 | 118 | // Get detector and verify backend roles
|
134 |
| - getConfig( |
135 |
| - requestedUser, |
136 |
| - detectorId, |
137 |
| - listener, |
138 |
| - function, |
139 |
| - client, |
140 |
| - clusterService, |
141 |
| - xContentRegistry, |
142 |
| - filterByBackendRole, |
143 |
| - AnomalyDetector.class |
144 |
| - ); |
| 119 | + getConfig(detectorId, listener, function, client, clusterService, xContentRegistry, AnomalyDetector.class); |
145 | 120 | } else {
|
146 | 121 | // Create Detector. No need to get current detector.
|
147 | 122 | function.accept(null);
|
@@ -175,6 +150,8 @@ protected void adExecute(
|
175 | 150 | checkIndicesAndExecute(detector.getIndices(), () -> {
|
176 | 151 | // Don't replace detector's user when update detector
|
177 | 152 | // Github issue: https://github.com/opensearch-project/anomaly-detection/issues/124
|
| 153 | + // TODO this and similar code should be updated to remove reference to a user |
| 154 | + |
178 | 155 | User detectorUser = currentDetector == null ? user : currentDetector.getUser();
|
179 | 156 | IndexAnomalyDetectorActionHandler indexAnomalyDetectorActionHandler = new IndexAnomalyDetectorActionHandler(
|
180 | 157 | clusterService,
|
|
0 commit comments