2016-07-26 176 views
0

我想查詢針對Active Directory用戶憑據沒有進入他的身份憑證。即用戶登錄到自己的企業系統(Intranetwork)我需要使用這些證書來驗證對AD和該用戶是否存在找回了自己的電子郵件地址。(NO單點登錄所需)查詢Active Directory

回答

1

當然,這是爲時已晚回答,但是......像我這樣可以搜索相同的答案......

我只是不知道爲什麼你需要驗證用戶憑據? 如果用戶已經登錄,則驗證憑證。

獲得他的電子郵件(和AD等信息)通過使用Windows PowerShell是可能的。

public class TestWindowsAD { 

public static void main(String... args) throws Exception { 

    System.out.println("Current user e-mail: " + getCurrentUserEmail()); 

} 

private static String getCurrentUserEmail() { 

    String cmd = "powershell \"Add-Type -AssemblyName System.DirectoryServices.AccountManagement;[System.DirectoryServices.AccountManagement.UserPrincipal]::Current.EmailAddress;\""; 
    String userEmail = ""; 
    if (!System.getProperty("os.name").toLowerCase().startsWith("win")) { throw new RuntimeException(
      "We are not in Windows! OS is " + System.getProperty("os.name")); } 
    Runtime rt = Runtime.getRuntime(); 
    Process pr; 
    try { 
     pr = rt.exec(cmd); 
     pr.waitFor(); 
     BufferedReader bf = new BufferedReader(new InputStreamReader(pr.getInputStream())); 
     String nextLine = null; 

     while (true) { 
      nextLine = bf.readLine(); 
      if (nextLine == null) break; 
      userEmail = nextLine; 
     } 
     bf.close(); 
    } catch (Exception e) { 
     System.err.println("Failed to get user email: " + e.getMessage()); 
     throw new RuntimeException(e); 
    } 

    return userEmail; 
} 

P.S.如果你需要更多的信息,只需在命令提示符下運行:

powershell "Add-Type -AssemblyName System.DirectoryServices.AccountManagement;[System.DirectoryServices.AccountManagement.UserPrincipal]::Current" 

並選擇你所需要的。