通过GWT按钮与Jetty进行身份验证

通过GWT按钮与Jetty进行身份验证,gwt,forms-authentication,smartgwt,embedded-jetty,Gwt,Forms Authentication,Smartgwt,Embedded Jetty,我正在尝试使用SmartGWT创建一个登录页面,并且一直在尝试让表单身份验证与嵌入了用于Eclipse的GWT插件的Jetty服务器一起工作。我有一个使用TextItems获取用户名和密码的页面,然后一旦按下登录按钮,我需要进行身份验证 我已经设置了jetty-web.xml文件来创建一个自定义领域,该领域目前没有做任何事情,只是告诉我正在调用它的方法,这样我就知道它正在工作,因为一旦我进入了这个领域,我很确定我可以解决剩下的问题 jetty-web.xml <Configure clas

我正在尝试使用SmartGWT创建一个登录页面,并且一直在尝试让表单身份验证与嵌入了用于Eclipse的GWT插件的Jetty服务器一起工作。我有一个使用TextItems获取用户名和密码的页面,然后一旦按下登录按钮,我需要进行身份验证

我已经设置了jetty-web.xml文件来创建一个自定义领域,该领域目前没有做任何事情,只是告诉我正在调用它的方法,这样我就知道它正在工作,因为一旦我进入了这个领域,我很确定我可以解决剩下的问题

jetty-web.xml

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
    <Get name="SecurityHandler">
        <Call name="setUserRealm">
            <Arg>
                <New class="custom.realm.CustomRealm">
                    <Set name="name">CustomRealm</Set>
                </New>
            </Arg>
        </Call>

        <Call name="setAuthenticator">
            <Arg>
                <New class="org.mortbay.jetty.security.FormAuthenticator">
                    <Set name="loginPage">/login.html</Set>
                    <Set name="errorPage">/login.html</Set>
                </New>
            </Arg>
        </Call>
    </Get>
</Configure>
[重新更新] 如果未注释auth约束,则永远不会调用onModuleLoad方法。有人知道为什么会这样吗

<security-constraint>
    <web-resource-collection>        
        <web-resource-name>Login</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <!-- <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint> -->

</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>CustomRealm</realm-name>
    <form-login-config>
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/login.html</form-login-page>
    </form-login-config>
</login-config>
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "login.html");
StringBuilder postData = new StringBuilder();
postData.append(URL.encode("j_username")).append("=").append(URL.encode(getUsername()));
postData.append("&");
postData.append(URL.encode("j_password")).append("=").append(URL.encode(getPassword()));
rb.setRequestData(postData.toString());
rb.setHeader("Content-type", "application/x-www-form-urlencoded");
rb.setCallback(new RequestCallback() {
    @Override
    public void onResponseReceived(Request request, Response response)
    {
        if (response.getStatusCode() != Response.SC_OK)         
        {
            onError(request, new RequestException(response.getStatusText() + ":\n" + response.getText()));
            return;
        }

        if (response.getText().contains("Access Denied"))
        {
            Window.alert("Incorrect username or password entered. Please try again.");
        }
        else
        {
            System.out.println("IT WORKED!!!");
        }
    }

    @Override
    public void onError(Request request, Throwable exception)
    {
        Window.alert(exception.getMessage());
    }
});

try
{
    rb.send();
}
catch (RequestException e)
{
    SC.say(e.getMessage());
}