Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,30 @@
import org.jetbrains.annotations.NotNull;

/**
* TODO: Javadocs
* Utility methods for safely representing {@link AuthConfig} objects as strings.
* <p>
* This class masks sensitive authentication information such as passwords,
* authentication tokens, and registry tokens before including them in the
* returned string. It is intended for logging and debugging purposes where
* exposing secrets would be a security risk.
*/
@UtilityClass
public class AuthConfigUtil {

/**
* Returns a safe string representation of the given {@link AuthConfig}.
* <p>
* Sensitive fields including the password, authentication value, and
* registry token are replaced with an obfuscated placeholder, while
* non-sensitive fields such as the username, email, and registry address
* are included in the output. If the supplied configuration is
* {@code null}, the string {@code "null"} is returned.
*
* @param authConfig the authentication configuration to represent safely;
* may be {@code null}
* @return a string representation with sensitive values hidden, or
* {@code "null"} if {@code authConfig} is {@code null}
*/
public static String toSafeString(AuthConfig authConfig) {
if (authConfig == null) {
return "null";
Expand All @@ -28,6 +47,17 @@ public static String toSafeString(AuthConfig authConfig) {
.toString();
}

/**
* Returns an obfuscated representation of a potentially sensitive value.
* <p>
* If the value is {@code null} or empty, the string {@code "blank"} is
* returned. Otherwise, the actual value is concealed by returning
* {@code "hidden non-blank value"}.
*
* @param value the value to obfuscate
* @return {@code "blank"} if the value is null or empty; otherwise
* {@code "hidden non-blank value"}
*/
@NotNull
private static String obfuscated(String value) {
return Strings.isNullOrEmpty(value) ? "blank" : "hidden non-blank value";
Expand Down