---
title: "SpringSecurity备忘配置"
author: "Kenny.Lee"
date: "2011-11-01T11:37:32Z"
tags: []
categories: ["编程语言"]
slug: "springsecurity"
draft: false
lastmod: "2011-11-01T11:37:54Z"
id: 1226568
url: "https://kennylee26.iteye.com/blog/1226568"
---

1.定义登录后的首页action.do，该action决定了用户登录成功后的具体初始化内容。

 

2.在根目录定义index.jsp页面，并设置为welcome-file-list首要引导页面。

 

3.index.jsp页面只做跳转操作，内容如下：

 

 

&lt;%

response.setHeader("Cache-Control", "Private");

response.setDateHeader("Expires",

System.currentTimeMillis() + 864000000L);

response.sendRedirect("./index.do");

%&gt;

 

 

\-------------

 

意味着任何请求都跳转到 index.do，若没通过验证，则自动再会被拦截跳到配置的登录页面，登录成功后会index.do。

 

4.直接访问登录页面，向/j\_spring\_security\_check发请求后。会跳转到默认的索引页面，例如 www.foo.com

  即直接访问welcome-file-list中配置的页面，然而参考第三点的设置。

 

所以，我们也能实现用户直接访问登录页面，但成功后又能返回我们指定首页中去。

 

5.勿忘，除了导入SpringSecurity的配置XML文件，在web.xml中的

 

&lt;filter&gt;

&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;

&lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;

&lt;/filter&gt;

&lt;filter-mapping&gt;

&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;

&lt;url-pattern&gt;/\*&lt;/url-pattern&gt;

&lt;/filter-mapping&gt;

 

 

也是尤其重要的。

 

6.默认让请求都IS\_AUTHENTICATED\_REMEMBERED

 

这样可以让所以通过了验证或记录了验证权限的角色访问页面，不需要另外弄自定义登录权限了。