-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Create/Update role mapping API #34171
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
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
231a018
Create/Update role mapping API
8aa1db5
review
8f9ec11
review
c568146
Address review comments
7c0ace3
Merge branch 'master' into create-role-mapping-hl-api
7654961
Address review comments
998f28a
Address review comments
e83fbb5
Merge branch 'master' into create-role-mapping-hl-api
4f78586
Merge branch 'master' into create-role-mapping-hl-api
06944f4
Add comment on how the parser ignores the role_mapping field
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
124 changes: 124 additions & 0 deletions
124
...est-high-level/src/main/java/org/elasticsearch/client/security/PutRoleMappingRequest.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,124 @@ | ||
| /* | ||
| * 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.support.expressiondsl.RoleMapperExpression; | ||
| import org.elasticsearch.common.Nullable; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Request object to create or update a role mapping. | ||
| */ | ||
| public final class PutRoleMappingRequest implements Validatable, ToXContentObject { | ||
|
|
||
| private final String name; | ||
| private final boolean enabled; | ||
| private final List<String> roles; | ||
| private final RoleMapperExpression rules; | ||
|
|
||
| private final Map<String, Object> metadata; | ||
| private final RefreshPolicy refreshPolicy; | ||
|
|
||
| public PutRoleMappingRequest(final String name, final boolean enabled, final List<String> roles, final RoleMapperExpression rules, | ||
| @Nullable final Map<String, Object> metadata, @Nullable final RefreshPolicy refreshPolicy) { | ||
| if (Strings.hasText(name) == false) { | ||
| throw new IllegalArgumentException("role-mapping name is missing"); | ||
| } | ||
| this.name = name; | ||
| this.enabled = enabled; | ||
| if (roles == null || roles.isEmpty()) { | ||
| throw new IllegalArgumentException("role-mapping roles are missing"); | ||
| } | ||
| this.roles = Collections.unmodifiableList(roles); | ||
| this.rules = Objects.requireNonNull(rules, "role-mapping rules are missing"); | ||
| this.metadata = (metadata == null) ? Collections.emptyMap() : metadata; | ||
| this.refreshPolicy = (refreshPolicy == null) ? RefreshPolicy.getDefault() : refreshPolicy; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public List<String> getRoles() { | ||
| return roles; | ||
| } | ||
|
|
||
| public RoleMapperExpression getRules() { | ||
| return rules; | ||
| } | ||
|
|
||
| public Map<String, Object> getMetadata() { | ||
| return metadata; | ||
| } | ||
|
|
||
| public RefreshPolicy getRefreshPolicy() { | ||
| return refreshPolicy; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(name, enabled, refreshPolicy, roles, rules, metadata); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null) { | ||
| return false; | ||
| } | ||
| if (getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| final PutRoleMappingRequest other = (PutRoleMappingRequest) obj; | ||
|
|
||
| return (enabled == other.enabled) && | ||
| (refreshPolicy == other.refreshPolicy) && | ||
| Objects.equals(name, other.name) && | ||
| Objects.equals(roles, other.roles) && | ||
| Objects.equals(rules, other.rules) && | ||
| Objects.equals(metadata, other.metadata); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field("enabled", enabled); | ||
| builder.field("roles", roles); | ||
| builder.field("rules", rules); | ||
| builder.field("metadata", metadata); | ||
| return builder.endObject(); | ||
| } | ||
|
|
||
| } |
74 changes: 74 additions & 0 deletions
74
...st-high-level/src/main/java/org/elasticsearch/client/security/PutRoleMappingResponse.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,74 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
|
||
| /** | ||
| * Response when adding/updating a role mapping. Returns a boolean field for | ||
| * whether the role mapping was created or updated. | ||
| */ | ||
| public final class PutRoleMappingResponse { | ||
|
|
||
| private final boolean created; | ||
|
|
||
| public PutRoleMappingResponse(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; | ||
| } | ||
| final PutRoleMappingResponse that = (PutRoleMappingResponse) o; | ||
| return created == that.created; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(created); | ||
| } | ||
|
|
||
| private static final ConstructingObjectParser<PutRoleMappingResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
| "put_role_mapping_response", true, args -> new PutRoleMappingResponse((boolean) args[0])); | ||
| static { | ||
| PARSER.declareBoolean(constructorArg(), new ParseField("created")); | ||
| PARSER.declareObject((a,b) -> {}, (parser, context) -> null, new ParseField("role_mapping")); // ignore the role_mapping field! | ||
| } | ||
|
|
||
| public static PutRoleMappingResponse fromXContent(XContentParser parser) throws IOException { | ||
| return PARSER.parse(parser, null); | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.