2012-02-10 18 views
0

私のアプリケーションでspring 3を使用していて、1つの問題に直面しています。私は私のxmlファイルでは、このような春のセキュリティを設定している:Spring Security - UsernamePasswordAuthenticationFilterでユーザー名/パスワード以外のカスタムパラメータを追加する方法

<bean id="authenticationFilter"  class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" 
     p:authenticationManager-ref="myAuthenticationManager" 
     p:authenticationFailureHandler-ref="customAuthenticationFailureHandler" 
     p:authenticationSuccessHandler-ref="customAuthenticationSuccessHandler" 
     p:sessionAuthenticationStrategy-ref="sas" p:usernameParameter="username" 
     p:passwordParameter="password" **p:customparameter="mycustomparameter"** p:filterProcessesUrl="/validate_user.jspx" 
     p:postOnly="true" /> 

しかし、春のコンテキストを初期化した後、私はmycustomparameterは、任意のゲッター/セッターを持っていないと見られないので...

ないという例外を取得しています

私はカスタムのauthenticatemanagerクラスに私のカスタムパラメータを渡す必要があります(認証オブジェクトでunameとpwdを取得しています)(authentication.getDetails()にこの追加情報があります) また、このフィールドはlogin.jspページにあります -

<s:hidden label="Password" id="login_form_mycustomparameter" name="mycustomparameter" 
value="false" cssClass="txtbox" required="true" /> 

可能ですか? そうでない場合は、これを達成する別の方法を提案してください。

おかげ..

+1

http://stackoverflow.com/questions/9028532/how-to-catch-spring-security-login-form-b​​efore-spring-gets-it/9034851#9034851 – sourcedelica

答えて

0

はcustomparameterは存在しませんUsernamePasswordAuthenticationFilter.setCustomparameterを呼び出そうとしています。したがって、UsernamePasswordAuthenticationFilterを拡張し、setCustomparameterメソッドを提供するカスタムフィルタを作成する必要があります。作成するカスタムフィルタは、このカスタムパラメータを含むカスタム認証オブジェクトを作成する必要があります。最後に、カスタムAuthenticationProviderが必要になります。この認証プロバイダは、ユーザーの認証時にカスタムパラメータを使用します。

+0

ご返信ありがとうございます。カスタム認証オブジェクトを '作成 'することは可能ですか? サンプルコードを投稿してください。 – Ved

関連する問題