40
40
import org .opensearch .client .Client ;
41
41
import org .opensearch .cluster .service .ClusterService ;
42
42
import org .opensearch .common .settings .Settings ;
43
+ import org .opensearch .commons .authuser .User ;
43
44
import org .opensearch .core .action .ActionListener ;
44
45
import org .opensearch .core .xcontent .NamedXContentRegistry ;
45
46
import org .opensearch .index .query .BoolQueryBuilder ;
@@ -155,14 +156,28 @@ public SearchFeatureDao(
155
156
* @param listener onResponse is called with the epoch time of the latest data under the detector
156
157
*/
157
158
public void getLatestDataTime (Config config , Optional <Entity > entity , AnalysisType context , ActionListener <Optional <Long >> listener ) {
158
- BoolQueryBuilder internalFilterQuery = QueryBuilders .boolQuery ();
159
+ getLatestDataTime (null , config , entity , context , listener );
160
+ }
159
161
162
+ /**
163
+ * Returns to listener the epoch time of the latest data under the detector.
164
+ *
165
+ * @param config info about the data
166
+ * @param listener onResponse is called with the epoch time of the latest data under the detector
167
+ */
168
+ public void getLatestDataTime (
169
+ User user ,
170
+ Config config ,
171
+ Optional <Entity > entity ,
172
+ AnalysisType context ,
173
+ ActionListener <Optional <Long >> listener
174
+ ) {
175
+ BoolQueryBuilder internalFilterQuery = QueryBuilders .boolQuery ();
160
176
if (entity .isPresent ()) {
161
177
for (TermQueryBuilder term : entity .get ().getTermQueryForCustomerIndex ()) {
162
178
internalFilterQuery .filter (term );
163
179
}
164
180
}
165
-
166
181
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder ()
167
182
.query (internalFilterQuery )
168
183
.aggregation (AggregationBuilders .max (CommonName .AGG_NAME_MAX_TIME ).field (config .getTimeField ()))
@@ -172,15 +187,27 @@ public void getLatestDataTime(Config config, Optional<Entity> entity, AnalysisTy
172
187
.wrap (response -> listener .onResponse (ParseUtils .getLatestDataTime (response )), listener ::onFailure );
173
188
// using the original context in listener as user roles have no permissions for internal operations like fetching a
174
189
// checkpoint
175
- clientUtil
176
- .<SearchRequest , SearchResponse >asyncRequestWithInjectedSecurity (
177
- searchRequest ,
178
- client ::search ,
179
- config .getId (),
180
- client ,
181
- context ,
182
- searchResponseListener
183
- );
190
+ if (user != null ) {
191
+ clientUtil
192
+ .<SearchRequest , SearchResponse >asyncRequestWithInjectedSecurity (
193
+ searchRequest ,
194
+ client ::search ,
195
+ user ,
196
+ client ,
197
+ context ,
198
+ searchResponseListener
199
+ );
200
+ } else {
201
+ clientUtil
202
+ .<SearchRequest , SearchResponse >asyncRequestWithInjectedSecurity (
203
+ searchRequest ,
204
+ client ::search ,
205
+ config .getId (),
206
+ client ,
207
+ context ,
208
+ searchResponseListener
209
+ );
210
+ }
184
211
}
185
212
186
213
/**
0 commit comments