tags:

views:

26

answers:

1

We have a gwt app that uses jcifs to pull the user name from our NT domain. Here is a clip of our web.xml:

<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>

So currently when the user goes to our site they get about 2 or 3 repeated prompts asking them to log onto the domain even though they already are (you have to be on the domain to get to our app). I would like to at least reduce the prompting to only happen once. So I was going to make a dummy servlet off of "/trunkui/dummy" and let that get called only when I ask for the name. The remote servlet has this method that we call asynchronously:

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;
}

So I wanted to do some sort of call to the dummy servlet to do the domain prompting, but I am unsure on how to do this from the gwt remote service. Or if there is a better way to do this?

A: 

I figured it out. I built the dummy servlet and then used a RequestBuilder on the client side to do a get on that servlet. That servlet then gets the userprincipal. Here is the client side:

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