Gwt 我需要在spring中进行简单的自定义身份验证

Gwt 我需要在spring中进行简单的自定义身份验证,gwt,web,spring-security,Gwt,Web,Spring Security,我需要在spring中有一个自定义身份验证,它应该是一个简单的类,接受用户提供的用户名和密码,并将其与一些值进行比较,然后根据这些值进行身份验证 我们使用的是GWT制作的系统,我们的登录表单一旦成功,就会在一个新窗口中打开另一个页面 这就是我迄今为止所做的尝试: 文件:应用程序上下文安全性: ... <http auto-config="true"> <intercept-url pattern='/*Login.html' access="IS_AUTH

我需要在spring中有一个自定义身份验证,它应该是一个简单的类,接受用户提供的用户名和密码,并将其与一些值进行比较,然后根据这些值进行身份验证

我们使用的是GWT制作的系统,我们的登录表单一旦成功,就会在一个新窗口中打开另一个页面

这就是我迄今为止所做的尝试: 文件:应用程序上下文安全性:

...
<http auto-config="true">
           <intercept-url pattern='/*Login.html' access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <intercept-url pattern='/**/*MainScreen.html' access="ROLE_ADMIN"/>   
        <form-login login-page="/Login.html"/><!-- This is the default login page -->
    </http>
<authentication-provider>
        <user-service>
            <user name="test1" password="abc" authorities="ROLE_ADMIN" />
            <user name="test2" password="test" authorities="ROLE_ADMIN" />
        </user-service>
</authentication-provider>
...
问题:

  • 登录错误:显示成功并打开包含登录屏幕的弹出窗口!!(显然登录没有成功,但登录屏幕无法检测到)
  • 我不想硬编码身份验证提供程序中的值,是否有其他方法可以提供我自己的类?我尝试了几篇教程,但都是徒劳的,它们似乎都指向我允许spring通过数据库或其他类型的文件进行比较,我不能自己做吗

  • 听起来你需要编写自己的用户详细信息服务。这是Spring安全接口,它用UserDetails填充SecurityContext.getPrincipal()。如果,在安全过滤器链的末尾,此对象尚未填充,则Spring将抛出一个授权异常,可以捕获该异常,并将用户重新定向到应用程序的另一个页面/部分。

    客户端登录代码基于:除用户名和密码外,我还需要传递更多数据,这也有可能吗?我现在真的很沮丧,我已经尝试了1000件事情(字面意思)如果可能的话,你能给我提供一个解决我问题的代码片段或一个简单例子的链接吗??
            RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST,"j_spring_security_check");
            requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
            //-- sending the username and the password in designated fields.
            //Hard coding values for testing reasons:
            requestBuilder.setRequestData("j_username=test1" +
                            "&j_password=abc");
    
            requestBuilder.setCallback(new RequestCallback() {
                public void onError(Request request, Throwable exception)
                {
                    Window.alert("ERROR !!!"+exception.getMessage());
                }
                public void onResponseReceived(Request request, Response response)
                {
                    if (response.getStatusCode() != Response.SC_UNAUTHORIZED && response.getStatusCode() != Response.SC_OK)
                    { 
                        onError(request, new RequestException(response.getStatusText() + ":\n" + response.getText())); 
                        return; 
                    }
    
                    if (response.getStatusCode() == Response.SC_UNAUTHORIZED)
                    { 
                        //This code is never encountered !! :((
                        Window.alert("You have entered an incorrect username or password. Please try again."); 
                    }
                    else
                    { 
                        String height = 800+"";
                        String width = 600+"";
    
                        Window.alert("Authorisation succeeded, you may enter....");
                        Window.open("MainScreen.html", "Main screen!!", "height=" + height + ",width=" + width
                                        + ",scrollbars=yes,resizable=yes,titlebar=no,toolbar=no,status=yes,close=no,left=0,top=0");
                    } 
    
                }
            });
            requestBuilder.send();