通过GWT按钮通过Jetty进行认证

| 我正在尝试使用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>
[编辑05/18 1:16 pm] 我的CustomRealm扩展了Jetty的HashUserRealm,如果可能会引起问题,那就不要了,btu认为我也提到了它。 我还在我的web.xml文件中设置了安全约束 web.xml代码段
<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>
我是从事此类工作的新手,tbh。我不确定是否需要约束。之所以被注释掉是因为当我取消注释时,该页面根本不会加载。 从我读到的内容中,我收集到将安全性约束与Jetty一起使用应弹出一个浏览器登录对话框。那不是我想要发生的事情,而且实际上也并非如此。因此,我不确定自己在做什么错。 我还在GWT中找到了RequestBuilder类,但这似乎并没有做我想做的任何事情。我需要登录按钮以某种方式在自定义领域中调用authenticate方法。我想知道是否有办法做到这一点?或至少指向正确的方向,因为我一直在寻找而未发现任何东西。 提前致谢。 [编辑05/18 8:56 am] 根据Peter的建议,添加现在如何设置我的RequestBuilder
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());
}
[重新更新] 如果未对auth-constraint进行注释,则永远不会调用onModuleLoad方法。有人知道为什么会这样做吗?     
已邀请:

要回复问题请先登录注册