簡體   English   中英

在Tomcat中使用華夫餅干的Java SSO

[英]Java SSO with using waffle in Tomcat

我使用以下代碼來獲取實際登錄用戶:

    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中啟動時,它始終為null。

它會為您提供在服務器上運行Tomcat服務的用戶標識。 如果您需要來自客戶端的用戶ID,則應使用request.getUserPrincipal().getName());

如果您嘗試在tomcat中使用華夫餅干驗證,則應該使用過濾器而不是獨立代碼。 您的代碼現在適用於某些獨立應用程序,例如Swing / win表單等。但是通過HTTP,它應該使用過濾器完成。 看看使用Spring security + tomcat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM