我正在使用以下代码来获取实际登录用户:
IWindowsSecurityContext clientContext = WindowsSecurityContextImpl.getCurrent("Negotiate", "localhost");
WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
IWindowsSecurityContext serverContext = null;
do {
if (serverContext != null) {
byte[] tokenForTheClientOnTheServer = serverContext.getToken();
SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, tokenForTheClientOnTheServer);
clientContext.initialize(clientContext.getHandle(), continueToken, "localhost");
}
byte[] tokenForTheServerOnTheClient = clientContext.getToken();
serverContext = provider.acceptSecurityToken("server-connection", tokenForTheServerOnTheClient, "Negotiate");
System.out.println("SSO-Identity: " + serverContext.getIdentity().getFqn());
} while (clientContext.getContinue());
System.out.println("Identity: " + serverContext.getIdentity().getFqn());
当我在 Eclipse 中启动它并返回我的用户名时,它工作正常。
当我部署我的 Web 应用程序并在 Tomcat 中启动它时,它会返回 nt-authority\system。但我需要实际登录用户的名称。(在 Tomcat 中使用 Waffle SSO 工作正常,但我无法获取用户名)
拜托,有人有想法吗?
编辑:eclipse中的用户主体也是正确的。当我在 Tomcat 中启动时,它始终为空。