我需要给用户的基础上,还记得我的cookie的网页进行验证, 本网站所启发:教程检查春季认证, 我想出了用于检查所述认证中的溶液。

<强>在我的申请作出更改

的applicationContext-security.xml文件:

<intercept-url pattern='/**AuthenticationChecker.html' access="ROLE_ADMIN"/>
...
<form-login login-page="/Login.html" authentication-failure-url="/Login.html" always-use-default-target="true" default-target-url="/Main.html"/>

GWT代码:

try
{
    RequestBuilder rb = new RequestBuilder(
    RequestBuilder.POST, "AuthenticationChecker.html");
            rb.sendRequest(null, new RequestCallback() 
            {
                public void onError(Request request, Throwable exception)
                {
                    RootPanel.get().add(new HTML("[error]" + exception.getMessage()));
                }
                public void onResponseReceived(Request request, Response response)
                {
                    RootPanel.get()
                   .add(new HTML("[success (" + response.getStatusCode() + "," + response.getStatusText() + ")]"));
                }
            }
    );
}
catch (Exception e)
{
    RootPanel.get().add(new HTML("Error sending request " + e.getMessage()));
}

AuthenticationChecker.html是一个简单的空白html页面, 从我个人理解,作为AuthenticationChecker.html需要以管理员的角色,我应该有一个401未经授权,如果还记得我如果用户身份验证和他的cookie存在的cookie不存在和一个200 OK。

然而,输出总是所示:[成功(200,OK)]

要的相互核对,我简单类型authenticaionChecker.html(没有记录),并将其返回到的login.html指示弹簧确实认证所述用户。

我在这里做错了什么?

有帮助吗?

解决方案

如果你看看教程,你会看到一个401,当你使用基本身份验证才会返回。随着基于表单的认证,你必须检查是否有错误消息的响应文本。例如:

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("You have entered an incorrect username or password. Please try again.");
    } else {
        // authentication worked, show a fancy dashboard screen
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top