web项目shiro与spring集成 maven依赖及web配置详解

依赖shiro的maven坐标:

              
	            org.apache.shiro  
	            shiro-core  
	            ${shiro.version}  
	          
	          
	            org.apache.shiro  
	            shiro-web  
	            ${shiro.version}  
	          
	          
	            org.apache.shiro  
	            shiro-cas  
	            ${shiro.version}  
	          
	          
	            org.apache.shiro  
	            shiro-spring  
	            ${shiro.version}  
	  	    
		      
		        org.apache.shiro  
		        shiro-ehcache  
		        1.2.0  
		     
	  	    
	  	      
		        net.sf.ehcache  
		        ehcache-core  
		        2.5.3  
	 	      
在web.xml中添加shiro的filter

  
	  
	    shiroFilter  
	      
	        org.springframework.web.filter.DelegatingFilterProxy  
	      
	  
	  
	    shiroFilter  
	    /*  
	 

添加shiro的xml配置文件applicationContext-shiro.xml

 
 
     
          
  
   
  
   
    
           
   
            
                
                /home* = anon    
                / = anon    
                /logout = logout    
                /role/** = roles[admin]    
                /permission/** = perms[permssion:look]    
                /** = authc    
                
            
      
  
    
    
        
        
   
  
  
    
      
      
      
       
        
       
        
      
      
        
        
      
       
       
    
    
          
            
          
            
          
            
 
   


官方给出的内置权限过滤器(有两种)
第一种:认证过滤器
anon org.apache.shiro.web.filter.authc.AnonymousFilter
anon 表示可以匿名使用。(即无权限控制)
authc org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authc表示需要认证(登录)才能使用
user org.apache.shiro.web.filter.authc.UserFilter
user 表示必须存在用户,当登入操作时不做检查      
---------注意user和authc不同:当应用开启了rememberMe时,用户下次访问时可以是一个user,但绝不会是authc,因为authc是需要重新认证的
authcBasic org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
authcBasic 表示httpBasic认证
第二种:授权过滤器
perms org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
perms 参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,例如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。


port org.apache.shiro.web.filter.authz.PortFilter
port 当请求的url的端口不是指定端口是跳转到schemal://serverName:指定端口?queryString,其中schmal是协议http或https等,serverName是你访问的host,指定端口是url配置里port的端口,queryString


rest org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
rest这个暂时没有理解,理解后过来进行修改
roles org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
roles 参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,当有多个参数时,例如admins/user/**=roles["admin,guest"],每个参数通过才算通过,相当于hasAllRoles()方法。


ssl org.apache.shiro.web.filter.authz.SslFilter
ssl 表示安全的url请求,协议为https






























你可能感兴趣的:(shiro)