使用Waffle在Tomcat中实现Java单点登录

5

我正在使用以下代码来获取实际登录的用户:

    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中始终为空。
2个回答

1

它可以获取运行在服务器上的Tomcat服务的用户ID。如果您需要来自客户端的用户ID,则应使用request.getUserPrincipal().getName());


1
如果您想在Tomcat中使用华夫饼干身份验证,应该使用过滤器而不是独立的代码。 您现在的代码适用于一些独立应用程序,例如Swing/win表单等。 但是通过HTTP进行身份验证,应该使用过滤器。请查看使用Spring安全性+Tomcat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接