0
ユーザーが資格情報を入力しなくても、Active Directoryに対してユーザーの資格情報を照会します。すなわち、ユーザは自分の企業システム(Intranetwork)にログインします。私はこれらのクレデンシャルを使用して広告を検証し、ユーザがいる場合は電子メールアドレスを取得する必要があります(シングルサインオンは不要)Active Directoryを照会しています
ユーザーが資格情報を入力しなくても、Active Directoryに対してユーザーの資格情報を照会します。すなわち、ユーザは自分の企業システム(Intranetwork)にログインします。私はこれらのクレデンシャルを使用して広告を検証し、ユーザがいる場合は電子メールアドレスを取得する必要があります(シングルサインオンは不要)Active Directoryを照会しています
もちろん、私のような誰かが同じ答えを探すことができます...
なぜ私はユーザーの資格情報を確認する必要がありますか分かりません? ユーザーが既にログインしている場合は...資格情報が確認されます。
Windows powershellを使用すると、彼の電子メール(およびADからの他の情報)を取得することができます。
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"
を選択してください。