Shiro知识点备忘录
1、Shiro手动认证
Subject currentUser = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(user.getUserName(), user.getPassword()); // 开始进入shiro的认证流程 currentUser.login(token)
2、Shiro免密码登录
//获取用户信息,可以使用token等其它唯一字段获取用户信息 SystemService systemService = SpringContextHolder.getBean(SystemService.class); User user = systemService.getUserByLoginName("sheungxin"); //定义授权用户信息,Principal为自定义授权用户基本信息 PrincipalCollection principals = new SimplePrincipalCollection(new Principal(user,false), "MobileRealm"); ServletRequestAttributes servletRequestAttributes=(ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); //创建WebSubject,根据自己的应用选择需要创建的Subject类 Builder builder = new WebSubject.Builder( servletRequestAttributes.getRequest(), servletRequestAttributes.getResponse()); builder.principals(principals); builder.authenticated(true); WebSubject subject = builder.buildWebSubject(); //为shiro线程变量绑定Subject ThreadContext.bind(subject);
3、Shiro登录成功之后跳到指定URL
引用
相关推荐
杜鲁门 2020-11-05
luckyxl0 2020-08-16
Dullonjiang 2020-08-09
xclxcl 2020-08-03
zmzmmf 2020-08-03
MicroBoy 2020-08-02
ganjing 2020-08-02
likesyour 2020-08-01
zmzmmf 2020-07-09
MicroBoy 2020-07-05
zzhao 2020-06-26
子云 2020-06-18
visionzheng 2020-06-07
neweastsun 2020-06-04
ErixHao 2020-06-03
GDreams0 2020-06-01
ganjing 2020-05-29
zmzmmf 2020-05-28
nullcy 2020-05-26