Spring Acegi Security实例解析二

        1. 在MySql中执行如下脚本:

Drop TABLE IF EXISTS `test`.`student`;
Create TABLE `test`.`student` (
`name` varchar(40) NOT NULL,
`psw` varchar(10) NOT NULL,
`enabled` boolean
);
insert into student values("lanp","lanpiao",true);

Drop TABLE IF EXISTS `test`.`user_privileges`;
Create TABLE `test`.`user_privileges` (
`name` varchar(40) NOT NULL,
`privilege` varchar(40) NOT NULL
);
insert into user_privileges values("lanp","ROLE_PRESIDENT");


 

        2. 将以下Jar包导入工程中:acegi-security-0.8.3.jar、commons-logging-1.0.4.jar、javax.servlet.jar、mysql-connector-java-5.0.3-bin.jar、oro-2.0.8.jar和spring-1.2-RC2.jar。并要加入工程的classpath中。

        3. web.xml配置文件的配置如下:



	myacegi
	
	
		contextConfigLocation
		
			/WEB-INF/applicationContext-acegi-security.xml
		
	
	
	
  		MyAcegiFilter
  		net.sf.acegisecurity.util.FilterToBeanProxy
		
    		targetBean
    		filterChainProxy 
  		
	
	
	
      MyAcegiFilter
      /*
    
    
    
		org.springframework.web.context.ContextLoaderListener
	
	
	
		index.html
		index.htm
		index.jsp
		default.html
		default.htm
		default.jsp
	


 

        4. applicationContext-acegi-security.xml的配置如下:




	
	
      
         
		    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
		    PATTERN_TYPE_APACHE_ANT
            /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter
         
      
    
    
   
      net.sf.acegisecurity.context.security.SecureContextImpl
   
   
   
        
            com.mysql.jdbc.Driver
        
        
            jdbc:mysql://127.0.0.1:3306/test
        
        
            root
        
        
            157891
        
    
    
    
	  	
	  	
	    	SELECT name, psw, enabled FROM student WHERE name=?
	    
	    
	    	SELECT name, privilege FROM user_privileges where name=?
	  	
	

	
  		
    		
  		
	


	
  		
	    
	      
	    
  		
	
	
	
  		
    		/login.jsp
  		
  		true
	
	
	
	  
	    /j_acegi_security_check
	  
	  
	    /login.jsp?failed=true
	  
	  
	    /jsp/index.jsp
	  
	  
	    
	  
	

        5. 登陆表单如下:


	
Name:
Password:

 

 

你可能感兴趣的:(IT海洋——Spring)