-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
HLRC: add change password API support #33509
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ebc99c9
WIP
jkakavas 397a019
Merge remote-tracking branch 'origin/master' into change-password-hlrc
jkakavas 931ec38
Complete the implementation
jkakavas 168fe4f
undo whitespace changes
jkakavas 54830e8
Address feedback
jkakavas dcb091d
Username should not be part of the request body
jkakavas b2bbed7
Merge remote-tracking branch 'origin/master' into change-password-hlrc
jkakavas 2d45731
Remove unused imports
jkakavas 6c19675
Merge remote-tracking branch 'origin/master' into change-password-hlrc
jkakavas e5404d0
Address feedback
jkakavas 7578bd1
Merge remote-tracking branch 'origin/master' into change-password-hlrc
jkakavas 5eaaa42
address feedback
jkakavas 1cbd8a7
address feedback
jkakavas 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 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 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 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
76 changes: 76 additions & 0 deletions
76
...est-high-level/src/main/java/org/elasticsearch/client/security/ChangePasswordRequest.java
This file contains 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,76 @@ | ||
/* | ||
* 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.common.CharArrays; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Request object to change the password of a user of a native realm or a built-in user. | ||
*/ | ||
public final class ChangePasswordRequest implements Validatable, ToXContentObject { | ||
|
||
private final String username; | ||
private final char[] password; | ||
private final RefreshPolicy refreshPolicy; | ||
|
||
/** | ||
* @param username The username of the user whose password should be changed or null for the current user. | ||
* @param password The new password. The password array is not cleared by the {@link ChangePasswordRequest} object so the | ||
* calling code must clear it after receiving the response. | ||
* @param refreshPolicy The refresh policy for the request. | ||
*/ | ||
public ChangePasswordRequest(@Nullable String username, char[] password, RefreshPolicy refreshPolicy) { | ||
this.username = username; | ||
this.password = Objects.requireNonNull(password, "password is required"); | ||
this.refreshPolicy = refreshPolicy == null ? RefreshPolicy.getDefault() : refreshPolicy; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public char[] getPassword() { | ||
return password; | ||
} | ||
|
||
public RefreshPolicy getRefreshPolicy() { | ||
return refreshPolicy; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
byte[] charBytes = CharArrays.toUtf8Bytes(password); | ||
try { | ||
return builder.startObject() | ||
.field("password").utf8Value(charBytes, 0, charBytes.length) | ||
.endObject(); | ||
} finally { | ||
Arrays.fill(charBytes, (byte) 0); | ||
} | ||
} | ||
jaymode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains 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.
nit: remove extra new line