Convert core security actions to use writeable ActionType (#44359) (#44390)

This commit converts all the StreamableResponseActionType security
classes in xpack core to ActionType, implementing Writeable for their
response classes.

relates #34389
This commit is contained in:
Ryan Ernst 2019-07-16 01:11:13 -07:00 committed by GitHub
parent be98a12cd0
commit c4cf98c538
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 281 additions and 370 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.client.security.hlrc;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.client.security.HasPrivilegesResponse; import org.elasticsearch.client.security.HasPrivilegesResponse;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
@ -31,7 +32,6 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xpack.core.security.authz.permission.ResourcePrivileges; import org.elasticsearch.xpack.core.security.authz.permission.ResourcePrivileges;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
@ -51,7 +51,7 @@ import java.util.stream.Collectors;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class HasPrivilegesResponseTests extends AbstractHlrcStreamableXContentTestCase< public class HasPrivilegesResponseTests extends AbstractResponseTestCase<
org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse, org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse,
HasPrivilegesResponse> { HasPrivilegesResponse> {
@ -110,38 +110,15 @@ public class HasPrivilegesResponseTests extends AbstractHlrcStreamableXContentTe
} }
@Override @Override
protected boolean supportsUnknownFields() { protected org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse createServerTestInstance() {
// Because we have nested objects with { string : boolean }, unknown fields cause parsing problems
return false;
}
@Override
protected org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse createBlankInstance() {
return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse();
}
@Override
protected org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse createTestInstance() {
return randomResponse(); return randomResponse();
} }
@Override @Override
public HasPrivilegesResponse doHlrcParseInstance(XContentParser parser) throws IOException { protected HasPrivilegesResponse doParseToClientInstance(XContentParser parser) throws IOException {
return HasPrivilegesResponse.fromXContent(parser); return HasPrivilegesResponse.fromXContent(parser);
} }
@Override
public org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse convertHlrcToInternal(HasPrivilegesResponse hlrc) {
return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(
hlrc.getUsername(),
hlrc.hasAllRequested(),
hlrc.getClusterPrivileges(),
toResourcePrivileges(hlrc.getIndexPrivileges()),
hlrc.getApplicationPrivileges().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> toResourcePrivileges(e.getValue())))
);
}
private static List<ResourcePrivileges> toResourcePrivileges(Map<String, Map<String, Boolean>> map) { private static List<ResourcePrivileges> toResourcePrivileges(Map<String, Map<String, Boolean>> map) {
return map.entrySet().stream() return map.entrySet().stream()
.map(e -> ResourcePrivileges.builder(e.getKey()).addPrivileges(e.getValue()).build()) .map(e -> ResourcePrivileges.builder(e.getKey()).addPrivileges(e.getValue()).build())
@ -155,11 +132,10 @@ public class HasPrivilegesResponseTests extends AbstractHlrcStreamableXContentTe
out.setVersion(version); out.setVersion(version);
original.writeTo(out); original.writeTo(out);
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy =
new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse();
final StreamInput in = out.bytes().streamInput(); final StreamInput in = out.bytes().streamInput();
in.setVersion(version); in.setVersion(version);
copy.readFrom(in); final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy =
new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(in);
Assert.assertThat(in.read(), equalTo(-1)); Assert.assertThat(in.read(), equalTo(-1));
return copy; return copy;
} }
@ -193,4 +169,19 @@ public class HasPrivilegesResponseTests extends AbstractHlrcStreamableXContentTe
} }
return list; return list;
} }
@Override
protected void assertInstances(org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse serverTestInstance,
HasPrivilegesResponse hlrc) {
org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse other =
new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(
hlrc.getUsername(),
hlrc.hasAllRequested(),
hlrc.getClusterPrivileges(),
toResourcePrivileges(hlrc.getIndexPrivileges()),
hlrc.getApplicationPrivileges().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> toResourcePrivileges(e.getValue())))
);
assertEquals(serverTestInstance, other);
}
} }

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.privilege; package org.elasticsearch.xpack.core.security.action.privilege;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for deleting application privileges. * ActionType for deleting application privileges.
*/ */
public final class DeletePrivilegesAction extends StreamableResponseActionType<DeletePrivilegesResponse> { public final class DeletePrivilegesAction extends ActionType<DeletePrivilegesResponse> {
public static final DeletePrivilegesAction INSTANCE = new DeletePrivilegesAction(); public static final DeletePrivilegesAction INSTANCE = new DeletePrivilegesAction();
public static final String NAME = "cluster:admin/xpack/security/privilege/delete"; public static final String NAME = "cluster:admin/xpack/security/privilege/delete";
private DeletePrivilegesAction() { private DeletePrivilegesAction() {
super(NAME); super(NAME, DeletePrivilegesResponse::new);
}
@Override
public DeletePrivilegesResponse newResponse() {
return new DeletePrivilegesResponse();
} }
} }

View File

@ -25,7 +25,9 @@ public final class DeletePrivilegesResponse extends ActionResponse implements To
private Set<String> found; private Set<String> found;
public DeletePrivilegesResponse() { public DeletePrivilegesResponse(StreamInput in) throws IOException {
super(in);
this.found = Collections.unmodifiableSet(in.readSet(StreamInput::readString));
} }
public DeletePrivilegesResponse(Collection<String> found) { public DeletePrivilegesResponse(Collection<String> found) {
@ -44,8 +46,7 @@ public final class DeletePrivilegesResponse extends ActionResponse implements To
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.found = Collections.unmodifiableSet(in.readSet(StreamInput::readString));
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.privilege; package org.elasticsearch.xpack.core.security.action.privilege;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for retrieving builtin privileges from security * ActionType for retrieving builtin privileges from security
*/ */
public final class GetBuiltinPrivilegesAction extends StreamableResponseActionType<GetBuiltinPrivilegesResponse> { public final class GetBuiltinPrivilegesAction extends ActionType<GetBuiltinPrivilegesResponse> {
public static final GetBuiltinPrivilegesAction INSTANCE = new GetBuiltinPrivilegesAction(); public static final GetBuiltinPrivilegesAction INSTANCE = new GetBuiltinPrivilegesAction();
public static final String NAME = "cluster:admin/xpack/security/privilege/builtin/get"; public static final String NAME = "cluster:admin/xpack/security/privilege/builtin/get";
private GetBuiltinPrivilegesAction() { private GetBuiltinPrivilegesAction() {
super(NAME); super(NAME, GetBuiltinPrivilegesResponse::new);
}
@Override
public GetBuiltinPrivilegesResponse newResponse() {
return new GetBuiltinPrivilegesResponse();
} }
} }

View File

@ -37,6 +37,12 @@ public final class GetBuiltinPrivilegesResponse extends ActionResponse {
this(Collections.emptySet(), Collections.emptySet()); this(Collections.emptySet(), Collections.emptySet());
} }
public GetBuiltinPrivilegesResponse(StreamInput in) throws IOException {
super(in);
this.clusterPrivileges = in.readStringArray();
this.indexPrivileges = in.readStringArray();
}
public String[] getClusterPrivileges() { public String[] getClusterPrivileges() {
return clusterPrivileges; return clusterPrivileges;
} }
@ -47,9 +53,7 @@ public final class GetBuiltinPrivilegesResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.clusterPrivileges = in.readStringArray();
this.indexPrivileges = in.readStringArray();
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.privilege; package org.elasticsearch.xpack.core.security.action.privilege;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for retrieving one or more application privileges from the security index * ActionType for retrieving one or more application privileges from the security index
*/ */
public final class GetPrivilegesAction extends StreamableResponseActionType<GetPrivilegesResponse> { public final class GetPrivilegesAction extends ActionType<GetPrivilegesResponse> {
public static final GetPrivilegesAction INSTANCE = new GetPrivilegesAction(); public static final GetPrivilegesAction INSTANCE = new GetPrivilegesAction();
public static final String NAME = "cluster:admin/xpack/security/privilege/get"; public static final String NAME = "cluster:admin/xpack/security/privilege/get";
private GetPrivilegesAction() { private GetPrivilegesAction() {
super(NAME); super(NAME, GetPrivilegesResponse::new);
}
@Override
public GetPrivilegesResponse newResponse() {
return new GetPrivilegesResponse();
} }
} }

View File

@ -29,8 +29,9 @@ public final class GetPrivilegesResponse extends ActionResponse {
this(privileges.toArray(new ApplicationPrivilegeDescriptor[0])); this(privileges.toArray(new ApplicationPrivilegeDescriptor[0]));
} }
public GetPrivilegesResponse() { public GetPrivilegesResponse(StreamInput in) throws IOException {
this(new ApplicationPrivilegeDescriptor[0]); super(in);
this.privileges = in.readArray(ApplicationPrivilegeDescriptor::new, ApplicationPrivilegeDescriptor[]::new);
} }
public ApplicationPrivilegeDescriptor[] privileges() { public ApplicationPrivilegeDescriptor[] privileges() {
@ -39,8 +40,7 @@ public final class GetPrivilegesResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.privileges = in.readArray(ApplicationPrivilegeDescriptor::new, ApplicationPrivilegeDescriptor[]::new);
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.privilege; package org.elasticsearch.xpack.core.security.action.privilege;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for putting (adding/updating) one or more application privileges. * ActionType for putting (adding/updating) one or more application privileges.
*/ */
public final class PutPrivilegesAction extends StreamableResponseActionType<PutPrivilegesResponse> { public final class PutPrivilegesAction extends ActionType<PutPrivilegesResponse> {
public static final PutPrivilegesAction INSTANCE = new PutPrivilegesAction(); public static final PutPrivilegesAction INSTANCE = new PutPrivilegesAction();
public static final String NAME = "cluster:admin/xpack/security/privilege/put"; public static final String NAME = "cluster:admin/xpack/security/privilege/put";
private PutPrivilegesAction() { private PutPrivilegesAction() {
super(NAME); super(NAME, PutPrivilegesResponse::new);
}
@Override
public PutPrivilegesResponse newResponse() {
return new PutPrivilegesResponse();
} }
} }

View File

@ -24,8 +24,9 @@ public final class PutPrivilegesResponse extends ActionResponse implements ToXCo
private Map<String, List<String>> created; private Map<String, List<String>> created;
PutPrivilegesResponse() { public PutPrivilegesResponse(StreamInput in) throws IOException {
this(Collections.emptyMap()); super(in);
this.created = Collections.unmodifiableMap(in.readMap(StreamInput::readString, StreamInput::readStringList));
} }
public PutPrivilegesResponse(Map<String, List<String>> created) { public PutPrivilegesResponse(Map<String, List<String>> created) {
@ -53,7 +54,6 @@ public final class PutPrivilegesResponse extends ActionResponse implements ToXCo
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.created = Collections.unmodifiableMap(in.readMap(StreamInput::readString, StreamInput::readStringList));
} }
} }

View File

@ -5,23 +5,18 @@
*/ */
package org.elasticsearch.xpack.core.security.action.role; package org.elasticsearch.xpack.core.security.action.role;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for deleting a role from the security index * ActionType for deleting a role from the security index
*/ */
public class DeleteRoleAction extends StreamableResponseActionType<DeleteRoleResponse> { public class DeleteRoleAction extends ActionType<DeleteRoleResponse> {
public static final DeleteRoleAction INSTANCE = new DeleteRoleAction(); public static final DeleteRoleAction INSTANCE = new DeleteRoleAction();
public static final String NAME = "cluster:admin/xpack/security/role/delete"; public static final String NAME = "cluster:admin/xpack/security/role/delete";
protected DeleteRoleAction() { protected DeleteRoleAction() {
super(NAME); super(NAME, DeleteRoleResponse::new);
}
@Override
public DeleteRoleResponse newResponse() {
return new DeleteRoleResponse();
} }
} }

View File

@ -20,7 +20,10 @@ public class DeleteRoleResponse extends ActionResponse implements ToXContentObje
private boolean found = false; private boolean found = false;
public DeleteRoleResponse() {} public DeleteRoleResponse(StreamInput in) throws IOException {
super(in);
found = in.readBoolean();
}
public DeleteRoleResponse(boolean found) { public DeleteRoleResponse(boolean found) {
this.found = found; this.found = found;
@ -38,8 +41,7 @@ public class DeleteRoleResponse extends ActionResponse implements ToXContentObje
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
found = in.readBoolean();
} }
@Override @Override

View File

@ -5,23 +5,18 @@
*/ */
package org.elasticsearch.xpack.core.security.action.role; package org.elasticsearch.xpack.core.security.action.role;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType to retrieve a role from the security index * ActionType to retrieve a role from the security index
*/ */
public class GetRolesAction extends StreamableResponseActionType<GetRolesResponse> { public class GetRolesAction extends ActionType<GetRolesResponse> {
public static final GetRolesAction INSTANCE = new GetRolesAction(); public static final GetRolesAction INSTANCE = new GetRolesAction();
public static final String NAME = "cluster:admin/xpack/security/role/get"; public static final String NAME = "cluster:admin/xpack/security/role/get";
protected GetRolesAction() { protected GetRolesAction() {
super(NAME); super(NAME, GetRolesResponse::new);
}
@Override
public GetRolesResponse newResponse() {
return new GetRolesResponse();
} }
} }

View File

@ -19,6 +19,15 @@ public class GetRolesResponse extends ActionResponse {
private RoleDescriptor[] roles; private RoleDescriptor[] roles;
public GetRolesResponse(StreamInput in) throws IOException {
super(in);
int size = in.readVInt();
roles = new RoleDescriptor[size];
for (int i = 0; i < size; i++) {
roles[i] = new RoleDescriptor(in);
}
}
public GetRolesResponse(RoleDescriptor... roles) { public GetRolesResponse(RoleDescriptor... roles) {
this.roles = roles; this.roles = roles;
} }
@ -33,12 +42,7 @@ public class GetRolesResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
int size = in.readVInt();
roles = new RoleDescriptor[size];
for (int i = 0; i < size; i++) {
roles[i] = new RoleDescriptor(in);
}
} }
@Override @Override

View File

@ -5,23 +5,18 @@
*/ */
package org.elasticsearch.xpack.core.security.action.role; package org.elasticsearch.xpack.core.security.action.role;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for adding a role to the security index * ActionType for adding a role to the security index
*/ */
public class PutRoleAction extends StreamableResponseActionType<PutRoleResponse> { public class PutRoleAction extends ActionType<PutRoleResponse> {
public static final PutRoleAction INSTANCE = new PutRoleAction(); public static final PutRoleAction INSTANCE = new PutRoleAction();
public static final String NAME = "cluster:admin/xpack/security/role/put"; public static final String NAME = "cluster:admin/xpack/security/role/put";
protected PutRoleAction() { protected PutRoleAction() {
super(NAME); super(NAME, PutRoleResponse::new);
}
@Override
public PutRoleResponse newResponse() {
return new PutRoleResponse();
} }
} }

View File

@ -21,7 +21,9 @@ public class PutRoleResponse extends ActionResponse implements ToXContentObject
private boolean created; private boolean created;
public PutRoleResponse() { public PutRoleResponse(StreamInput in) throws IOException {
super(in);
this.created = in.readBoolean();
} }
public PutRoleResponse(boolean created) { public PutRoleResponse(boolean created) {
@ -45,7 +47,6 @@ public class PutRoleResponse extends ActionResponse implements ToXContentObject
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.created = in.readBoolean();
} }
} }

View File

@ -5,23 +5,18 @@
*/ */
package org.elasticsearch.xpack.core.security.action.rolemapping; package org.elasticsearch.xpack.core.security.action.rolemapping;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for deleting a role-mapping from the * ActionType for deleting a role-mapping from the
* org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore * org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore
*/ */
public class DeleteRoleMappingAction extends StreamableResponseActionType<DeleteRoleMappingResponse> { public class DeleteRoleMappingAction extends ActionType<DeleteRoleMappingResponse> {
public static final DeleteRoleMappingAction INSTANCE = new DeleteRoleMappingAction(); public static final DeleteRoleMappingAction INSTANCE = new DeleteRoleMappingAction();
public static final String NAME = "cluster:admin/xpack/security/role_mapping/delete"; public static final String NAME = "cluster:admin/xpack/security/role_mapping/delete";
private DeleteRoleMappingAction() { private DeleteRoleMappingAction() {
super(NAME); super(NAME, DeleteRoleMappingResponse::new);
}
@Override
public DeleteRoleMappingResponse newResponse() {
return new DeleteRoleMappingResponse();
} }
} }

View File

@ -21,10 +21,10 @@ public class DeleteRoleMappingResponse extends ActionResponse implements ToXCont
private boolean found = false; private boolean found = false;
/** public DeleteRoleMappingResponse(StreamInput in) throws IOException {
* Package private for {@link DeleteRoleMappingAction#newResponse()} super(in);
*/ found = in.readBoolean();
public DeleteRoleMappingResponse() {} }
public DeleteRoleMappingResponse(boolean found) { public DeleteRoleMappingResponse(boolean found) {
this.found = found; this.found = found;
@ -46,8 +46,7 @@ public class DeleteRoleMappingResponse extends ActionResponse implements ToXCont
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
found = in.readBoolean();
} }
@Override @Override

View File

@ -5,24 +5,19 @@
*/ */
package org.elasticsearch.xpack.core.security.action.rolemapping; package org.elasticsearch.xpack.core.security.action.rolemapping;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType to retrieve one or more role-mappings from X-Pack security * ActionType to retrieve one or more role-mappings from X-Pack security
* *
* see org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore * see org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore
*/ */
public class GetRoleMappingsAction extends StreamableResponseActionType<GetRoleMappingsResponse> { public class GetRoleMappingsAction extends ActionType<GetRoleMappingsResponse> {
public static final GetRoleMappingsAction INSTANCE = new GetRoleMappingsAction(); public static final GetRoleMappingsAction INSTANCE = new GetRoleMappingsAction();
public static final String NAME = "cluster:admin/xpack/security/role_mapping/get"; public static final String NAME = "cluster:admin/xpack/security/role_mapping/get";
private GetRoleMappingsAction() { private GetRoleMappingsAction() {
super(NAME); super(NAME, GetRoleMappingsResponse::new);
}
@Override
public GetRoleMappingsResponse newResponse() {
return new GetRoleMappingsResponse();
} }
} }

View File

@ -21,6 +21,15 @@ public class GetRoleMappingsResponse extends ActionResponse {
private ExpressionRoleMapping[] mappings; private ExpressionRoleMapping[] mappings;
public GetRoleMappingsResponse(StreamInput in) throws IOException {
super(in);
int size = in.readVInt();
mappings = new ExpressionRoleMapping[size];
for (int i = 0; i < size; i++) {
mappings[i] = new ExpressionRoleMapping(in);
}
}
public GetRoleMappingsResponse(ExpressionRoleMapping... mappings) { public GetRoleMappingsResponse(ExpressionRoleMapping... mappings) {
this.mappings = mappings; this.mappings = mappings;
} }
@ -35,12 +44,7 @@ public class GetRoleMappingsResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
int size = in.readVInt();
mappings = new ExpressionRoleMapping[size];
for (int i = 0; i < size; i++) {
mappings[i] = new ExpressionRoleMapping(in);
}
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.rolemapping; package org.elasticsearch.xpack.core.security.action.rolemapping;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for adding a role to the security index * ActionType for adding a role to the security index
*/ */
public class PutRoleMappingAction extends StreamableResponseActionType<PutRoleMappingResponse> { public class PutRoleMappingAction extends ActionType<PutRoleMappingResponse> {
public static final PutRoleMappingAction INSTANCE = new PutRoleMappingAction(); public static final PutRoleMappingAction INSTANCE = new PutRoleMappingAction();
public static final String NAME = "cluster:admin/xpack/security/role_mapping/put"; public static final String NAME = "cluster:admin/xpack/security/role_mapping/put";
private PutRoleMappingAction() { private PutRoleMappingAction() {
super(NAME); super(NAME, PutRoleMappingResponse::new);
}
@Override
public PutRoleMappingResponse newResponse() {
return new PutRoleMappingResponse();
} }
} }

View File

@ -22,7 +22,9 @@ public class PutRoleMappingResponse extends ActionResponse implements ToXContent
private boolean created; private boolean created;
public PutRoleMappingResponse() { public PutRoleMappingResponse(StreamInput in) throws IOException {
super(in);
this.created = in.readBoolean();
} }
public PutRoleMappingResponse(boolean created) { public PutRoleMappingResponse(boolean created) {
@ -46,7 +48,6 @@ public class PutRoleMappingResponse extends ActionResponse implements ToXContent
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.created = in.readBoolean();
} }
} }

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.saml; package org.elasticsearch.xpack.core.security.action.saml;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for authenticating using SAML assertions * ActionType for authenticating using SAML assertions
*/ */
public final class SamlAuthenticateAction extends StreamableResponseActionType<SamlAuthenticateResponse> { public final class SamlAuthenticateAction extends ActionType<SamlAuthenticateResponse> {
public static final String NAME = "cluster:admin/xpack/security/saml/authenticate"; public static final String NAME = "cluster:admin/xpack/security/saml/authenticate";
public static final SamlAuthenticateAction INSTANCE = new SamlAuthenticateAction(); public static final SamlAuthenticateAction INSTANCE = new SamlAuthenticateAction();
private SamlAuthenticateAction() { private SamlAuthenticateAction() {
super(NAME); super(NAME, SamlAuthenticateResponse::new);
}
@Override
public SamlAuthenticateResponse newResponse() {
return new SamlAuthenticateResponse();
} }
} }

View File

@ -23,7 +23,12 @@ public final class SamlAuthenticateResponse extends ActionResponse {
private String refreshToken; private String refreshToken;
private TimeValue expiresIn; private TimeValue expiresIn;
public SamlAuthenticateResponse() { public SamlAuthenticateResponse(StreamInput in) throws IOException {
super(in);
principal = in.readString();
tokenString = in.readString();
refreshToken = in.readString();
expiresIn = in.readTimeValue();
} }
public SamlAuthenticateResponse(String principal, String tokenString, String refreshToken, TimeValue expiresIn) { public SamlAuthenticateResponse(String principal, String tokenString, String refreshToken, TimeValue expiresIn) {
@ -59,10 +64,6 @@ public final class SamlAuthenticateResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
principal = in.readString();
tokenString = in.readString();
refreshToken = in.readString();
expiresIn = in.readTimeValue();
} }
} }

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.saml; package org.elasticsearch.xpack.core.security.action.saml;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType to perform IdP-initiated logout for a SAML-SSO user * ActionType to perform IdP-initiated logout for a SAML-SSO user
*/ */
public final class SamlInvalidateSessionAction extends StreamableResponseActionType<SamlInvalidateSessionResponse> { public final class SamlInvalidateSessionAction extends ActionType<SamlInvalidateSessionResponse> {
public static final String NAME = "cluster:admin/xpack/security/saml/invalidate"; public static final String NAME = "cluster:admin/xpack/security/saml/invalidate";
public static final SamlInvalidateSessionAction INSTANCE = new SamlInvalidateSessionAction(); public static final SamlInvalidateSessionAction INSTANCE = new SamlInvalidateSessionAction();
private SamlInvalidateSessionAction() { private SamlInvalidateSessionAction() {
super(NAME); super(NAME, SamlInvalidateSessionResponse::new);
}
@Override
public SamlInvalidateSessionResponse newResponse() {
return new SamlInvalidateSessionResponse();
} }
} }

View File

@ -20,7 +20,11 @@ public final class SamlInvalidateSessionResponse extends ActionResponse {
private int count; private int count;
private String redirectUrl; private String redirectUrl;
public SamlInvalidateSessionResponse() { public SamlInvalidateSessionResponse(StreamInput in) throws IOException {
super(in);
realmName = in.readString();
count = in.readInt();
redirectUrl = in.readString();
} }
public SamlInvalidateSessionResponse(String realmName, int count, String redirectUrl) { public SamlInvalidateSessionResponse(String realmName, int count, String redirectUrl) {
@ -50,10 +54,7 @@ public final class SamlInvalidateSessionResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
realmName = in.readString();
count = in.readInt();
redirectUrl = in.readString();
} }
} }

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.saml; package org.elasticsearch.xpack.core.security.action.saml;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for initiating a logout process for a SAML-SSO user * ActionType for initiating a logout process for a SAML-SSO user
*/ */
public final class SamlLogoutAction extends StreamableResponseActionType<SamlLogoutResponse> { public final class SamlLogoutAction extends ActionType<SamlLogoutResponse> {
public static final String NAME = "cluster:admin/xpack/security/saml/logout"; public static final String NAME = "cluster:admin/xpack/security/saml/logout";
public static final SamlLogoutAction INSTANCE = new SamlLogoutAction(); public static final SamlLogoutAction INSTANCE = new SamlLogoutAction();
private SamlLogoutAction() { private SamlLogoutAction() {
super(NAME); super(NAME, SamlLogoutResponse::new);
}
@Override
public SamlLogoutResponse newResponse() {
return new SamlLogoutResponse();
} }
} }

View File

@ -18,7 +18,9 @@ public final class SamlLogoutResponse extends ActionResponse {
private String redirectUrl; private String redirectUrl;
public SamlLogoutResponse() { public SamlLogoutResponse(StreamInput in) throws IOException {
super(in);
redirectUrl = in.readString();
} }
public SamlLogoutResponse(String redirectUrl) { public SamlLogoutResponse(String redirectUrl) {
@ -36,8 +38,7 @@ public final class SamlLogoutResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
redirectUrl = in.readString();
} }
} }

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.saml; package org.elasticsearch.xpack.core.security.action.saml;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for initiating an authentication process using SAML assertions * ActionType for initiating an authentication process using SAML assertions
*/ */
public final class SamlPrepareAuthenticationAction extends StreamableResponseActionType<SamlPrepareAuthenticationResponse> { public final class SamlPrepareAuthenticationAction extends ActionType<SamlPrepareAuthenticationResponse> {
public static final String NAME = "cluster:admin/xpack/security/saml/prepare"; public static final String NAME = "cluster:admin/xpack/security/saml/prepare";
public static final SamlPrepareAuthenticationAction INSTANCE = new SamlPrepareAuthenticationAction(); public static final SamlPrepareAuthenticationAction INSTANCE = new SamlPrepareAuthenticationAction();
private SamlPrepareAuthenticationAction() { private SamlPrepareAuthenticationAction() {
super(NAME); super(NAME, SamlPrepareAuthenticationResponse::new);
}
@Override
public SamlPrepareAuthenticationResponse newResponse() {
return new SamlPrepareAuthenticationResponse();
} }
} }

View File

@ -20,7 +20,9 @@ public final class SamlPrepareAuthenticationResponse extends ActionResponse {
private String requestId; private String requestId;
private String redirectUrl; private String redirectUrl;
public SamlPrepareAuthenticationResponse() { public SamlPrepareAuthenticationResponse(StreamInput in) throws IOException {
super(in);
redirectUrl = in.readString();
} }
public SamlPrepareAuthenticationResponse(String realmName, String requestId, String redirectUrl) { public SamlPrepareAuthenticationResponse(String realmName, String requestId, String redirectUrl) {
@ -48,8 +50,7 @@ public final class SamlPrepareAuthenticationResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
redirectUrl = in.readString();
} }
} }

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.token; package org.elasticsearch.xpack.core.security.action.token;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for creating a new token * ActionType for creating a new token
*/ */
public final class CreateTokenAction extends StreamableResponseActionType<CreateTokenResponse> { public final class CreateTokenAction extends ActionType<CreateTokenResponse> {
public static final String NAME = "cluster:admin/xpack/security/token/create"; public static final String NAME = "cluster:admin/xpack/security/token/create";
public static final CreateTokenAction INSTANCE = new CreateTokenAction(); public static final CreateTokenAction INSTANCE = new CreateTokenAction();
private CreateTokenAction() { private CreateTokenAction() {
super(NAME); super(NAME, CreateTokenResponse::new);
}
@Override
public CreateTokenResponse newResponse() {
return new CreateTokenResponse();
} }
} }

View File

@ -31,6 +31,19 @@ public final class CreateTokenResponse extends ActionResponse implements ToXCont
CreateTokenResponse() {} CreateTokenResponse() {}
public CreateTokenResponse(StreamInput in) throws IOException {
super(in);
tokenString = in.readString();
expiresIn = in.readTimeValue();
scope = in.readOptionalString();
if (in.getVersion().onOrAfter(Version.V_6_5_0)) {
refreshToken = in.readOptionalString();
} else if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
refreshToken = in.readString();
}
kerberosAuthenticationResponseToken = in.readOptionalString();
}
public CreateTokenResponse(String tokenString, TimeValue expiresIn, String scope, String refreshToken, public CreateTokenResponse(String tokenString, TimeValue expiresIn, String scope, String refreshToken,
String kerberosAuthenticationResponseToken) { String kerberosAuthenticationResponseToken) {
this.tokenString = Objects.requireNonNull(tokenString); this.tokenString = Objects.requireNonNull(tokenString);
@ -79,16 +92,7 @@ public final class CreateTokenResponse extends ActionResponse implements ToXCont
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
tokenString = in.readString();
expiresIn = in.readTimeValue();
scope = in.readOptionalString();
if (in.getVersion().onOrAfter(Version.V_6_5_0)) {
refreshToken = in.readOptionalString();
} else if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
refreshToken = in.readString();
}
kerberosAuthenticationResponseToken = in.readOptionalString();
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.token; package org.elasticsearch.xpack.core.security.action.token;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for invalidating one or more tokens * ActionType for invalidating one or more tokens
*/ */
public final class InvalidateTokenAction extends StreamableResponseActionType<InvalidateTokenResponse> { public final class InvalidateTokenAction extends ActionType<InvalidateTokenResponse> {
public static final String NAME = "cluster:admin/xpack/security/token/invalidate"; public static final String NAME = "cluster:admin/xpack/security/token/invalidate";
public static final InvalidateTokenAction INSTANCE = new InvalidateTokenAction(); public static final InvalidateTokenAction INSTANCE = new InvalidateTokenAction();
private InvalidateTokenAction() { private InvalidateTokenAction() {
super(NAME); super(NAME, InvalidateTokenResponse::new);
}
@Override
public InvalidateTokenResponse newResponse() {
return new InvalidateTokenResponse();
} }
} }

View File

@ -25,6 +25,11 @@ public final class InvalidateTokenResponse extends ActionResponse implements ToX
public InvalidateTokenResponse() {} public InvalidateTokenResponse() {}
public InvalidateTokenResponse(StreamInput in) throws IOException {
super(in);
result = new TokensInvalidationResult(in);
}
public InvalidateTokenResponse(TokensInvalidationResult result) { public InvalidateTokenResponse(TokensInvalidationResult result) {
this.result = result; this.result = result;
} }
@ -40,8 +45,7 @@ public final class InvalidateTokenResponse extends ActionResponse implements ToX
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
result = new TokensInvalidationResult(in);
} }
@Override @Override

View File

@ -5,19 +5,14 @@
*/ */
package org.elasticsearch.xpack.core.security.action.token; package org.elasticsearch.xpack.core.security.action.token;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
public final class RefreshTokenAction extends StreamableResponseActionType<CreateTokenResponse> { public final class RefreshTokenAction extends ActionType<CreateTokenResponse> {
public static final String NAME = "cluster:admin/xpack/security/token/refresh"; public static final String NAME = "cluster:admin/xpack/security/token/refresh";
public static final RefreshTokenAction INSTANCE = new RefreshTokenAction(); public static final RefreshTokenAction INSTANCE = new RefreshTokenAction();
private RefreshTokenAction() { private RefreshTokenAction() {
super(NAME); super(NAME, CreateTokenResponse::new);
}
@Override
public CreateTokenResponse newResponse() {
return new CreateTokenResponse();
} }
} }

View File

@ -5,19 +5,14 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
public class AuthenticateAction extends StreamableResponseActionType<AuthenticateResponse> { public class AuthenticateAction extends ActionType<AuthenticateResponse> {
public static final String NAME = "cluster:admin/xpack/security/user/authenticate"; public static final String NAME = "cluster:admin/xpack/security/user/authenticate";
public static final AuthenticateAction INSTANCE = new AuthenticateAction(); public static final AuthenticateAction INSTANCE = new AuthenticateAction();
public AuthenticateAction() { public AuthenticateAction() {
super(NAME); super(NAME, AuthenticateResponse::new);
}
@Override
public AuthenticateResponse newResponse() {
return new AuthenticateResponse();
} }
} }

View File

@ -18,7 +18,16 @@ public class AuthenticateResponse extends ActionResponse {
private Authentication authentication; private Authentication authentication;
public AuthenticateResponse() {} public AuthenticateResponse(StreamInput in) throws IOException {
super(in);
if (in.getVersion().before(Version.V_6_6_0)) {
final User user = User.readFrom(in);
final Authentication.RealmRef unknownRealm = new Authentication.RealmRef("__unknown", "__unknown", "__unknown");
authentication = new Authentication(user, unknownRealm, unknownRealm);
} else {
authentication = new Authentication(in);
}
}
public AuthenticateResponse(Authentication authentication){ public AuthenticateResponse(Authentication authentication){
this.authentication = authentication; this.authentication = authentication;
@ -39,14 +48,7 @@ public class AuthenticateResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
if (in.getVersion().before(Version.V_6_6_0)) {
final User user = User.readFrom(in);
final Authentication.RealmRef unknownRealm = new Authentication.RealmRef("__unknown", "__unknown", "__unknown");
authentication = new Authentication(user, unknownRealm, unknownRealm);
} else {
authentication = new Authentication(in);
}
} }
} }

View File

@ -5,19 +5,14 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
public class ChangePasswordAction extends StreamableResponseActionType<ChangePasswordResponse> { public class ChangePasswordAction extends ActionType<ChangePasswordResponse> {
public static final ChangePasswordAction INSTANCE = new ChangePasswordAction(); public static final ChangePasswordAction INSTANCE = new ChangePasswordAction();
public static final String NAME = "cluster:admin/xpack/security/user/change_password"; public static final String NAME = "cluster:admin/xpack/security/user/change_password";
protected ChangePasswordAction() { protected ChangePasswordAction() {
super(NAME); super(NAME, ChangePasswordResponse::new);
}
@Override
public ChangePasswordResponse newResponse() {
return new ChangePasswordResponse();
} }
} }

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException; import java.io.IOException;
@ -14,6 +15,10 @@ public class ChangePasswordResponse extends ActionResponse {
public ChangePasswordResponse() {} public ChangePasswordResponse() {}
public ChangePasswordResponse(StreamInput in) throws IOException {
super(in);
}
@Override @Override
public void writeTo(StreamOutput out) throws IOException {} public void writeTo(StreamOutput out) throws IOException {}
} }

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for deleting a native user. * ActionType for deleting a native user.
*/ */
public class DeleteUserAction extends StreamableResponseActionType<DeleteUserResponse> { public class DeleteUserAction extends ActionType<DeleteUserResponse> {
public static final DeleteUserAction INSTANCE = new DeleteUserAction(); public static final DeleteUserAction INSTANCE = new DeleteUserAction();
public static final String NAME = "cluster:admin/xpack/security/user/delete"; public static final String NAME = "cluster:admin/xpack/security/user/delete";
protected DeleteUserAction() { protected DeleteUserAction() {
super(NAME); super(NAME, DeleteUserResponse::new);
}
@Override
public DeleteUserResponse newResponse() {
return new DeleteUserResponse();
} }
} }

View File

@ -21,7 +21,9 @@ public class DeleteUserResponse extends ActionResponse implements ToXContentObje
private boolean found; private boolean found;
public DeleteUserResponse() { public DeleteUserResponse(StreamInput in) throws IOException {
super(in);
found = in.readBoolean();
} }
public DeleteUserResponse(boolean found) { public DeleteUserResponse(boolean found) {
@ -40,8 +42,7 @@ public class DeleteUserResponse extends ActionResponse implements ToXContentObje
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
found = in.readBoolean();
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType that lists the set of privileges held by a user. * ActionType that lists the set of privileges held by a user.
*/ */
public final class GetUserPrivilegesAction extends StreamableResponseActionType<GetUserPrivilegesResponse> { public final class GetUserPrivilegesAction extends ActionType<GetUserPrivilegesResponse> {
public static final GetUserPrivilegesAction INSTANCE = new GetUserPrivilegesAction(); public static final GetUserPrivilegesAction INSTANCE = new GetUserPrivilegesAction();
public static final String NAME = "cluster:admin/xpack/security/user/list_privileges"; public static final String NAME = "cluster:admin/xpack/security/user/list_privileges";
private GetUserPrivilegesAction() { private GetUserPrivilegesAction() {
super(NAME); super(NAME, GetUserPrivilegesResponse::new);
}
@Override
public GetUserPrivilegesResponse newResponse() {
return new GetUserPrivilegesResponse();
} }
} }

View File

@ -38,8 +38,13 @@ public final class GetUserPrivilegesResponse extends ActionResponse {
private Set<RoleDescriptor.ApplicationResourcePrivileges> application; private Set<RoleDescriptor.ApplicationResourcePrivileges> application;
private Set<String> runAs; private Set<String> runAs;
public GetUserPrivilegesResponse() { public GetUserPrivilegesResponse(StreamInput in) throws IOException {
this(Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()); super(in);
cluster = Collections.unmodifiableSet(in.readSet(StreamInput::readString));
conditionalCluster = Collections.unmodifiableSet(in.readSet(ConditionalClusterPrivileges.READER));
index = Collections.unmodifiableSet(in.readSet(Indices::new));
application = Collections.unmodifiableSet(in.readSet(RoleDescriptor.ApplicationResourcePrivileges::new));
runAs = Collections.unmodifiableSet(in.readSet(StreamInput::readString));
} }
public GetUserPrivilegesResponse(Set<String> cluster, Set<ConditionalClusterPrivilege> conditionalCluster, public GetUserPrivilegesResponse(Set<String> cluster, Set<ConditionalClusterPrivilege> conditionalCluster,
@ -74,12 +79,7 @@ public final class GetUserPrivilegesResponse extends ActionResponse {
} }
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
cluster = Collections.unmodifiableSet(in.readSet(StreamInput::readString));
conditionalCluster = Collections.unmodifiableSet(in.readSet(ConditionalClusterPrivileges.READER));
index = Collections.unmodifiableSet(in.readSet(Indices::new));
application = Collections.unmodifiableSet(in.readSet(RoleDescriptor.ApplicationResourcePrivileges::new));
runAs = Collections.unmodifiableSet(in.readSet(StreamInput::readString));
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for retrieving a user from the security index * ActionType for retrieving a user from the security index
*/ */
public class GetUsersAction extends StreamableResponseActionType<GetUsersResponse> { public class GetUsersAction extends ActionType<GetUsersResponse> {
public static final GetUsersAction INSTANCE = new GetUsersAction(); public static final GetUsersAction INSTANCE = new GetUsersAction();
public static final String NAME = "cluster:admin/xpack/security/user/get"; public static final String NAME = "cluster:admin/xpack/security/user/get";
protected GetUsersAction() { protected GetUsersAction() {
super(NAME); super(NAME, GetUsersResponse::new);
}
@Override
public GetUsersResponse newResponse() {
return new GetUsersResponse();
} }
} }

View File

@ -20,6 +20,19 @@ public class GetUsersResponse extends ActionResponse {
private User[] users; private User[] users;
public GetUsersResponse(StreamInput in) throws IOException {
super(in);
int size = in.readVInt();
if (size < 0) {
users = null;
} else {
users = new User[size];
for (int i = 0; i < size; i++) {
users[i] = User.readFrom(in);
}
}
}
public GetUsersResponse(User... users) { public GetUsersResponse(User... users) {
this.users = users; this.users = users;
} }
@ -38,16 +51,7 @@ public class GetUsersResponse extends ActionResponse {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
int size = in.readVInt();
if (size < 0) {
users = null;
} else {
users = new User[size];
for (int i = 0; i < size; i++) {
users[i] = User.readFrom(in);
}
}
} }
@Override @Override

View File

@ -5,24 +5,19 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor; import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
/** /**
* This action is testing whether a user has the specified * This action is testing whether a user has the specified
* {@link RoleDescriptor.IndicesPrivileges privileges} * {@link RoleDescriptor.IndicesPrivileges privileges}
*/ */
public class HasPrivilegesAction extends StreamableResponseActionType<HasPrivilegesResponse> { public class HasPrivilegesAction extends ActionType<HasPrivilegesResponse> {
public static final HasPrivilegesAction INSTANCE = new HasPrivilegesAction(); public static final HasPrivilegesAction INSTANCE = new HasPrivilegesAction();
public static final String NAME = "cluster:admin/xpack/security/user/has_privileges"; public static final String NAME = "cluster:admin/xpack/security/user/has_privileges";
private HasPrivilegesAction() { private HasPrivilegesAction() {
super(NAME); super(NAME, HasPrivilegesResponse::new);
}
@Override
public HasPrivilegesResponse newResponse() {
return new HasPrivilegesResponse();
} }
} }

View File

@ -37,6 +37,25 @@ public class HasPrivilegesResponse extends ActionResponse implements ToXContentO
this("", true, Collections.emptyMap(), Collections.emptyList(), Collections.emptyMap()); this("", true, Collections.emptyMap(), Collections.emptyList(), Collections.emptyMap());
} }
public HasPrivilegesResponse(StreamInput in) throws IOException {
super(in);
completeMatch = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_6_6_0 )) {
cluster = in.readMap(StreamInput::readString, StreamInput::readBoolean);
} else {
cluster = Collections.emptyMap();
}
index = readResourcePrivileges(in);
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
application = in.readMap(StreamInput::readString, HasPrivilegesResponse::readResourcePrivileges);
} else {
application = Collections.emptyMap();
}
if (in.getVersion().onOrAfter(Version.V_6_6_0)) {
username = in.readString();
}
}
public HasPrivilegesResponse(String username, boolean completeMatch, Map<String, Boolean> cluster, Collection<ResourcePrivileges> index, public HasPrivilegesResponse(String username, boolean completeMatch, Map<String, Boolean> cluster, Collection<ResourcePrivileges> index,
Map<String, Collection<ResourcePrivileges>> application) { Map<String, Collection<ResourcePrivileges>> application) {
super(); super();
@ -101,18 +120,7 @@ public class HasPrivilegesResponse extends ActionResponse implements ToXContentO
} }
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
completeMatch = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_6_6_0 )) {
cluster = in.readMap(StreamInput::readString, StreamInput::readBoolean);
}
index = readResourcePrivileges(in);
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
application = in.readMap(StreamInput::readString, HasPrivilegesResponse::readResourcePrivileges);
}
if (in.getVersion().onOrAfter(Version.V_6_6_0)) {
username = in.readString();
}
} }
private static Set<ResourcePrivileges> readResourcePrivileges(StreamInput in) throws IOException { private static Set<ResourcePrivileges> readResourcePrivileges(StreamInput in) throws IOException {

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* ActionType for putting (adding/updating) a native user. * ActionType for putting (adding/updating) a native user.
*/ */
public class PutUserAction extends StreamableResponseActionType<PutUserResponse> { public class PutUserAction extends ActionType<PutUserResponse> {
public static final PutUserAction INSTANCE = new PutUserAction(); public static final PutUserAction INSTANCE = new PutUserAction();
public static final String NAME = "cluster:admin/xpack/security/user/put"; public static final String NAME = "cluster:admin/xpack/security/user/put";
protected PutUserAction() { protected PutUserAction() {
super(NAME); super(NAME, PutUserResponse::new);
}
@Override
public PutUserResponse newResponse() {
return new PutUserResponse();
} }
} }

View File

@ -22,7 +22,9 @@ public class PutUserResponse extends ActionResponse implements ToXContentObject
private boolean created; private boolean created;
public PutUserResponse() { public PutUserResponse(StreamInput in) throws IOException {
super(in);
this.created = in.readBoolean();
} }
public PutUserResponse(boolean created) { public PutUserResponse(boolean created) {
@ -40,8 +42,7 @@ public class PutUserResponse extends ActionResponse implements ToXContentObject
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.created = in.readBoolean();
} }
@Override @Override

View File

@ -5,22 +5,17 @@
*/ */
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
/** /**
* This action is for setting the enabled flag on a native or reserved user * This action is for setting the enabled flag on a native or reserved user
*/ */
public class SetEnabledAction extends StreamableResponseActionType<SetEnabledResponse> { public class SetEnabledAction extends ActionType<SetEnabledResponse> {
public static final SetEnabledAction INSTANCE = new SetEnabledAction(); public static final SetEnabledAction INSTANCE = new SetEnabledAction();
public static final String NAME = "cluster:admin/xpack/security/user/set_enabled"; public static final String NAME = "cluster:admin/xpack/security/user/set_enabled";
private SetEnabledAction() { private SetEnabledAction() {
super(NAME); super(NAME, SetEnabledResponse::new);
}
@Override
public SetEnabledResponse newResponse() {
return new SetEnabledResponse();
} }
} }

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.core.security.action.user; package org.elasticsearch.xpack.core.security.action.user;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException; import java.io.IOException;
@ -14,6 +15,12 @@ import java.io.IOException;
* Empty response for a {@link SetEnabledRequest} * Empty response for a {@link SetEnabledRequest}
*/ */
public class SetEnabledResponse extends ActionResponse { public class SetEnabledResponse extends ActionResponse {
public SetEnabledResponse() {}
public SetEnabledResponse(StreamInput in) throws IOException {
super(in);
}
@Override @Override
public void writeTo(StreamOutput out) throws IOException {} public void writeTo(StreamOutput out) throws IOException {}
} }

View File

@ -23,8 +23,7 @@ public class DeletePrivilegesResponseTests extends ESTestCase {
final BytesStreamOutput output = new BytesStreamOutput(); final BytesStreamOutput output = new BytesStreamOutput();
original.writeTo(output); original.writeTo(output);
output.flush(); output.flush();
final DeletePrivilegesResponse copy = new DeletePrivilegesResponse(); final DeletePrivilegesResponse copy = new DeletePrivilegesResponse(output.bytes().streamInput());
copy.readFrom(output.bytes().streamInput());
assertThat(copy.found(), equalTo(original.found())); assertThat(copy.found(), equalTo(original.found()));
} }
} }

View File

@ -22,8 +22,7 @@ public class GetBuiltinPrivilegesResponseTests extends ESTestCase {
final BytesStreamOutput out = new BytesStreamOutput(); final BytesStreamOutput out = new BytesStreamOutput();
original.writeTo(out); original.writeTo(out);
final GetBuiltinPrivilegesResponse copy = new GetBuiltinPrivilegesResponse(); final GetBuiltinPrivilegesResponse copy = new GetBuiltinPrivilegesResponse(out.bytes().streamInput());
copy.readFrom(out.bytes().streamInput());
assertThat(copy.getClusterPrivileges(), Matchers.equalTo(cluster)); assertThat(copy.getClusterPrivileges(), Matchers.equalTo(cluster));
assertThat(copy.getIndexPrivileges(), Matchers.equalTo(index)); assertThat(copy.getIndexPrivileges(), Matchers.equalTo(index));

View File

@ -24,8 +24,7 @@ public class GetPrivilegesResponseTests extends ESTestCase {
final BytesStreamOutput out = new BytesStreamOutput(); final BytesStreamOutput out = new BytesStreamOutput();
original.writeTo(out); original.writeTo(out);
final GetPrivilegesResponse copy = new GetPrivilegesResponse(); final GetPrivilegesResponse copy = new GetPrivilegesResponse(out.bytes().streamInput());
copy.readFrom(out.bytes().streamInput());
assertThat(copy.privileges(), Matchers.equalTo(original.privileges())); assertThat(copy.privileges(), Matchers.equalTo(original.privileges()));
} }

View File

@ -33,8 +33,7 @@ public class PutPrivilegesResponseTests extends ESTestCase {
final BytesStreamOutput output = new BytesStreamOutput(); final BytesStreamOutput output = new BytesStreamOutput();
original.writeTo(output); original.writeTo(output);
output.flush(); output.flush();
final PutPrivilegesResponse copy = new PutPrivilegesResponse(); final PutPrivilegesResponse copy = new PutPrivilegesResponse(output.bytes().streamInput());
copy.readFrom(output.bytes().streamInput());
assertThat(copy.created(), equalTo(original.created())); assertThat(copy.created(), equalTo(original.created()));
assertThat(Strings.toString(copy), equalTo(Strings.toString(original))); assertThat(Strings.toString(copy), equalTo(Strings.toString(original)));
} }

View File

@ -20,8 +20,7 @@ public class CreateTokenResponseTests extends ESTestCase {
try (BytesStreamOutput output = new BytesStreamOutput()) { try (BytesStreamOutput output = new BytesStreamOutput()) {
response.writeTo(output); response.writeTo(output);
try (StreamInput input = output.bytes().streamInput()) { try (StreamInput input = output.bytes().streamInput()) {
CreateTokenResponse serialized = new CreateTokenResponse(); CreateTokenResponse serialized = new CreateTokenResponse(input);
serialized.readFrom(input);
assertEquals(response, serialized); assertEquals(response, serialized);
} }
} }
@ -31,8 +30,7 @@ public class CreateTokenResponseTests extends ESTestCase {
try (BytesStreamOutput output = new BytesStreamOutput()) { try (BytesStreamOutput output = new BytesStreamOutput()) {
response.writeTo(output); response.writeTo(output);
try (StreamInput input = output.bytes().streamInput()) { try (StreamInput input = output.bytes().streamInput()) {
CreateTokenResponse serialized = new CreateTokenResponse(); CreateTokenResponse serialized = new CreateTokenResponse(input);
serialized.readFrom(input);
assertEquals(response, serialized); assertEquals(response, serialized);
} }
} }
@ -47,8 +45,7 @@ public class CreateTokenResponseTests extends ESTestCase {
response.writeTo(output); response.writeTo(output);
try (StreamInput input = output.bytes().streamInput()) { try (StreamInput input = output.bytes().streamInput()) {
input.setVersion(version); input.setVersion(version);
CreateTokenResponse serialized = new CreateTokenResponse(); CreateTokenResponse serialized = new CreateTokenResponse(input);
serialized.readFrom(input);
assertNull(serialized.getRefreshToken()); assertNull(serialized.getRefreshToken());
assertEquals(response.getTokenString(), serialized.getTokenString()); assertEquals(response.getTokenString(), serialized.getTokenString());
assertEquals(response.getExpiresIn(), serialized.getExpiresIn()); assertEquals(response.getExpiresIn(), serialized.getExpiresIn());
@ -66,8 +63,7 @@ public class CreateTokenResponseTests extends ESTestCase {
response.writeTo(output); response.writeTo(output);
try (StreamInput input = output.bytes().streamInput()) { try (StreamInput input = output.bytes().streamInput()) {
input.setVersion(version); input.setVersion(version);
CreateTokenResponse serialized = new CreateTokenResponse(); CreateTokenResponse serialized = new CreateTokenResponse(input);
serialized.readFrom(input);
assertEquals(response, serialized); assertEquals(response, serialized);
} }
} }
@ -80,8 +76,7 @@ public class CreateTokenResponseTests extends ESTestCase {
response.writeTo(output); response.writeTo(output);
try (StreamInput input = output.bytes().streamInput()) { try (StreamInput input = output.bytes().streamInput()) {
input.setVersion(version); input.setVersion(version);
CreateTokenResponse serialized = new CreateTokenResponse(); CreateTokenResponse serialized = new CreateTokenResponse(input);
serialized.readFrom(input);
assertEquals("", serialized.getRefreshToken()); assertEquals("", serialized.getRefreshToken());
assertEquals(response.getTokenString(), serialized.getTokenString()); assertEquals(response.getTokenString(), serialized.getTokenString());
assertEquals(response.getExpiresIn(), serialized.getExpiresIn()); assertEquals(response.getExpiresIn(), serialized.getExpiresIn());

View File

@ -34,8 +34,7 @@ public class InvalidateTokenResponseTests extends ESTestCase {
try (BytesStreamOutput output = new BytesStreamOutput()) { try (BytesStreamOutput output = new BytesStreamOutput()) {
response.writeTo(output); response.writeTo(output);
try (StreamInput input = output.bytes().streamInput()) { try (StreamInput input = output.bytes().streamInput()) {
InvalidateTokenResponse serialized = new InvalidateTokenResponse(); InvalidateTokenResponse serialized = new InvalidateTokenResponse(input);
serialized.readFrom(input);
assertThat(serialized.getResult().getInvalidatedTokens(), equalTo(response.getResult().getInvalidatedTokens())); assertThat(serialized.getResult().getInvalidatedTokens(), equalTo(response.getResult().getInvalidatedTokens()));
assertThat(serialized.getResult().getPreviouslyInvalidatedTokens(), assertThat(serialized.getResult().getPreviouslyInvalidatedTokens(),
equalTo(response.getResult().getPreviouslyInvalidatedTokens())); equalTo(response.getResult().getPreviouslyInvalidatedTokens()));
@ -51,8 +50,7 @@ public class InvalidateTokenResponseTests extends ESTestCase {
try (BytesStreamOutput output = new BytesStreamOutput()) { try (BytesStreamOutput output = new BytesStreamOutput()) {
response.writeTo(output); response.writeTo(output);
try (StreamInput input = output.bytes().streamInput()) { try (StreamInput input = output.bytes().streamInput()) {
InvalidateTokenResponse serialized = new InvalidateTokenResponse(); InvalidateTokenResponse serialized = new InvalidateTokenResponse(input);
serialized.readFrom(input);
assertThat(serialized.getResult().getInvalidatedTokens(), equalTo(response.getResult().getInvalidatedTokens())); assertThat(serialized.getResult().getInvalidatedTokens(), equalTo(response.getResult().getInvalidatedTokens()));
assertThat(serialized.getResult().getPreviouslyInvalidatedTokens(), assertThat(serialized.getResult().getPreviouslyInvalidatedTokens(),
equalTo(response.getResult().getPreviouslyInvalidatedTokens())); equalTo(response.getResult().getPreviouslyInvalidatedTokens()));

View File

@ -48,10 +48,10 @@ public class GetUserPrivilegesResponseTests extends ESTestCase {
final BytesStreamOutput out = new BytesStreamOutput(); final BytesStreamOutput out = new BytesStreamOutput();
original.writeTo(out); original.writeTo(out);
final GetUserPrivilegesResponse copy = new GetUserPrivilegesResponse();
final NamedWriteableRegistry registry = new NamedWriteableRegistry(new XPackClientPlugin(Settings.EMPTY).getNamedWriteables()); final NamedWriteableRegistry registry = new NamedWriteableRegistry(new XPackClientPlugin(Settings.EMPTY).getNamedWriteables());
StreamInput in = new NamedWriteableAwareStreamInput(ByteBufferStreamInput.wrap(BytesReference.toBytes(out.bytes())), registry); StreamInput in = new NamedWriteableAwareStreamInput(ByteBufferStreamInput.wrap(BytesReference.toBytes(out.bytes())), registry);
copy.readFrom(in); final GetUserPrivilegesResponse copy = new GetUserPrivilegesResponse(in);
assertThat(copy.getClusterPrivileges(), equalTo(original.getClusterPrivileges())); assertThat(copy.getClusterPrivileges(), equalTo(original.getClusterPrivileges()));
assertThat(copy.getConditionalClusterPrivileges(), equalTo(original.getConditionalClusterPrivileges())); assertThat(copy.getConditionalClusterPrivileges(), equalTo(original.getConditionalClusterPrivileges()));

View File

@ -112,7 +112,7 @@ public final class TransportSamlLogoutAction
final String session = getMetadataString(tokenMetadata, SamlRealm.TOKEN_METADATA_SESSION); final String session = getMetadataString(tokenMetadata, SamlRealm.TOKEN_METADATA_SESSION);
final LogoutRequest logout = realm.buildLogoutRequest(nameId.asXml(), session); final LogoutRequest logout = realm.buildLogoutRequest(nameId.asXml(), session);
if (logout == null) { if (logout == null) {
return new SamlLogoutResponse(null); return new SamlLogoutResponse((String)null);
} }
final String uri = new SamlRedirect(logout, realm.getSigningConfiguration()).getRedirectUrl(); final String uri = new SamlRedirect(logout, realm.getSigningConfiguration()).getRedirectUrl();
return new SamlLogoutResponse(uri); return new SamlLogoutResponse(uri);