-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[HLRC] Put Role #36209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
albertzaharovits
merged 27 commits into
elastic:master
from
albertzaharovits:hlrc_put_role_2
Dec 10, 2018
Merged
[HLRC] Put Role #36209
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2999459
Put Role request
albertzaharovits 53ad4bb
RequestConvertTests
albertzaharovits 862bdcd
Merge branch 'master' into hlrc_put_role_2
albertzaharovits 345838a
Remove Transient metadata from the Role builder
albertzaharovits e55ee55
Revert "Remove Transient metadata from the Role builder"
albertzaharovits c918ca3
Merge branch 'master' into hlrc_put_role_2
albertzaharovits d085ef7
Put Role security client and request
albertzaharovits 9707795
Transient metadata
albertzaharovits d087f98
SecurityDocumentationIT
albertzaharovits fcbaad3
IndicesPrivilegesTests
albertzaharovits e09be47
PutRoleRequestTests
albertzaharovits 8c8cf33
SecurityIT in progress
albertzaharovits ff5d788
transient metadata no longer public
albertzaharovits e273930
Almost there!
albertzaharovits 86941b5
And docs
albertzaharovits fa48020
Trimming
albertzaharovits 730f835
Unsaved trimming
albertzaharovits f1f0550
Merge branch 'master' into hlrc_put_role_2
albertzaharovits 302f62b
Review
albertzaharovits 8234a2f
Merge branch 'master' into hlrc_put_role_2
albertzaharovits 0499df0
Pull transient metadata out of Role
albertzaharovits 6ae513e
Minor left over
albertzaharovits e65f81a
supported-apis
albertzaharovits 0137e25
Checkstyle
albertzaharovits e798779
Merge branch 'master' into hlrc_put_role_2
albertzaharovits 4c94995
Merge branch 'master' into hlrc_put_role_2
albertzaharovits 6699ad3
Checkstyle
albertzaharovits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
client/rest-high-level/src/main/java/org/elasticsearch/client/security/PutRoleRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.security; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.client.security.user.privileges.Role; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Request object to create or update a role. | ||
*/ | ||
public final class PutRoleRequest implements Validatable, ToXContentObject { | ||
|
||
private final Role role; | ||
private final RefreshPolicy refreshPolicy; | ||
|
||
public PutRoleRequest(Role role, @Nullable final RefreshPolicy refreshPolicy) { | ||
this.role = Objects.requireNonNull(role); | ||
this.refreshPolicy = (refreshPolicy == null) ? RefreshPolicy.getDefault() : refreshPolicy; | ||
} | ||
|
||
public Role getRole() { | ||
return role; | ||
} | ||
|
||
public RefreshPolicy getRefreshPolicy() { | ||
return refreshPolicy; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(role, refreshPolicy); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final PutRoleRequest other = (PutRoleRequest) obj; | ||
|
||
return (refreshPolicy == other.getRefreshPolicy()) && | ||
Objects.equals(role, other.role); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
if (role.getApplicationResourcePrivileges() != null) { | ||
builder.field(Role.APPLICATIONS.getPreferredName(), role.getApplicationResourcePrivileges()); | ||
} | ||
if (role.getClusterPrivileges() != null) { | ||
builder.field(Role.CLUSTER.getPreferredName(), role.getClusterPrivileges()); | ||
} | ||
if (role.getGlobalApplicationPrivileges() != null) { | ||
builder.field(Role.GLOBAL.getPreferredName(), role.getGlobalApplicationPrivileges()); | ||
} | ||
if (role.getIndicesPrivileges() != null) { | ||
builder.field(Role.INDICES.getPreferredName(), role.getIndicesPrivileges()); | ||
} | ||
if (role.getMetadata() != null) { | ||
builder.field(Role.METADATA.getPreferredName(), role.getMetadata()); | ||
} | ||
if (role.getRunAsPrivilege() != null) { | ||
builder.field(Role.RUN_AS.getPreferredName(), role.getRunAsPrivilege()); | ||
} | ||
return builder.endObject(); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
client/rest-high-level/src/main/java/org/elasticsearch/client/security/PutRoleResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.security; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentParser.Token; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureFieldName; | ||
|
||
/** | ||
* Response when adding a role to the native roles store. Returns a | ||
* single boolean field for whether the role was created (true) or updated (false). | ||
*/ | ||
public final class PutRoleResponse { | ||
|
||
private final boolean created; | ||
|
||
public PutRoleResponse(boolean created) { | ||
this.created = created; | ||
} | ||
|
||
public boolean isCreated() { | ||
return created; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
PutRoleResponse that = (PutRoleResponse) o; | ||
return created == that.created; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(created); | ||
} | ||
|
||
private static final ConstructingObjectParser<PutRoleResponse, Void> PARSER = new ConstructingObjectParser<>("put_role_response", | ||
true, args -> new PutRoleResponse((boolean) args[0])); | ||
|
||
static { | ||
PARSER.declareBoolean(constructorArg(), new ParseField("created")); | ||
} | ||
|
||
public static PutRoleResponse fromXContent(XContentParser parser) throws IOException { | ||
if (parser.currentToken() == null) { | ||
parser.nextToken(); | ||
} | ||
// parse extraneous wrapper | ||
ensureExpectedToken(Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation); | ||
ensureFieldName(parser, parser.nextToken(), "role"); | ||
parser.nextToken(); | ||
final PutRoleResponse roleResponse = PARSER.parse(parser, null); | ||
ensureExpectedToken(Token.END_OBJECT, parser.nextToken(), parser::getTokenLocation); | ||
return roleResponse; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the previous condition was correctly from the server logic stand point, it would hinder testing in
IndicesPrivilegesTests
.