shiro整合SpringMVC

shiro(三)shiro实战,常见java面试题和答案 配置AOP 式方法级权限检查 配置 Shiro Filter 配置 Shiro Filter filterChainDefinitions 属性:设置 Shiro Filter 拦截的 URL 及访问该 URL 所需要的权限信息。 格式:URL_Ant_Path_Expression = Path_Specific_Filter_Chain。 等号左边是一个与 Web 应用程序上下文根目录相关的Ant 风格的路径表达式。 等号右边是逗号隔开的过滤器列表,用来执行匹配该路径的请求 Ant 风格资源地址支持 阅读详情

一、前言

前面我们主要讲解了写什么,讲解通过ini文件加载,自定义realm源(ishi加密),对用户认证和权限授权。这一章开始,我们开始整合shrio到web项目中,当然还是与我们之前的springmvc与mybatis整合。这里的mybatis不强求,如果你整合的时候也可以用hibernate,只不过是另一个数据框架。

二、整合spring

2.1 基础框架

语言准备好基础框架:springmvc+mybatis的整合文件,项目采用maven

2.2jar包导入,pom.xml引入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
   <!--======================================shrio=================================================-->
     < dependency >
         < groupId >org.apache.shiro</ groupId >
         < artifactId >shiro-core</ artifactId >
         < version >1.2.4</ version >
     </ dependency >
     < dependency >
         < groupId >org.apache.shiro</ groupId >
         < artifactId >shiro-web</ artifactId >
         < version >1.2.4</ version >
     </ dependency >
     < dependency >
         < groupId >org.apache.shiro</ groupId >
         < artifactId >shiro-spring</ artifactId >
         < version >1.2.4</ version >
     </ dependency >
     < dependency >
         < groupId >org.apache.shiro</ groupId >
         < artifactId >shiro-ehcache</ artifactId >
         < version >1.2.4</ version >
     </ dependency >
     < dependency >
         < groupId >org.apache.shiro</ groupId >
         < artifactId >shiro-quartz</ artifactId >
         < version >1.2.4</ version >
     </ dependency >

2.3在web.xml配置filter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!--===============================================shiro过虑器================================================-->
     <!-- shiro过虑器,DelegatingFilterProx会从spring容器中找shiroFilter代理模式(律师模式) -->
     < filter >
         < filter-name >shiroFilter</ filter-name >
         < filter-class >org.springframework.web.filter.DelegatingFilterProxy</ filter-class >
         <!--设置为true有servlet容器控制filter声明周期-->
         < init-param >
             < param-name >targetFilterLifecycle</ param-name >
             < param-value >true</ param-value >
         </ init-param >
     </ filter >
     < filter-mapping >
         < filter-name >shiroFilter</ filter-name >
         < url-pattern >/*</ url-pattern >
     </ filter-mapping >

2.4在spring中配置filter

配置完毕web.xml,我们需要在spring设置我们filter,主要配置:(拒绝权限地址,用户认证跳转页面)1、过滤器,2、安全管理器, 3、自己定义realm

跟我们用ini配置是思想是一样的。拦截---交给shrio的filter---shrio拦截

(applicationContext-shiro.xml)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
< beans  xmlns = "http://www.springframework.org/schema/beans"
        xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"  xmlns:mvc = "http://www.springframework.org/schema/mvc"
        xmlns:context = "http://www.springframework.org/schema/context"
        xmlns:aop = "http://www.springframework.org/schema/aop"  xmlns:tx = "http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-4.0.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd ">
     <!-- Shiro 的Web过滤器 -->
     <!--1、与web.xml对应的bean-->
     < bean  id = "shiroFilter"  class = "org.apache.shiro.spring.web.ShiroFilterFactoryBean" >
         < property  name = "securityManager"  ref = "securityManager"  />
         <!-- 如果没有认证将要跳转的登陆地址,http可访问的url,如果不在表单认证过虑器FormAuthenticationFilter中指定此地址就为身份认证地址 -->
         < property  name = "loginUrl"  value = "/login.action"  />
         <!-- 没有权限跳转的地址 -->
         < property  name = "unauthorizedUrl"  value = "/pages/jsp/refuse.jsp"  />
         <!--过滤定义,从上而下,蒋匿名的anon放最下面-->
         < property  name = "filterChainDefinitions" >
             < value >
                 /** anon
             </ value >
         </ property >
     </ bean >
 
     <!-- 2、安全管理器 -->
     < bean  id = "securityManager"  class = "org.apache.shiro.web.mgt.DefaultWebSecurityManager" >
         < property  name = "realm"  ref = "userRealm"  />
     </ bean >
 
     <!--3、realm-->
     < bean  id = "userRealm"  class = "com.ycy.shiro.CustomRealm" />
</ beans >

2.4.1 shrio过滤器

上面所说的过滤器需要配置文件,配置如下

过滤器简称

对应的Java类

anon

org.apache.shiro.web.filter.authc.AnonymousFilter

authc

org.apache.shiro.web.filter.authc.FormAuthenticationFilter

authcBasic

org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter

perms

org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter

port

org.apache.shiro.web.filter.authz.PortFilter

rest

org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter

roles

org.apache.shiro.web.filter.authz.RolesAuthorizationFilter

ssl

org.apache.shiro.web.filter.authz.SslFilter

user

org.apache.shiro.web.filter.authc.UserFilter

logout

org.apache.shiro.web.filter.authc.LogoutFilter


Shiro-1.2.2内置的FilterChain

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
=========================================================================================================================
   1)Shiro验证URL时,URL匹配成功便不再继续匹配查找(所以要注意配置文件中的URL顺序,尤其在使用通配符时)
     
     故filterChainDefinitions的配置顺序为自上而下,以最上面的为准
     
   2)当运行一个Web应用程序时,Shiro将会创建一些有用的默认Filter实例,并自动地在[main]项中将它们置为可用
     
     自动地可用的默认的Filter实例是被DefaultFilter枚举类定义的,枚举的名称字段就是可供配置的名称
     
     anon---------------org.apache.shiro.web.filter.authc.AnonymousFilter
     
     authc--------------org.apache.shiro.web.filter.authc.FormAuthenticationFilter
     
     perms--------------org.apache.shiro.web.filter.authz.PermissionAuthorizationFilter
     
     port---------------org.apache.shiro.web.filter.authz.PortFilter
     
     rest---------------org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
     
     roles--------------org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
     
     ssl----------------org.apache.shiro.web.filter.authz.SslFilter
     
     user---------------org.apache.shiro.web.filter.authz.UserFilter
     
   =========================================================================================================================
   3)通常可将这些过滤器分为两组
   
     anon,authc,authcBasic,user是第一组认证过滤器
     
     perms,port,rest,roles,ssl是第二组授权过滤器
     
     注意user和authc不同:当应用开启了rememberMe时,用户下次访问时可以是一个user,但绝不会是authc,因为authc是需要重新认证的
     
                        user表示用户不一定已通过认证,只要曾被Shiro记住过登录状态的用户就可以正常发起请求,比如rememberMe
                        
                        说白了,以前的一个用户登录时开启了rememberMe,然后他关闭浏览器,下次再访问时他就是一个user,而不会authc
                        
   =========================================================================================================================
   4)举几个例子
     /admin=authc,roles[admin]      表示用户必需已通过认证,并拥有admin角色才可以正常发起'/admin'请求
     
     /edit=authc,perms[admin:edit]  表示用户必需已通过认证,并拥有admin:edit权限才可以正常发起'/edit'请求
     
     /home=user                     表示用户不一定需要已经通过认证,只需要曾经被Shiro记住过登录状态就可以正常发起'/home'请求
     
   =========================================================================================================================
   5)各默认过滤器常用如下(注意URL Pattern里用到的是两颗星,这样才能实现任意层次的全匹配)
   
     /admins/**=anon             无参,表示可匿名使用,可以理解为匿名用户或游客
     
     /admins/user/**=authc       无参,表示需认证才能使用
     
     /admins/user/**=authcBasic  无参,表示httpBasic认证
     
     /admins/user/**=user        无参,表示必须存在用户,当登入操作时不做检查
     
     /admins/user/**=ssl         无参,表示安全的URL请求,协议为https
     
     /admins/user/**=perms[user:add:*]
     
         参数可写多个,多参时必须加上引号,且参数之间用逗号分割,如/admins/user/**=perms["user:add:*,user:modify:*"]
         
         当有多个参数时必须每个参数都通过才算通过,相当于isPermitedAll()方法
         
     /admins/user/**=port[8081]
     
         当请求的URL端口不是8081时,跳转到schemal://serverName:8081?queryString
         
         其中schmal是协议http或https等,serverName是你访问的Host,8081是Port端口,queryString是你访问的URL里的?后面的参数
         
     /admins/user/**=rest[user]
     
         根据请求的方法,相当于/admins/user/**=perms[user:method],其中method为post,get,delete等
         
     /admins/user/**=roles[admin]
     
         参数可写多个,多个时必须加上引号,且参数之间用逗号分割,如/admins/user/**=roles["admin,guest"]
         
         当有多个参数时必须每个参数都通过才算通过,相当于hasAllRoles()方法

2.5自定义realm的编写

realm从数据库查询用户信息,将用户菜单、usercode、username等设置在SimpleAuthenticationInfo中。数据库表可参考前面几个章节的mapper.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package  com.ycy.shiro;
 
import  java.util.ArrayList;
import  java.util.List;
 
import  com.ycy.model.ActiveUser;
import  com.ycy.model.SysPermission;
import  com.ycy.model.SysUser;
import  com.ycy.service.SysService;
import  org.apache.shiro.SecurityUtils;
import  org.apache.shiro.authc.AuthenticationException;
import  org.apache.shiro.authc.AuthenticationInfo;
import  org.apache.shiro.authc.AuthenticationToken;
import  org.apache.shiro.authc.SimpleAuthenticationInfo;
import  org.apache.shiro.authz.AuthorizationInfo;
import  org.apache.shiro.authz.SimpleAuthorizationInfo;
import  org.apache.shiro.realm.AuthorizingRealm;
import  org.apache.shiro.subject.PrincipalCollection;
import  org.apache.shiro.util.ByteSource;
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.stereotype.Component;
import  org.springframework.stereotype.Service;
 
 
/**
  * 
  * <p>
  * Title: CustomRealm
  * </p>
  * <p>
  * Description:自定义realm
  * </p>
  */
public  class  CustomRealm  extends  AuthorizingRealm {
     
     //注入service
     @Autowired
     private  SysService sysService;
 
     // 设置realm的名称
     @Override
     public  void  setName(String name) {
         super .setName( "customRealm" );
     }
 
     // 用于认证
     //realm的认证方法,从数据库查询用户信息
     @Override
     protected  AuthenticationInfo doGetAuthenticationInfo(
             AuthenticationToken token)  throws  AuthenticationException {
         
         // token是用户输入的用户名和密码 
         // 第一步从token中取出用户名
         String userCode = (String) token.getPrincipal();
 
         // 第二步:根据用户输入的userCode从数据库查询
         SysUser sysUser =  null ;
         try  {
             sysUser = sysService.findSysUserByUserCode(userCode);
         }  catch  (Exception e1) {
             e1.printStackTrace();
         }
 
         // 如果查询不到返回null
         if (sysUser== null ){ //
             return  null ;
         }
         // 从数据库查询到密码
         String password = sysUser.getPassword();
         
         //盐
         String salt = sysUser.getSalt();
 
         // 如果查询到返回认证信息AuthenticationInfo
         
         //activeUser就是用户身份信息
         ActiveUser activeUser =  new  ActiveUser();
         
         activeUser.setUserid(sysUser.getId());
         activeUser.setUsercode(sysUser.getUsercode());
         activeUser.setUsername(sysUser.getUsername());
         //..
         
         //根据用户id取出菜单
         List<SysPermission> menus  =  null ;
         try  {
             //通过service取出菜单 
             menus = sysService.findMenuListByUserId(sysUser.getId());
         }  catch  (Exception e) {
             e.printStackTrace();
         }
         //将用户菜单 设置到activeUser
         activeUser.setMenus(menus);
 
         //将activeUser设置simpleAuthenticationInfo
         SimpleAuthenticationInfo simpleAuthenticationInfo =  new  SimpleAuthenticationInfo(
                 activeUser, password,ByteSource.Util.bytes(salt),  this .getName());
 
         return  simpleAuthenticationInfo;
     }
     
     
 
     // 用于授权
     @Override
     protected  AuthorizationInfo doGetAuthorizationInfo(
             PrincipalCollection principals) {
         
         //从 principals获取主身份信息
         //将getPrimaryPrincipal方法返回值转为真实身份类型(在上边的doGetAuthenticationInfo认证通过填充到SimpleAuthenticationInfo中身份类型),
         ActiveUser activeUser =  (ActiveUser) principals.getPrimaryPrincipal();
         
         //根据身份信息获取权限信息
         //从数据库获取到权限数据
         List<SysPermission> permissionList =  null ;
         try  {
             permissionList = sysService.findMenuListByUserId(activeUser.getUserid());
         }  catch  (Exception e) {
             e.printStackTrace();
         }
         //单独定一个集合对象 
         List<String> permissions =  new  ArrayList<String>();
         if (permissionList!= null ){
             for (SysPermission sysPermission:permissionList){
                 //将数据库中的权限标签 符放入集合
                 permissions.add(sysPermission.getPercode());
             }
         }
         
         //查到权限数据,返回授权信息(要包括 上边的permissions)
         SimpleAuthorizationInfo simpleAuthorizationInfo =  new  SimpleAuthorizationInfo();
         //将上边查询到授权信息填充到simpleAuthorizationInfo对象中
         simpleAuthorizationInfo.addStringPermissions(permissions);
 
         return  simpleAuthorizationInfo;
     }
     
     //清除缓存
     public  void  clearCached() {
         PrincipalCollection principals = SecurityUtils.getSubject().getPrincipals();
         super .clearCache(principals);
     }
 
 
}

注意:先前的我们springmvc整合项目时候,先加载审springmvc:scan扫描是配置在springmvc里面,这个需要重新配置到spring

1
< param-value >classpath:spring/applicationContext-*.xml</ param-value >

配置

1
< context:component-scan  base-package = "com.ycy" />

到这个applicationContext-*.xml中里面,因为这个是第一加载顺序。


三、shrio实现登录退出实例

上面已经实现了整合,说白了就是加一个shrio的拦截器而已。真正的实现还没做,我们以登录退出来做一个实例。

3.1登录

使用FormAuthenticationFilter过虑器实现 ,原理如下:

将用户没有认证时,请求loginurl进行认证,用户身份和用户密码提交数据到loginurl

FormAuthenticationFilter拦截住取出request中的username和password(两个参数名称是可以配置的)

FormAuthenticationFilter调用realm传入一个token(username和password)

realm认证时根据username查询用户信息(在Activeuser中存储,包括 userid、usercode、username、menus)。

如果查询不到,realm返回null,FormAuthenticationFilter向request域中填充一个参数(记录了异常信息)


3.1.1  LoginController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package  com.ycy.controller;
 
import  com.ycy.Exception.CustomException;
import  com.ycy.model.ActiveUser;
import  com.ycy.service.SysService;
import  org.apache.shiro.authc.IncorrectCredentialsException;
import  org.apache.shiro.authc.UnknownAccountException;
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.stereotype.Controller;
import  org.springframework.web.bind.annotation.RequestMapping;
 
import  javax.servlet.http.HttpServletRequest;
import  javax.servlet.http.HttpSession;
 
/**
  * 
  * <p>Title: LoginController</p>
  * <p>Description: 登陆和退出</p>
  */
@Controller
public  class  LoginController {
     
     @Autowired
     private  SysService sysService;
     //用户登陆提交方法
     /*@RequestMapping("/login")
     public String login(HttpSession session,String usercode,String password,String randomcode)throws Exception{
 
         //校验验证码
         //从session获取正确的验证码
         String validateCode = (String)session.getAttribute("validateCode");
         if(!randomcode.equals(validateCode)){
             //抛出异常:验证码错误
             throw new CustomException("验证码 错误 !");
         }
         //用户身份认证
         ActiveUser activeUser = sysService.authenticat(usercode, password);
         //记录session
         session.setAttribute("activeUser", activeUser);
         //重定向到商品查询页面
         return "redirect:/first";
     }
 
     //用户退出
     @RequestMapping("/logout")
     public String logout(HttpSession session)throws Exception{
         //session失效
         session.invalidate();
         //重定向到商品查询页面
         return "redirect:/items/queryItems";
 
     }*/
     @RequestMapping ( "/login" )
     public   String login(HttpServletRequest request) throws  Exception{
         //如果登录失败从request中获取认证异常信息,shrioLoginFailure就是shiro异常类的全限定名
         String exceptionClassName = (String) request.getAttribute( "shiroLoginFailure" );
         //根据shrio返回的异常路径判断,抛出指定异常信息
         if  (exceptionClassName!= null ){
             if (UnknownAccountException. class .getName().equals(exceptionClassName)){
                 //抛出异常
                 throw  new  CustomException( "账户不存在" );
             } else  if (IncorrectCredentialsException. class .getName().equals(exceptionClassName)){
                 throw  new  CustomException( "用户名/密码错误" );
             }  else  {
                 throw  new  Exception( "未知错误" );
             }
         }
         return  "login" ;
     }
 
     
 
}

3.1.2 配置applicationContext-shiro.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package  com.ycy.controller;
 
import  com.ycy.Exception.CustomException;
import  com.ycy.model.ActiveUser;
import  com.ycy.service.SysService;
import  org.apache.shiro.authc.IncorrectCredentialsException;
import  org.apache.shiro.authc.UnknownAccountException;
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.stereotype.Controller;
import  org.springframework.web.bind.annotation.RequestMapping;
 
import  javax.servlet.http.HttpServletRequest;
import  javax.servlet.http.HttpSession;
 
/**
  * 
  * <p>Title: LoginController</p>
  * <p>Description: 登陆和退出</p>
  */
@Controller
public  class  LoginController {
     
     @Autowired
     private  SysService sysService;
     //用户登陆提交方法
     /*@RequestMapping("/login")
     public String login(HttpSession session,String usercode,String password,String randomcode)throws Exception{
 
         //校验验证码
         //从session获取正确的验证码
         String validateCode = (String)session.getAttribute("validateCode");
         if(!randomcode.equals(validateCode)){
             //抛出异常:验证码错误
             throw new CustomException("验证码 错误 !");
         }
         //用户身份认证
         ActiveUser activeUser = sysService.authenticat(usercode, password);
         //记录session
         session.setAttribute("activeUser", activeUser);
         //重定向到商品查询页面
         return "redirect:/first";
     }
 
     //用户退出
     @RequestMapping("/logout")
     public String logout(HttpSession session)throws Exception{
         //session失效
         session.invalidate();
         //重定向到商品查询页面
         return "redirect:/items/queryItems";
 
     }*/
     @RequestMapping ( "/login" )
     public   String login(HttpServletRequest request) throws  Exception{
         //如果登录失败从request中获取认证异常信息,shrioLoginFailure就是shiro异常类的全限定名
         String exceptionClassName=(String)request.getAttribute( "shiroLoginFailure" );
         //根据shrio返回的异常路径判断,抛出指定异常信息
         if  (exceptionClassName!= null ){
             if (UnknownAccountException. class .getName().equals(exceptionClassName)){
                 //抛出异常
                 throw  new  CustomException( "账户不存在" );
             }
         } else  if (IncorrectCredentialsException. class .getName().equals(exceptionClassName)){
                 throw  new  CustomException( "用户名/密码错误" );
         }
         return  "login" ;
     }
 
     
 
}

3.1.3 加入首页数据

1
2
3
4
5
6
7
8
9
10
//系统首页
@RequestMapping ( "/first" )
public  String first(Model model) throws  Exception{
     //从shiro的session中取出activeUser
     Subject subject= SecurityUtils.getSubject();
     ActiveUser activeUser=(ActiveUser)subject.getPrincipal();
     //通过model传送到页面
     model.addAttribute( "activeUser" ,activeUser);
     return  "first" ;
}

3.2 退出

退出我们已经用shiro的。很简单

1
2
       <!--请求logout,shrio擦除sssion-->
                 /logout=logout

展示页面:

shiro教程

3.3 总结登录退出实例5步走

1、web.xml配置shiroFileter拦截器

2、applicationContext-shiro配置:1、首先配置 shiroFileter  2、设置securityManager 3、设置过滤表达式 4、设置我们自己的realm

3、再配置loginController,根据异常返回用户认证错误信息

4、配置FristController,从securityUtil.getInstance(),加入环境。然后获取subject主体,再用属性注入到实体

5、在frist.jsp 获取controller传入的activeUser数据展示。

shiro整合spring项目实例 shiro整合spring项目实例,shiro整合spring项目实例,shiro整合spring项目实例 立即下载

相关推荐

Shiro整合Spring

Shiro整合Spring,maven,Shiro整合Spring,maven,Shiro整合Spring,maven,

shiro与springMVC整合

此realm先不从数据库查询权限数据/***** 自定义Realm***/@Override}// 支持什么类型的token@Override}/**** 获取授权信息*///先自定义一个query权限,就不从数据库查询了= null) {//权限}}/**** 获取认证信息** 问题:如何在登录后不再进登录页面了呢???????????????????????????*/// 通过表单接收的用户名= null &&!if (user!

web13985085406的博客 1112

spring+springMVC+shiro 完美例子

非常完美的spring+springMVC+shiro 完美例子实现权限认证,相信你一定会喜欢,里面有文档说明

Shiro集成Spring

1、Shiro集成Spring,使用maven进行jar包的依赖与管理,pom.xml的配置文件,如下所示: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://w...

HiterCoder 260

SpringMVC整合Shiro的完整示例代码下载

这是我的博文https://jadyer.github.io/2013/09/30/springmvc-shiro/里面知识点的可直接运行的完整代码

spring cloud + shiro集成方案

手把手教你集成spring cloud + shiro微服务框架;用最少的工作量,改造基于shiro安全框架的微服务项目,实现spring cloud + shiro 框架集成。博客地址:https://blog.youkuaiyun.com/weixin_42686388/article/details/103084289

shiro 整合 springmvc 实战及源码详解

针对每一个请求,shiro 会判断请求的 url 是否和我们指定的 url 匹配,并且调用对应的 filter,然后出发对应的方法。这一节我们讲解了如何整合 springmvc 与 shiro,可以发现 shiro 内置了非常多的实现,帮助我们简化登录的设计实现。还有比较常用的就是 form 表单提交,springboot 整合的时候甚至可以省略掉我们写的登录校验实现。当然,不同的用户登录的权限不同,肯定是因为我们定义了不同的权限。登录的校验非常简单,直接根据页面的账户密码,然后执行登录校验。

1084

用Arduino+ESP32复现TDOA定位:低成本实现厘米级精度的完整教程

本文提供了一套利用Arduino和ESP32平台,结合NRF24L01+模块与GPS/PPS时间同步方案,低成本复现高精度TDOA(到达时间差)定位系统的完整教程。教程详细阐述了从硬件选型、天线阵列设计、时间同步实现到核心算法与多径抑制的实战步骤,旨在帮助开发者和硬件爱好者以可控成本实现厘米级精度的定位演示系统。

weixin_29084111的博客 162

spring集成shiro详解

shiro说明 springboot集成shiro 前后端分离项目集成shiro shiro集成其他认证方式

u010752885的博客 7536

Python实战:如何用高德API批量获取POI数据(附完整代码)

本文详细介绍了如何使用Python通过高德API批量获取POI数据,包括API基础准备、核心功能模块设计、高级功能实现及实战应用案例。文章提供了完整代码示例,帮助开发者高效解决商业网点分析、公共设施规划等实际项目中的数据采集需求。

stem5的博客 324

content-pipeline:一条可落地的内容生产流水线

content-pipeline 是一种将内容创作工程化的系统性方法,其核心在于用确定性流程替代碎片化人工操作。它基于结构化提示(prompt)、预置叙事框架与品牌参数固化三大原理,实现从素材输入到多平台发布的端到端自动化。技术价值体现在显著降低认知负荷、保障输出一致性、支持本地化资源绑定与闭环反馈校验。典型应用场景包括技术教程批量生成、跨平台(公众号/小红书/即刻)内容适配、AI写作质量可控迭代等。本文深入解析其作为‘内容制造业’基础设施的底层设计逻辑与实操路径,尤其聚焦Claude Code环境下的真实

weixin_31199559的博客 269

SpringMVC整合Shiro

第一部分:SpringMVC框架的配置 配置步骤说明   (1)导入依赖的Jar包   (2)构建一个请求的界面   (3)创建业务控制器   (4)配置 web.xml 的核心控制器   (5)创建配置文件   (6)构建一个返回界面 第一步:导入依赖的Jar包    第二步:构建一个请求界面 1 <%@ page language="java" co...

banghaoqs409152的博客 214

DOA估计算法从原理到仿真——CBF、Capon、MUSIC算法

从原理出发理解并实现经典的DOA估计算法

m0_55845774的博客 1万+

谈谈 spring springMVC Shiro 整合流程

今天谈谈如题所说的三个框架的整合流程,Spring,SpringMVC我想大家都很熟悉了,下面简单介绍一下Shiro,废话不多说,注意红色标注的部分,开讲,有什么不对请各位提出交流改正; Shiro:Shiro是Apache下基于安全的一个框架,它可以帮助我们快速完成各个用户安全模块的搭建,使得系统更加安全稳定,Shiro主要重要组成模块如下: Authentication:身

ShiLuoHeroKing的博客 813

38、四旋翼无人机的机械建模、控制与仿真及小型无人机高度的最优鲁棒无模型控制

本文探讨了四旋翼无人机的机械建模、控制与仿真方法,采用基于PID控制器的分层控制策略实现稳定飞行与路径跟踪,并开发了结合CAD模型与MATLAB环境的飞行模拟器。同时,针对小型无人机高度控制问题,提出了一种基于粒子群优化(PSO)的最优鲁棒无模型控制(PSO-MFC)方法,有效解决了参数整定难题,实现了零稳态误差跟踪和强抗干扰能力。两种方法在仿真中均表现出良好性能,为无人机控制系统的设计与优化提供了理论与实践基础。

l6m7n8的博客 100

关于React Native Android找不到node的错误

最近,按照官方文档初始化了一个React Native项目,但是在Android端运行的时候,报了如下的一个错误。 org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:recordFilesBeforeBundleCommandDebug'. Caused by: org.gradle.process.internal.ExecException: A problem occurred starting p

xiangzhihong8的专栏 4247

Shiro整合SpringMVC

SpringMVC讲整合shiro

进击的小猴 202

SolidWorks速成教程P3-5【零件 | 第五节】——异形孔向导&线性阵列&镜像

这节介绍异形孔向导、线性阵列、镜像。

嵌入式阿齐Archie 6074

SpringMVC与Shiro快速整合

SpringMVC与Shiro快速整合: 好久没有重新整合Shiro框架了,为了方便以后参考查阅,特此将步骤分享出来,共同学习。 一、配置XML文件: 1、到相应的pom.xml中添加shiro相关依赖,注意这里没有版本号,因为在父模块中已经集中定义依赖版本号。 <!-- 添加Apache Shiro 依赖关系 --> <!-- shiro核心包 --> <dependency> <groupId>org.apache.s

QQ1941638512的博客 533

AMBA-CHI协议详解(七)

本节描述该协议包含的支持系统保序需求的机制。

Crazzy_M的博客 1158

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

maven项目中SSM+Shiro整合配置中,在有SpringMVC+MyBatis配置下整合shiro的配置步骤

最近在做SSM(SpringMVC+Shiro+MyBatis)整合的一个项目,对于shiro的配置不是特别熟练,于是想要写下来,加深一下印象。在有SpringMVC+MyBatis配置的基础上整合shiro:      首先进入shiro的官方网站(http://shiro.apache.org/),如下图所示(图中有提示下一步怎么操作):点击Download进入到下面这个页面:向下拖动,可以看

m0_37954004的博客 9283

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

上一篇: Java8 新特性之流式数据处理
下一篇: shiro的注解和缓存
SnakeMoving
博客等级 码龄11年 65粉丝 97原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值