0

春にカスタム認証を行う必要があります。これは、ユーザーから提供されたユーザー名とパスワードを取得し、それをいくつかの値と比較し、それに基づいて認証する単純なクラスである必要があります。

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

カスタムログインコード([OK]ボタンをクリックした場合):

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

問題:

  1. 不正なログイン:成功を示し、ログイン画面を含むポップアップを開きます!! (明らかにログインは成功しませんでしたが、ログイン画面はそれを検出できませんでした)
  2. authentication-providerに値をハードコーディングしたくないのですが、独自のクラスを提供する別の方法はありますか?私はいくつかのチュートリアルを試しましたが、無駄に、それらのすべてが、スプリングがデータベースまたは他の種類のファイルを介して比較の作業を行うことを許可していることを示しているようです、私はそれを自分で行うことはできませんか?
4

1 に答える 1

1

独自のUserDetailsS​​erviceを作成する必要があるように思えます。これは、SecurityContext.getPrincipal()にUserDetailsを設定するSpringSecurityインターフェイスです。セキュリティフィルターチェーンの終わりまでにこのオブジェクトが設定されていない場合、Springは承認例外をスローします。これをキャッチして、ユーザーをアプリケーションの別のページ/部分にリダイレクトできます。

于 2009-10-22T15:59:07.113 に答える