-
Notifications
You must be signed in to change notification settings - Fork 245
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
[JENKINS-44860] UsernameCredentials.isUsernameSecret
#205
Changes from all commits
09a8622
6c8d6b6
a2b5c5f
5c62332
f2df059
4f2aa3d
ba505d7
3fce07b
cc3d3b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,11 @@ Result name(@NonNull Credentials credentials, @NonNull Class<?> clazz) { | |
if (nameWith != null) { | ||
try { | ||
CredentialsNameProvider nameProvider = nameWith.value().newInstance(); | ||
return new Result(nameProvider.getName(credentials), nameWith.priority()); | ||
String name = nameProvider.getName(credentials); | ||
if (!name.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make it possible to just |
||
LOGGER.fine(() -> "named `" + name + "` from " + nameProvider); | ||
return new Result(name, nameWith.priority()); | ||
} | ||
} catch (ClassCastException | InstantiationException | IllegalAccessException e) { | ||
// ignore | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,12 @@ | |
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials; | ||
import edu.umd.cs.findbugs.annotations.CheckForNull; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.Nullable; | ||
import hudson.Extension; | ||
import hudson.Util; | ||
import hudson.util.Secret; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
/** | ||
* Concrete implementation of {@link StandardUsernamePasswordCredentials}. | ||
|
@@ -53,6 +55,9 @@ public class UsernamePasswordCredentialsImpl extends BaseStandardCredentials imp | |
@NonNull | ||
private final Secret password; | ||
|
||
@Nullable | ||
private Boolean usernameSecret = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default false in the Java constructor which would be used only from tests or scripts. |
||
|
||
/** | ||
* Constructor. | ||
* | ||
|
@@ -72,6 +77,13 @@ public UsernamePasswordCredentialsImpl(@CheckForNull CredentialsScope scope, | |
this.password = Secret.fromString(password); | ||
} | ||
|
||
private Object readResolve() { | ||
if (usernameSecret == null) { | ||
usernameSecret = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default true for deserialized credentials, either from settings predating the upgrade, or REST uploads as XML. |
||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
@@ -88,6 +100,16 @@ public String getUsername() { | |
return username; | ||
} | ||
|
||
@Override | ||
public boolean isUsernameSecret() { | ||
return usernameSecret; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setUsernameSecret(boolean usernameSecret) { | ||
this.usernameSecret = usernameSecret; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ | |
<f:entry title="${%Username}" field="username"> | ||
<f:textbox/> | ||
</f:entry> | ||
<f:entry field="usernameSecret"> | ||
<f:checkbox title="${%Treat username as secret}"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default false for new credentials created from the GUI. |
||
</f:entry> | ||
<f:entry title="${%Password}" field="password"> | ||
<f:password/> | ||
</f:entry> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div> | ||
Historically, not only passwords but usernames were masked in the build log. | ||
Since these can interfere with diagnostics, | ||
and cause unrelated occurrences of a common word to be masked, | ||
you may choose to leave usernames unmasked if they are not sensitive. | ||
Note that regardless of this setting, the username will be displayed to anyone permitted to reconfigure the credentials. | ||
</div> |
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.
Just proposing a version bump. Do we really need to keep the micro version? Can revert if desired.