Skip to content

Commit 380172b

Browse files
authored
Remove Version.V_6_x_x constants use in security (#41185)
This removes some use of the v6 constants in various parts of security. Mostly this is BWC testing code, which is no longer needed as ES8 will not need to maintain compatibility with ES6. Relates: #41164
1 parent 29fefcf commit 380172b

File tree

15 files changed

+33
-233
lines changed

15 files changed

+33
-233
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/security/hlrc/HasPrivilegesResponseTests.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.client.security.hlrc;
2121

22-
import org.apache.lucene.util.LuceneTestCase;
2322
import org.elasticsearch.Version;
2423
import org.elasticsearch.client.security.HasPrivilegesResponse;
2524
import org.elasticsearch.common.bytes.BytesReference;
@@ -32,9 +31,7 @@
3231
import org.elasticsearch.common.xcontent.XContentParser;
3332
import org.elasticsearch.common.xcontent.XContentType;
3433
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
35-
import org.elasticsearch.test.VersionUtils;
3634
import org.elasticsearch.xpack.core.security.authz.permission.ResourcePrivileges;
37-
import org.hamcrest.Matchers;
3835
import org.junit.Assert;
3936

4037
import java.io.IOException;
@@ -55,28 +52,6 @@ public class HasPrivilegesResponseTests extends AbstractHlrcStreamableXContentTe
5552
org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse,
5653
HasPrivilegesResponse> {
5754

58-
public void testSerializationV64OrV65() throws IOException {
59-
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original = randomResponse();
60-
final Version version = VersionUtils.randomVersionBetween(LuceneTestCase.random(), Version.V_6_4_0, Version.V_6_5_1);
61-
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy = serializeAndDeserialize(original, version);
62-
63-
Assert.assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch()));
64-
Assert.assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable());
65-
Assert.assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges()));
66-
Assert.assertThat(copy.getApplicationPrivileges(), equalTo(original.getApplicationPrivileges()));
67-
}
68-
69-
public void testSerializationV63() throws IOException {
70-
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original = randomResponse();
71-
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy =
72-
serializeAndDeserialize(original, Version.V_6_3_0);
73-
74-
Assert.assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch()));
75-
Assert.assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable());
76-
Assert.assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges()));
77-
Assert.assertThat(copy.getApplicationPrivileges(), equalTo(Collections.emptyMap()));
78-
}
79-
8055
public void testToXContent() throws Exception {
8156
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse response =
8257
new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse("daredevil",

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.core.security.action.role;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionRequest;
109
import org.elasticsearch.action.ActionRequestValidationException;
1110
import org.elasticsearch.action.support.WriteRequest;
@@ -168,10 +167,8 @@ public void readFrom(StreamInput in) throws IOException {
168167
for (int i = 0; i < indicesSize; i++) {
169168
indicesPrivileges.add(new RoleDescriptor.IndicesPrivileges(in));
170169
}
171-
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
172-
applicationPrivileges = in.readList(RoleDescriptor.ApplicationResourcePrivileges::new);
173-
conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
174-
}
170+
applicationPrivileges = in.readList(RoleDescriptor.ApplicationResourcePrivileges::new);
171+
conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
175172
runAs = in.readStringArray();
176173
refreshPolicy = RefreshPolicy.readFrom(in);
177174
metadata = in.readMap();
@@ -186,10 +183,8 @@ public void writeTo(StreamOutput out) throws IOException {
186183
for (RoleDescriptor.IndicesPrivileges index : indicesPrivileges) {
187184
index.writeTo(out);
188185
}
189-
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
190-
out.writeList(applicationPrivileges);
191-
ConditionalClusterPrivileges.writeArray(out, this.conditionalClusterPrivileges);
192-
}
186+
out.writeList(applicationPrivileges);
187+
ConditionalClusterPrivileges.writeArray(out, this.conditionalClusterPrivileges);
193188
out.writeStringArray(runAs);
194189
refreshPolicy.writeTo(out);
195190
out.writeMap(metadata);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/AuthenticateResponse.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
*/
66
package org.elasticsearch.xpack.core.security.action.user;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionResponse;
109
import org.elasticsearch.common.io.stream.StreamInput;
1110
import org.elasticsearch.common.io.stream.StreamOutput;
1211
import org.elasticsearch.xpack.core.security.authc.Authentication;
13-
import org.elasticsearch.xpack.core.security.user.User;
1412

1513
import java.io.IOException;
1614

@@ -31,23 +29,13 @@ public Authentication authentication() {
3129
@Override
3230
public void writeTo(StreamOutput out) throws IOException {
3331
super.writeTo(out);
34-
if (out.getVersion().before(Version.V_6_6_0)) {
35-
User.writeTo(authentication.getUser(), out);
36-
} else {
37-
authentication.writeTo(out);
38-
}
32+
authentication.writeTo(out);
3933
}
4034

4135
@Override
4236
public void readFrom(StreamInput in) throws IOException {
4337
super.readFrom(in);
44-
if (in.getVersion().before(Version.V_6_6_0)) {
45-
final User user = User.readFrom(in);
46-
final Authentication.RealmRef unknownRealm = new Authentication.RealmRef("__unknown", "__unknown", "__unknown");
47-
authentication = new Authentication(user, unknownRealm, unknownRealm);
48-
} else {
49-
authentication = new Authentication(in);
50-
}
38+
authentication = new Authentication(in);
5139
}
5240

5341
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUserPrivilegesResponse.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.core.security.action.user;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionResponse;
109
import org.elasticsearch.common.Strings;
1110
import org.elasticsearch.common.bytes.BytesReference;
@@ -145,11 +144,7 @@ public Indices(StreamInput in) throws IOException {
145144
return new FieldPermissionsDefinition.FieldGrantExcludeGroup(grant, exclude);
146145
}));
147146
queries = Collections.unmodifiableSet(in.readSet(StreamInput::readBytesReference));
148-
if (in.getVersion().onOrAfter(Version.V_6_7_0)) {
149-
this.allowRestrictedIndices = in.readBoolean();
150-
} else {
151-
this.allowRestrictedIndices = false;
152-
}
147+
this.allowRestrictedIndices = in.readBoolean();
153148
}
154149

155150
public Set<String> getIndices() {
@@ -254,9 +249,7 @@ public void writeTo(StreamOutput out) throws IOException {
254249
output.writeOptionalStringArray(fields.getExcludedFields());
255250
});
256251
out.writeCollection(queries, StreamOutput::writeBytesReference);
257-
if (out.getVersion().onOrAfter(Version.V_6_7_0)) {
258-
out.writeBoolean(allowRestrictedIndices);
259-
}
252+
out.writeBoolean(allowRestrictedIndices);
260253
}
261254
}
262255
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.core.security.action.user;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionRequest;
109
import org.elasticsearch.action.ActionRequestValidationException;
1110
import org.elasticsearch.common.io.stream.StreamInput;
@@ -109,9 +108,7 @@ public void readFrom(StreamInput in) throws IOException {
109108
for (int i = 0; i < indexSize; i++) {
110109
indexPrivileges[i] = new RoleDescriptor.IndicesPrivileges(in);
111110
}
112-
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
113-
applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new);
114-
}
111+
applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new);
115112
}
116113

117114
@Override
@@ -123,9 +120,7 @@ public void writeTo(StreamOutput out) throws IOException {
123120
for (RoleDescriptor.IndicesPrivileges priv : indexPrivileges) {
124121
priv.writeTo(out);
125122
}
126-
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
127-
out.writeArray(ApplicationResourcePrivileges::write, applicationPrivileges);
128-
}
123+
out.writeArray(ApplicationResourcePrivileges::write, applicationPrivileges);
129124
}
130125

131126
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesResponse.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.core.security.action.user;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionResponse;
109
import org.elasticsearch.common.io.stream.StreamInput;
1110
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -103,16 +102,10 @@ public int hashCode() {
103102
public void readFrom(StreamInput in) throws IOException {
104103
super.readFrom(in);
105104
completeMatch = in.readBoolean();
106-
if (in.getVersion().onOrAfter(Version.V_6_6_0 )) {
107-
cluster = in.readMap(StreamInput::readString, StreamInput::readBoolean);
108-
}
105+
cluster = in.readMap(StreamInput::readString, StreamInput::readBoolean);
109106
index = readResourcePrivileges(in);
110-
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
111-
application = in.readMap(StreamInput::readString, HasPrivilegesResponse::readResourcePrivileges);
112-
}
113-
if (in.getVersion().onOrAfter(Version.V_6_6_0)) {
114-
username = in.readString();
115-
}
107+
application = in.readMap(StreamInput::readString, HasPrivilegesResponse::readResourcePrivileges);
108+
username = in.readString();
116109
}
117110

118111
private static Set<ResourcePrivileges> readResourcePrivileges(StreamInput in) throws IOException {
@@ -130,16 +123,10 @@ private static Set<ResourcePrivileges> readResourcePrivileges(StreamInput in) th
130123
public void writeTo(StreamOutput out) throws IOException {
131124
super.writeTo(out);
132125
out.writeBoolean(completeMatch);
133-
if (out.getVersion().onOrAfter(Version.V_6_6_0)) {
134-
out.writeMap(cluster, StreamOutput::writeString, StreamOutput::writeBoolean);
135-
}
126+
out.writeMap(cluster, StreamOutput::writeString, StreamOutput::writeBoolean);
136127
writeResourcePrivileges(out, index);
137-
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
138-
out.writeMap(application, StreamOutput::writeString, HasPrivilegesResponse::writeResourcePrivileges);
139-
}
140-
if (out.getVersion().onOrAfter(Version.V_6_6_0)) {
141-
out.writeString(username);
142-
}
128+
out.writeMap(application, StreamOutput::writeString, HasPrivilegesResponse::writeResourcePrivileges);
129+
out.writeString(username);
143130
}
144131

145132
private static void writeResourcePrivileges(StreamOutput out, Set<ResourcePrivileges> privileges) throws IOException {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Authentication.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,8 @@ public Authentication(StreamInput in) throws IOException {
6060
this.lookedUpBy = null;
6161
}
6262
this.version = in.getVersion();
63-
if (in.getVersion().onOrAfter(Version.V_6_7_0)) {
64-
type = AuthenticationType.values()[in.readVInt()];
65-
metadata = in.readMap();
66-
} else {
67-
type = AuthenticationType.REALM;
68-
metadata = Collections.emptyMap();
69-
}
63+
type = AuthenticationType.values()[in.readVInt()];
64+
metadata = in.readMap();
7065
}
7166

7267
public User getUser() {
@@ -165,10 +160,8 @@ public void writeTo(StreamOutput out) throws IOException {
165160
} else {
166161
out.writeBoolean(false);
167162
}
168-
if (out.getVersion().onOrAfter(Version.V_6_7_0)) {
169-
out.writeVInt(type.ordinal());
170-
out.writeMap(metadata);
171-
}
163+
out.writeVInt(type.ordinal());
164+
out.writeMap(metadata);
172165
}
173166

174167
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/RoleDescriptor.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package org.elasticsearch.xpack.core.security.authz;
77

88
import org.elasticsearch.ElasticsearchParseException;
9-
import org.elasticsearch.Version;
109
import org.elasticsearch.common.Nullable;
1110
import org.elasticsearch.common.ParseField;
1211
import org.elasticsearch.common.Strings;
@@ -122,13 +121,8 @@ public RoleDescriptor(StreamInput in) throws IOException {
122121
this.metadata = in.readMap();
123122
this.transientMetadata = in.readMap();
124123

125-
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
126-
this.applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new);
127-
this.conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
128-
} else {
129-
this.applicationPrivileges = ApplicationResourcePrivileges.NONE;
130-
this.conditionalClusterPrivileges = ConditionalClusterPrivileges.EMPTY_ARRAY;
131-
}
124+
this.applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new);
125+
this.conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
132126
}
133127

134128
public String getName() {
@@ -264,10 +258,8 @@ public void writeTo(StreamOutput out) throws IOException {
264258
out.writeStringArray(runAs);
265259
out.writeMap(metadata);
266260
out.writeMap(transientMetadata);
267-
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
268-
out.writeArray(ApplicationResourcePrivileges::write, applicationPrivileges);
269-
ConditionalClusterPrivileges.writeArray(out, getConditionalClusterPrivileges());
270-
}
261+
out.writeArray(ApplicationResourcePrivileges::write, applicationPrivileges);
262+
ConditionalClusterPrivileges.writeArray(out, getConditionalClusterPrivileges());
271263
}
272264

273265
public static RoleDescriptor parse(String name, BytesReference source, boolean allow2xFormat, XContentType xContentType)
@@ -608,11 +600,7 @@ public IndicesPrivileges(StreamInput in) throws IOException {
608600
this.deniedFields = in.readOptionalStringArray();
609601
this.privileges = in.readStringArray();
610602
this.query = in.readOptionalBytesReference();
611-
if (in.getVersion().onOrAfter(Version.V_6_7_0)) {
612-
allowRestrictedIndices = in.readBoolean();
613-
} else {
614-
allowRestrictedIndices = false;
615-
}
603+
this.allowRestrictedIndices = in.readBoolean();
616604
}
617605

618606
@Override
@@ -622,9 +610,7 @@ public void writeTo(StreamOutput out) throws IOException {
622610
out.writeOptionalStringArray(deniedFields);
623611
out.writeStringArray(privileges);
624612
out.writeOptionalBytesReference(query);
625-
if (out.getVersion().onOrAfter(Version.V_6_7_0)) {
626-
out.writeBoolean(allowRestrictedIndices);
627-
}
613+
out.writeBoolean(allowRestrictedIndices);
628614
}
629615

630616
public static Builder builder() {

0 commit comments

Comments
 (0)