Spring SecurityでCSRF対策機能だけ使うには、どのような記述をxmlファイルに追加すればいいのでしょうか?
現在、Spring MVC 4.3.2を用いてWebアプリケーションを作成しています。ユーザー登録・ログイン・ログアウト機能などを、自前で実装し終わったところで、ユーザー登録・ログインフォームにCSRF対策を施したいと考えました。これも自前で実装しても良いのですが、Spring SecurityにCSRF対策を自動で行ってくれる機能があるようなので、それを使うことにしました。Spring Securityの最新版をMavenの依存性に追加し、Web上の情報にしたがって以下の設定をSpringのxmlファイルに追記しました。
xml
1<security:http auto-config="true"/>
この状態でアプリケーションを起動したところ、以下のエラーメッセージが表示されました。
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.security.authenticationManager' is defined: Did you forget to add a global <authentication-manager> element to your configuration (with child <authentication-provider> elements)? Alternatively you can use the authentication-manager-ref attribute on your <http> and <global-method-security> elements.
そこで、xmlファイルの追加記述を以下のように変更しました。
xml
1<security:http auto-config="true"/> 2<security:authentication-manager/>
この変更でエラーは出ないようになったのですが、CSRFトークンがHTMLに挿入されておらず、困っています。ちなみに、web.xmlの方にはDelegatingFilterProxyを追加済みです。
xml
1<filter> 2 <filter-name>springSessionRepositoryFilter</filter-name> 3 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 4</filter> 5<filter-mapping> 6 <filter-name>springSessionRepositoryFilter</filter-name> 7 <url-pattern>/*</url-pattern> 8 <dispatcher>REQUEST</dispatcher> 9 <dispatcher>ERROR</dispatcher> 10</filter-mapping>
ご回答よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー