Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SSO with using waffle in Tomcat

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.

like image 356
PaPaNi Avatar asked Nov 01 '22 16:11

PaPaNi


1 Answers

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());

like image 194
manojtc Avatar answered Nov 15 '22 04:11

manojtc