Tomcat 7.0.37でSpring Security Release 3.1.3でSpring MVCを使用しています
BasicAuthentication 用と FormBasedAuthentication 用の 2 つのセキュリティ フィルター チェーンを構成する必要があります。
ここに私の spring-security.xml ファイルがあります:
<beans:beans ...>
...
<!-- ....................... -->
<!-- The Gui is secured here -->
<!-- ....................... -->
<http auto-config="true" use-expressions="true" pattern="/gui/**">
<intercept-url pattern="/gui/login**" access="isAnonymous()"/>
<form-login login-page="/gui/login" default-target-url="/gui/welcome"
authentication-failure-url="/gui/loginfailed" />
<logout logout-success-url="/gui/logout" />
<intercept-url pattern="/welcome*" access="hasRole('een_admin')" />
<intercept-url pattern="/mandantAdmin/**" access="isAuthenticated()"/>
<intercept-url pattern="/standortAdmin/**" access="isAuthenticated()"/>
<intercept-url pattern="/ereignisse/**" access="isAuthenticated()" />
<intercept-url pattern="/tickets/**" access="isAuthenticated()"/> <!-- requires-channel="https" -->
<intercept-url pattern="/**" access="hasRole('een_admin')"/>
</http>
<!-- ................................. -->
<!-- The Service Methods are secured here -->
<!-- ................................. -->
<http use-expressions="true" >
<http-basic />
<logout logout-url="/resources/j_spring_security_logout"/>
<intercept-url pattern="/service/ticketManagement/**" access="isAuthenticated()"/>
<intercept-url pattern="/service/standortKonfig/**" access="isAuthenticated()"/>
<intercept-url pattern="/service/ereignisStorage/**" access="isAuthenticated()"/>
</http>
<debug/>
<authentication-manager>
<authentication-provider>
<password-encoder hash="sha-256"/>
<user-service>
<user name="123" password="asdf" authorities="een_admin" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
私の web.xml は次のとおりです。
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- ........................................................................... -->
<!-- Spring Security -->
<!-- ........................................................................... -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
フォーム ベースの保護されたリソースの 1 つにアクセスすると、構成されたカスタム ログイン フォームに正常に委任されます。しかし、資格情報を入力した後、「j_spring_security_check」が見つからないという 404 エラーが表示されます (この URL を使用しています: "http://127.0.0.1:8080/webapp/j_spring_security_check"
)
ここにいくつかのログがあります:
Request received for '/gui/login':
org.apache.catalina.connector.RequestFacade@174e4b3
servletPath:/gui/login
pathInfo:null
Security filter chain: [
SecurityContextPersistenceFilter
LogoutFilter
UsernamePasswordAuthenticationFilter
BasicAuthenticationFilter
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
FilterSecurityInterceptor
]
Request received for '/j_spring_security_check':
org.apache.catalina.connector.RequestFacade@174e4b3
servletPath:/j_spring_security_check
pathInfo:null
Security filter chain: [
SecurityContextPersistenceFilter
LogoutFilter
BasicAuthenticationFilter
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
FilterSecurityInterceptor
]
01:06:06,345 WARN http-apr-8080-exec-3 servlet.PageNotFound:1080 - No mapping found for HTTP request with URI [/webapp/j_spring_security_check] in DispatcherServlet with name 'mvc-dispatcher'
In access_logs:
"POST /webapp/j_spring_security_check HTTP/1.1" 404 949
リダイレクト時にUsernamePasswordAuthenticationFilterが欠落していることに注意してください。
最初の要素のパターン属性 pattern="/gui/**" を削除し、2 番目の要素をコメント アウトすると (そうしないと、インターセプター URL パターンに問題があるため必要になります)、再び正常に動作します。
少し簡略化: パターン属性を http 要素に追加すると、j_spring_security_check が見つからなくなります。
私は何を間違っていますか、誰でも私を助けることができますか?