首先,如果这是重复的,请有人指出这一点。但目前,我找不到有人问过这个问题。我有这个弹簧安全配置:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config="true">
<intercept-url pattern="/admin/**" access="ROLE_ADMIN" />
<form-login login-page="/login.htm" default-target-url="/admin/adminDashboard.htm"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout.htm" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="123" authorities="ROLE_ADMIN" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
即这个控制器:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class AdministrationController {
@RequestMapping(value = "/login.htm", method = RequestMethod.GET)
public String login() {
return "login";
}
@RequestMapping(value = "/admin/banAppealsList.htm", method = RequestMethod.GET)
public String banAppealsList() {
return "banAppealsList";
}
@RequestMapping(value = "/admin/adminDashboard.htm", method = RequestMethod.GET)
public String adminDashboard() {
return "adminDashboard";
}
}
如您所见,它拦截了/admin/**
URL。登录后,它会将我重定向到adminDashboard.jsp
页面。但我面临的问题是:如何在adminDashboard.jsp
不要求提供凭据的情况下从我的页面重定向到其他安全页面?基本上,如果我想继续,banAppealsList.htm
它会再次要求我提供凭据。
编辑:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/security-context.xml
</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Define a filter to enable Spring Security, be sure to use the suggested
name 'springSecurityFilterChain' -->
<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>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>banAppeal.htm</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>60</session-timeout>
<!-- Obviously, problem was here -->
<cookie-config>
<secure>true</secure>
</cookie-config>
</session-config>
</web-app>