Skip to content

Commit 3914a98

Browse files
authored
Security: remove wrapping in put user response (#33512)
This change removes the wrapping of the created field in the put user response. The created field was added as a top level field in #32332, while also still being wrapped within the `user` object of the response. Since the value is available in both formats in 6.x, we can remove the wrapped version for 7.0.
1 parent 7dd22f0 commit 3914a98

File tree

10 files changed

+20
-20
lines changed

10 files changed

+20
-20
lines changed

docs/reference/migration/migrate_7_0/api.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ depending on whether {security} is enabled. Previously a
8787
404 - NOT FOUND (IndexNotFoundException) could be returned in case the
8888
current user was not authorized for any alias. An empty response with
8989
status 200 - OK is now returned instead at all times.
90+
91+
==== Put User API response no longer has `user` object
92+
93+
The Put User API response was changed in 6.5.0 to add the `created` field
94+
outside of the user object where it previously had been. In 7.0.0 the user
95+
object has been removed in favor of the top level `created` field.

x-pack/docs/en/rest-api/security/create-users.asciidoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ created or updated.
9090
[source,js]
9191
--------------------------------------------------
9292
{
93-
"user": {
94-
"created" : true
95-
},
9693
"created": true <1>
9794
}
9895
--------------------------------------------------

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.elasticsearch.action.ActionResponse;
1010
import org.elasticsearch.common.io.stream.StreamInput;
1111
import org.elasticsearch.common.io.stream.StreamOutput;
12-
import org.elasticsearch.common.xcontent.ToXContentFragment;
12+
import org.elasticsearch.common.xcontent.ToXContentObject;
1313
import org.elasticsearch.common.xcontent.XContentBuilder;
1414

1515
import java.io.IOException;
@@ -18,7 +18,7 @@
1818
* Response when adding a user to the security index. Returns a
1919
* single boolean field for whether the user was created or updated.
2020
*/
21-
public class PutUserResponse extends ActionResponse implements ToXContentFragment {
21+
public class PutUserResponse extends ActionResponse implements ToXContentObject {
2222

2323
private boolean created;
2424

@@ -47,6 +47,8 @@ public void readFrom(StreamInput in) throws IOException {
4747

4848
@Override
4949
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
50-
return builder.field("created", created);
50+
return builder.startObject()
51+
.field("created", created)
52+
.endObject();
5153
}
5254
}

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,8 @@ public RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient c
5858
return channel -> requestBuilder.execute(new RestBuilderListener<PutUserResponse>(channel) {
5959
@Override
6060
public RestResponse buildResponse(PutUserResponse putUserResponse, XContentBuilder builder) throws Exception {
61-
builder.startObject()
62-
.startObject("user"); // TODO in 7.0 remove wrapping of response in the user object and just return the object
6361
putUserResponse.toXContent(builder, request);
64-
builder.endObject();
65-
66-
putUserResponse.toXContent(builder, request);
67-
return new BytesRestResponse(RestStatus.OK, builder.endObject());
62+
return new BytesRestResponse(RestStatus.OK, builder);
6863
}
6964
});
7065
}

x-pack/plugin/src/test/resources/rest-api-spec/test/roles/11_idx_arrays.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ teardown:
5151
"password": "s3krit",
5252
"roles" : [ "admin_role2" ]
5353
}
54-
- match: { user: { created: true } }
54+
- match: { created: true }
5555

5656
- do:
5757
index:

x-pack/plugin/src/test/resources/rest-api-spec/test/users/10_basic.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ teardown:
3030
"key2" : "val2"
3131
}
3232
}
33-
- match: { user: { created: true } }
33+
- match: { created: true }
3434

3535
- do:
3636
headers:
@@ -65,7 +65,7 @@ teardown:
6565
"key2" : "val2"
6666
}
6767
}
68-
- match: { user: { created: true } }
68+
- match: { created: true }
6969

7070
- do:
7171
headers:

x-pack/plugin/src/test/resources/rest-api-spec/test/users/15_overwrite_user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ teardown:
5151
"key2" : "val2"
5252
}
5353
}
54-
- match: { user: { created: false } }
54+
- match: { created: false }
5555

5656
- do:
5757
xpack.security.get_user:

x-pack/plugin/src/test/resources/rest-api-spec/test/users/16_update_user.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ teardown:
6666
"key2" : "val2"
6767
}
6868
}
69-
- match: { user: { created: false } }
69+
- match: { created: false }
7070

7171
# validate existing password works
7272
- do:
@@ -103,7 +103,7 @@ teardown:
103103
"key3" : "val3"
104104
}
105105
}
106-
- match: { user: { created: false } }
106+
- match: { created: false }
107107

108108
# validate old password doesn't work
109109
- do:

x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/remote_cluster/10_basic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,4 @@ setup:
195195
"password": "s3krit",
196196
"roles" : [ ]
197197
}
198-
- match: { user: { created: false } }
198+
- match: { created: false }

x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/20_security.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"password" : "x-pack-test-password",
1010
"roles" : [ "native_role" ]
1111
}
12-
- match: { user: { created: true } }
12+
- match: { created: true }
1313

1414
- do:
1515
xpack.security.put_role:

0 commit comments

Comments
 (0)