|
30 | 30 | import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; |
31 | 31 | import org.elasticsearch.action.support.master.AcknowledgedRequest; |
32 | 32 | import org.elasticsearch.action.update.UpdateRequest; |
| 33 | +import org.elasticsearch.action.update.UpdateRequestBuilder; |
33 | 34 | import org.elasticsearch.action.update.UpdateResponse; |
34 | 35 | import org.elasticsearch.client.Client; |
35 | 36 | import org.elasticsearch.cluster.AckedClusterStateUpdateTask; |
@@ -744,13 +745,17 @@ private void innerRefresh(String tokenDocId, Authentication userAuth, ActionList |
744 | 745 | try (StreamInput in = StreamInput.wrap(Base64.getDecoder().decode(authString))) { |
745 | 746 | in.setVersion(authVersion); |
746 | 747 | Authentication authentication = new Authentication(in); |
747 | | - UpdateRequest updateRequest = |
| 748 | + UpdateRequestBuilder updateRequest = |
748 | 749 | client.prepareUpdate(SecurityIndexManager.SECURITY_INDEX_NAME, TYPE, tokenDocId) |
749 | | - .setVersion(response.getVersion()) |
750 | 750 | .setDoc("refresh_token", Collections.singletonMap("refreshed", true)) |
751 | | - .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL) |
752 | | - .request(); |
753 | | - executeAsyncWithOrigin(client.threadPool().getThreadContext(), SECURITY_ORIGIN, updateRequest, |
| 751 | + .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL); |
| 752 | + if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_6_7_0)) { |
| 753 | + updateRequest.setIfSeqNo(response.getSeqNo()); |
| 754 | + updateRequest.setIfPrimaryTerm(response.getPrimaryTerm()); |
| 755 | + } else { |
| 756 | + updateRequest.setVersion(response.getVersion()); |
| 757 | + } |
| 758 | + executeAsyncWithOrigin(client.threadPool().getThreadContext(), SECURITY_ORIGIN, updateRequest.request(), |
754 | 759 | ActionListener.<UpdateResponse>wrap( |
755 | 760 | updateResponse -> createUserToken(authentication, userAuth, listener, metadata, true), |
756 | 761 | e -> { |
|
0 commit comments