GP-0 revised SystemUtilities.getUserName() to eliminate Domain Name

This commit is contained in:
ghidra1 2023-08-17 11:02:40 -04:00
parent 96b61753a0
commit f64c38ef7f
2 changed files with 18 additions and 16 deletions

View file

@ -171,13 +171,7 @@ public class ClientUtil {
* @return default user name * @return default user name
*/ */
public static String getUserName() { public static String getUserName() {
String name = SystemUtilities.getUserName(); return SystemUtilities.getUserName();
// exclude domain prefix which may be included
int slashIndex = name.lastIndexOf('\\');
if (slashIndex >= 0) {
name = name.substring(slashIndex + 1);
}
return name;
} }
/** /**
@ -446,8 +440,8 @@ public class ClientUtil {
static void processSignatureCallback(String serverName, SignatureCallback sigCb) static void processSignatureCallback(String serverName, SignatureCallback sigCb)
throws IOException { throws IOException {
try { try {
SignedToken signedToken = ApplicationKeyManagerUtils.getSignedToken( SignedToken signedToken = ApplicationKeyManagerUtils
sigCb.getRecognizedAuthorities(), sigCb.getToken()); .getSignedToken(sigCb.getRecognizedAuthorities(), sigCb.getToken());
sigCb.sign(signedToken.certChain, signedToken.signature); sigCb.sign(signedToken.certChain, signedToken.signature);
Msg.info(ClientUtil.class, "PKI Authenticating to " + serverName + " as user '" + Msg.info(ClientUtil.class, "PKI Authenticating to " + serverName + " as user '" +
signedToken.certChain[0].getSubjectX500Principal() + "'"); signedToken.certChain[0].getSubjectX500Principal() + "'");

View file

@ -91,7 +91,7 @@ public class SystemUtilities {
if (url.getPath().contains("/build/libs")) { if (url.getPath().contains("/build/libs")) {
return true; // Source repository Gradle JavaExec task mode return true; // Source repository Gradle JavaExec task mode
} }
return switch(url.getProtocol()) { return switch (url.getProtocol()) {
case "file" -> true; // Eclipse run config mode (class files) case "file" -> true; // Eclipse run config mode (class files)
case "jar" -> false; // Release mode (jar files) case "jar" -> false; // Release mode (jar files)
case "bundleresource" -> false; // GhidraDev Utility.jar access mode case "bundleresource" -> false; // GhidraDev Utility.jar access mode
@ -100,25 +100,33 @@ public class SystemUtilities {
} }
/** /**
* Get the user that is running the ghidra application * Get the user that is running the ghidra application. This name may be modified to
* eliminate any spaces or leading domain name which may be present in Java's
* {@code user.name} system property.
* @return the user name * @return the user name
*/ */
public static String getUserName() { public static String getUserName() {
if (userName == null) { if (userName == null) {
String uname = System.getProperty("user.name"); String uname = System.getProperty("user.name");
// remove the spaces since some operating systems allow // Remove the spaces since some operating systems allow
// spaces and some do not, Java's File class doesn't // spaces and some do not, Java's File class doesn't
StringBuilder nameBuf = new StringBuilder();
if (uname.indexOf(" ") >= 0) { if (uname.indexOf(" ") >= 0) {
userName = "";
StringTokenizer tokens = new StringTokenizer(uname, " ", false); StringTokenizer tokens = new StringTokenizer(uname, " ", false);
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {
userName += tokens.nextToken(); nameBuf.append(tokens.nextToken());
} }
uname = nameBuf.toString();
} }
else {
userName = uname; // Remove leading Domain Name if present
int slashIndex = uname.lastIndexOf('\\');
if (slashIndex >= 0) {
uname = uname.substring(slashIndex + 1);
} }
userName = uname;
} }
return userName; return userName;
} }