spring security3的学习笔记

1、在spring-security官网下载最新jar然后拷贝jar到项目的lib下。 

2、在classpath下添加security配置文件,例如applicationContext-security.xml.网上现在大多都是2.0的schema. 要根据自己使用的版本而定.下面是3.0的schema.

xmlns:s="http://www.springframework.org/schema/security" 
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.0.xsd">

SpringSecurity Config

















login-page="/backLogin.jsp"
 default-target-url="/login_success_by_role_redirect.jsp"
authentication-failure-url="/login_failure_by_role_redirect.jsp?error=1" />












3. 在web.xml中要添加以下代码:

  1.   
  2.         <context-param>  
  3.         <param-name>contextConfigLocationparam-name>  
  4.         <param-value>  
  5.             classpath*:/applicationContext*.xml   
  6.         param-value>  
  7.     context-param>  
  8.   
  9.     <filter>  
  10.         <filter-name>springSecurityFilterChainfilter-name>  
  11.         <filter-class>  
  12.             org.springframework.web.filter.DelegatingFilterProxy   
  13.         filter-class>  
  14.     filter>  
  15.     <filter-mapping>  
  16.         <filter-name>springSecurityFilterChainfilter-name>  
  17.         <url-pattern>/*url-pattern>  
  18.     filter-mapping>  


4. 例子如下:   

  (1). login.jsp中主要:

   

 action="${pageContext.request.contextPath}/j_spring_security_check"   (固定的)
          method="post" style="width: 260px; text-align: center;">
  

   
     登陆
   

    用户:
    name="j_username" style="width: 150px;"
     value="${sessionScope['SPRING_SECURITY_LAST_USERNAME']}" />
   

    密码:
    name="j_password" style="width: 150px;" />
   

  (2). 其中login_success_by_role_redirect.jsp的内容有:

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>






















ifNotGranted="ROLE_Authority_Admin_Base, ROLE_Authority_Account_Admin, ROLE_Authority_Quality_Checker, ROLE_Authority_Developer">



5.以上就是一个完整的配置过程。







你可能感兴趣的:(spring security3的学习笔记)