2016-07-26 174 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" 

并选择你所需要的。