2010-05-26 49 views
0

我們有一個gwt應用程序,它使用jcifs從我們的NT域中提取用戶名。這裏是我們的web.xml的剪輯:GWT,jcifs和多個登錄提示

<filter> 
    <filter-name>NtlmHttpFilter</filter-name> 
    <filter-class>com.xxx.gwt.server.MyNTLMFilter</filter-class> 

    <init-param> 
     <param-name>jcifs.netbios.wins</param-name> 
     <param-value>192.168.109.20</param-value> 
    </init-param> 
    <init-param> 
     <param-name>jcifs.smb.client.domain</param-name> 
     <param-value>its</param-value> 
    </init-param> 
</filter> 

<filter-mapping> 
    <filter-name>NtlmHttpFilter</filter-name> 
    <url-pattern>/trunkui/greet</url-pattern> 
</filter-mapping> 

<!-- Servlets --> 
<servlet> 
    <servlet-name>greetServlet</servlet-name> 
    <servlet-class>com.xxx.gwt.server.GreetingServiceImpl</servlet-class> 
</servlet> 

<servlet-mapping> 
    <servlet-name>greetServlet</servlet-name> 
    <url-pattern>/trunkui/greet</url-pattern> 
</servlet-mapping> 

當用戶進入我們的網站,他們得到約2或3次重複提示,要求他們登錄到,即使他們已經是域所以目前(你必須在域上去到我們的應用程序)。我想至少減少提示只發生一次。所以我打算在「/ trunkui/dummy」之外創建一個虛擬servlet,並讓它只在我詢問名稱時才被調用。遠程servlet有這種方法,我們異步調用:

public String getUser() { 
    String userAgent = ""; 
    try { 
     userAgent = getThreadLocalRequest().getUserPrincipal().getName(); 

     int slashIdx = -1; 
     if ((slashIdx = userAgent.indexOf('\\')) >= 0) 
      userAgent = userAgent.substring(slashIdx + 1); 
    } catch (Exception npe) { 
     npe.printStackTrace(); 
    } 
    return userAgent; 
} 

所以我想要做某種呼叫到虛擬的servlet做域名提示,但我對如何從GWT遠程做到這一點不確定服務。或者如果有更好的方法來做到這一點?

回答

0

我想通了。我構建了虛擬servlet,然後在客戶端使用了一個RequestBuilder來實現該servlet。那個servlet然後得到userprincipal。這裏是客戶端:

RequestBuilder getNameRB = new RequestBuilder(RequestBuilder.GET, "naming"); 
    getNameRB.setCallback(new RequestCallback() { 

     @Override 
     public void onResponseReceived(Request request, Response response) { 
      loadUserName(response.getText()); 
     } 

     @Override 
     public void onError(Request request, Throwable exception) { 
      Window.alert("Unable to authenticate user\n"+exception.getMessage()); 
      Window.Location.replace("http://ccc"); 
     } 
    }); 
    try { 
     getNameRB.send(); 
    } catch (RequestException e) { 
     Window.alert(e.getMessage()); 
    }