Rae*_*vik 1 java spring spring-mvc spring-security
我最近开始学习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>
Run Code Online (Sandbox Code Playgroud)
和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>
Run Code Online (Sandbox Code Playgroud)
在我为springSecurityFilterChain("/ ")映射的 URI ,servlet映射的URL模式("/")和security:intercept-url模式("/ ")之间看起来有一些不好的魔力.这会导致重定向循环.我已经经历了无数变化的移动术语,将内容推送到子包以避免保护应用程序根目录等.我总是最终得到404的抓包,重定向循环等.
我正在做一些非常愚蠢的事情,并会欣赏另一双眼睛.感谢您的任何见解......
我相信你只需要为你的登录页面添加一个例外.除了security-config.xml中的内容之外,还要添加以下内容:
<security:http pattern="/login.jsp" security="none" />
Run Code Online (Sandbox Code Playgroud)
无论您尝试访问哪个URL,它都没有经过身份验证,因此它会尝试转到登录页面.然而,这也没有经过验证,所以它只是旋转和旋转.您的登录页面无需经过身份验证即可访问.
| 归档时间: |
|
| 查看次数: |
6749 次 |
| 最近记录: |