X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FOsUserUtils.java;fp=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FOsUserUtils.java;h=0000000000000000000000000000000000000000;hb=9f729eeb8255a9d800ad2506735dda8cc215a135;hp=ad6bf881653aabd565e1f16abfc99b69ea621f42;hpb=f9efbe5228615951dd8482a4582aa24e00c10ce5;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/OsUserUtils.java b/org.argeo.enterprise/src/org/argeo/osgi/useradmin/OsUserUtils.java deleted file mode 100644 index ad6bf8816..000000000 --- a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/OsUserUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.argeo.osgi.useradmin; - -import java.net.URISyntaxException; -import java.net.URL; -import java.security.NoSuchAlgorithmException; -import java.security.URIParameter; - -import javax.security.auth.Subject; -import javax.security.auth.login.Configuration; -import javax.security.auth.login.LoginContext; -import javax.security.auth.login.LoginException; - -public class OsUserUtils { - private static String LOGIN_CONTEXT_USER_NIX = "USER_NIX"; - private static String LOGIN_CONTEXT_USER_NT = "USER_NT"; - - public static String getOsUsername() { - return System.getProperty("user.name"); - } - - public static LoginContext loginAsSystemUser(Subject subject) { - try { - URL jaasConfigurationUrl = OsUserUtils.class.getClassLoader() - .getResource("org/argeo/osgi/useradmin/jaas-os.cfg"); - URIParameter uriParameter = new URIParameter(jaasConfigurationUrl.toURI()); - Configuration jaasConfiguration = Configuration.getInstance("JavaLoginConfig", uriParameter); - LoginContext lc = new LoginContext(isWindows() ? LOGIN_CONTEXT_USER_NT : LOGIN_CONTEXT_USER_NIX, subject, - null, jaasConfiguration); - lc.login(); - return lc; - } catch (URISyntaxException | NoSuchAlgorithmException | LoginException e) { - throw new RuntimeException("Cannot login as system user", e); - } - } - - public static void main(String args[]) { - Subject subject = new Subject(); - LoginContext loginContext = loginAsSystemUser(subject); - System.out.println(subject); - try { - loginContext.logout(); - } catch (LoginException e) { - // silent - } - } - - private static boolean isWindows() { - return System.getProperty("os.name").startsWith("Windows"); - } - - private OsUserUtils() { - } -}