我正在使用以下代码来获取实际登录的用户:
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中始终为空。