Commit 313b3d71 authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Move the getUserId method in UserFactory

parent 3bde1647
......@@ -17,6 +17,7 @@ import alien.config.JAliEnIAm;
import alien.shell.BusyBox;
import alien.shell.ShellColor;
import alien.shell.commands.JAliEnBaseCommand;
import alien.user.UserFactory;
import lazyj.commands.CommandOutput;
import lazyj.commands.SystemCommand;
import lia.util.process.ExternalProcess.ExitStatus;
......@@ -169,7 +170,7 @@ public class JSh {
Process p;
try {
p = Runtime.getRuntime().exec(new String[] { "java", "-Duserid=" + JBoxServer.getUserID(), "-DAliEnConfig=" + System.getProperty("AliEnConfig"), "-server",
p = Runtime.getRuntime().exec(new String[] { "java", "-Duserid=" + UserFactory.getUserID(), "-DAliEnConfig=" + System.getProperty("AliEnConfig"), "-server",
"-Djava.io.tmpdir=" + System.getProperty("java.io.tmpdir"), "alien.JBox" });
} catch (final IOException ioe) {
......@@ -331,7 +332,7 @@ public class JSh {
private static boolean getJBoxPID() {
final File f = new File(new File(System.getProperty("java.io.tmpdir")), "jclient_token_" + JBoxServer.getUserID());
final File f = new File(new File(System.getProperty("java.io.tmpdir")), "jclient_token_" + UserFactory.getUserID());
if (f.exists()) {
final byte[] buffer = new byte[(int) f.length()];
......
......@@ -159,8 +159,8 @@ public class TomcatServer {
final String keystorePass = new String(JAKeyStore.pass);
final String dirName = System.getProperty("java.io.tmpdir") + File.separator;
final String keystoreName = dirName + "keystore.jks_" + JBoxServer.getUserID();
final String truststoreName = dirName + "truststore.jks_" + JBoxServer.getUserID();
final String keystoreName = dirName + "keystore.jks_" + UserFactory.getUserID();
final String truststoreName = dirName + "truststore.jks_" + UserFactory.getUserID();
if (ConfigUtils.isCentralService())
JAKeyStore.saveKeyStore(JAKeyStore.getKeyStore(), keystoreName, JAKeyStore.pass);
......
......@@ -8,6 +8,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import alien.config.ConfigUtils;
import lazyj.commands.SystemCommand;
/**
* @author costing
......@@ -254,4 +255,23 @@ public final class UserFactory {
return null;
}
/**
* @return current user's ID, if it can be retrieved from the system
*/
public static String getUserID() {
String sUserId = System.getProperty("userid");
if (sUserId == null || sUserId.length() == 0) {
sUserId = SystemCommand.bash("id -u " + System.getProperty("user.name")).stdout;
if (sUserId != null && sUserId.length() > 0)
System.setProperty("userid", sUserId);
}
if (sUserId != null && sUserId.length() > 0)
return sUserId;
return null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment