我最近开始学习 Spring Security 并尝试将其整合到我现有的 Web 应用程序中。该应用程序的配置很简单,所以我很困惑我在哪里搞砸了。
我的 web.xml
<!-- FilterChain proxy for 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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appname-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>nistreq</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appname-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>appname</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>mainpage.jsp</welcome-file>
</welcome-file-list>
和 security-config.xml
<security:http access-denied-page="/denied.jsp" use-expressions="true">
<security:form-login login-page="/login.jsp"
authentication-failure-url="/login.jsp?login_error=true" />
<security:intercept-url pattern="/*" access="isAuthenticated()"/>
<security:logout/>
</security:http>
在我为 springSecurityFilterChain ("/ ")、servlet 映射的 URL 模式 ("/") 和 security:intercept-url 模式 ("/ ") 映射的 URI 之间似乎有一些不好的魔力。这会导致重定向循环。我经历了无数种移动术语的变化,将内容推送到子包中以避免保护应用程序根等。我总是最终得到一个 404 的抓包,一个重定向循环等。
我正在做一些非常愚蠢的事情,并且会欣赏另一双眼睛。感谢您的任何见解...