How can I get username / login in Java?
This is the code I tried ...
try{ LoginContext lc = new LoginContext(appName,new TextCallbackHandler()); lc.login(); Subject subject = lc.getSubject(); Principal principals[] = (Principal[])subject.getPrincipals().toArray(new Principal[0]); for (int i=0; i<principals.length; i++) { if (principals[i] instanceof NTUserPrincipal || principals[i] instanceof UnixPrincipal) { String loggedInUserName = principals[i].getName(); } } } catch(SecurityException se){ System.out.println("SecurityException: " + se.getMessage()); }
I get a SecurityException when I try to run this code. Can someone please tell me if I'm heading in the right direction and help me understand the problem.
java username
George Profenza Apr 28 '09 at 12:08 2009-04-28 12:08
source share