Comment puis-je obtenir le nom d'utilisateur / nom de connexion en Java?
C'est le code que j'ai essayé ...
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());
}J'obtiens un SecurityExceptionlorsque j'essaye d'exécuter ce code. Quelqu'un pourrait-il me dire si je vais dans la bonne direction et m'aider à comprendre le problème.