在Tomcat中使用华夫饼干的Java SSO

时间:2014-09-29 09:01:22

标签: java tomcat single-sign-on waffle

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

    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 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

如果您尝试在tomcat中使用华夫饼干验证,则应该使用过滤器而不是独立代码。 您的代码现在适用于某些独立应用程序,例如Swing / win表单等。 但是通过HTTP,它应该使用过滤器完成。看看Using Spring security + tomcat

相关问题