2009-09-10 5 views

답변

0

System.properties을 덤프하면 user.name이라는 속성을 찾을 수 있습니다. JDK 프로세스를 시작한 OS 사용자가 어느 정도는되어야합니다.

여기 당신은 아마도 어떤 유형의 인증을 작업중인 서버의 유형을 추가해야

Properties props = System.getProperties(); 
Enumeration e = props.propertyNames(); 
while(e.hasMoreElements()){ 
    Object key = e.nextElement(); 
    Object val = props.getProperty(key.toString()); 
    System.out.println("key:"+ key +" val:"+ val); 
} 
0

이것은 플랫폼에 따라 다릅니다. 어떤 유형의 서버에 대해 이야기하고 있습니까?

여기에는 응용 프로그램을 실행중인 사용자의 이름이 표시됩니다. 나는이 사이트에 따르면 http://www.exampledepot.com/egs/javax.security.auth.login/GetLogin.html

try { 
    String loginAppName = "GetLoginNameUnix"; 

    // If the application is run on NT rather than Unix, use this name 
    loginAppName = "GetLoginNameNT"; 

    // Create login context 
    LoginContext lc = new LoginContext(loginAppName, 
     new com.sun.security.auth.callback.TextCallbackHandler()); 

    // Retrieve the information on the logged-in user 
    lc.login(); 

    // Get the authenticated subject 
    Subject subject = lc.getSubject(); 

    // Get the subject principals 
    Principal principals[] = (Principal[])subject.getPrincipals().toArray(new Principal[0]); 
    for (int i=0; i<principals.length; i++) { 
     if (principals[i] instanceof com.sun.security.auth.NTUserPrincipal 
       || principals[i] instanceof com.sun.security.auth.UnixPrincipal) { 
      String loggedInUserName = principals[i].getName(); 
     } 
    } 
} catch (LoginException e) { 
    // Login failed 
} 

에이 코드 조각을 발견했습니다, 당신은 모듈이로드되는 구성이 필요합니다.

String login = System.getProperty("user.name"); 

을하지만, 보안 관리자 (애플릿에서 호출 할 때, 예를 들어)이되지 않을 수 있습니다 :

2

당신은 환경에서 찾을 수 있습니다!

관련 문제