I am using following code to get actual logged in user:
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());
It works fine when I start it in Eclipse and returns my username.
When I deploy my Web Application and start it in Tomcat, it returns nt-authority\system. But I need the name of the actual logged in user. (Using Waffle SSO in Tomcat works fine, but I have no possibility to get the name of the user)
Please, anyone an idea?
Edit: The user principal in eclipse is correct, too. When I start in Tomcat it is always null.
It gets you the user id that's running the Tomcat service on the server. If you need the user id from the client you should use request.getUserPrincipal().getName());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With