package com.zking;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
public class Demo {
//权限
public static void main(String[] args) {
//1.读取加载shiro.ini配置文件
IniSecurityManagerFactory is=new IniSecurityManagerFactory("classpath:shiro-permission.ini");
//2.创建SecurityManager安全管理器
SecurityManager instance = is.createInstance();
//3.将SecurityManager委托给SecurityUtils管理
SecurityUtils.setSecurityManager(instance);
//4.获取主体
Subject subject=SecurityUtils.getSubject();
//创建登录令牌
UsernamePasswordToken token=new UsernamePasswordToken("zs","123");
try {
subject.login(token);
//权限验证 是否又修改的权限
if(subject.isPermitted("user:update")){
System.out.println("具有修改的权限");
}
} catch (UnknownAccountException e) {
System.out.println("名字不存在");
}catch (IncorrectCredentialsException e){
System.out.println("密码错误");
}
}
//角色登录 shiro-role.ini
public static void main2(String[] args) {
//1.读取加载shiro.ini配置文件
IniSecurityManagerFactory is=new IniSecurityManagerFactory("classpath:shiro-role.ini");
//2.创建SecurityManager安全管理器
SecurityManager instance = is.createInstance();
//3.将SecurityManager委托给SecurityUtils管理
SecurityUtils.setSecurityManager(instance);
//4.获取主体
Subject subject=SecurityUtils.getSubject();
//创建登录令牌
UsernamePasswordToken token=new UsernamePasswordToken("ls","123");
try {
subject.login(token);
//角色验证
if(subject.hasRole("role1")){
System.out.println("角色1,管理员");
}
if(subject.hasRole("role2")){
System.out.println("角色2,普通用户");
}
if(subject.hasRole("role3")){
System.out.println("角色3,普通用户");
}
} catch (UnknownAccountException e) {
System.out.println("名字不存在");
}catch (IncorrectCredentialsException e){
System.out.println("密码错误");
}
}
//登录密码验证 shiro.ini
public static void main1(String[] args) {
//1.读取加载shiro.ini配置文件
IniSecurityManagerFactory is=new IniSecurityManagerFactory("classpath:shiro.ini");
//2.创建SecurityManager安全管理器
SecurityManager securityManager = is.createInstance();
//3.将SecurityManager委托给SecurityUtils管理
SecurityUtils.setSecurityManager(securityManager);
//4.获取主体
Subject subject = SecurityUtils.getSubject();
//创建令牌登录
UsernamePasswordToken token=new UsernamePasswordToken("zs","123");
//拿着令牌找体登录
try {
subject.login(token);
System.out.println("登录成功");
} catch (UnknownAccountException e) {
System.out.println("名字不存在");
}catch (IncorrectCredentialsException e){
System.out.println("密码错误");
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
shiro权限认证和授权
共299个文件
jar:53个
xml:43个
jsp:30个
需积分: 10 0 下载量 140 浏览量
2022-02-26
22:22:20
上传
评论 1
收藏 19.06MB ZIP 举报
温馨提示
shiro权限认证和授权
资源详情
资源评论
资源推荐
收起资源包目录
shiro权限认证和授权 (299个子文件)
03bb966cf399c439159fd27265596cb32a2d62 2KB
03fc7fd2584bbfd411a1b4c44d02c9143059cb 129B
05f792ee91a0134662800d6045510a1eb7c636 57B
067bbda4288dea4e757800869d74bd31657e8b 198B
0867fd059ff17f4f595628d9051f32e796fc07 437B
09804a7b8a7136dba9d833824bad24e3610a69 109B
0984e8058dd55615a2c62db876269fa518d126 46B
0ba9c3a765a5fd3104f73aa2f0f223b61f6ea5 47B
10d52d88e725dc82c3cc5b16a71d2ea00ab1bc 2KB
13fe73ad36a01e8309986fb99cfa5b6b17b653 47B
15d205b358a2aac6e5abbb7eaa1fe17eae2f8f 117B
15d996e66f0144d9f45c80720d48dfef0633e9 64B
160a8c73df09ed07316a3e196e6d4a96cf27c3 47B
1784a1dfac4d20c5af054f5c16252c01114d7f 45B
192644ab4f0a50f436b64d9c189b3521b9f32a 415B
1a562cc4dad11432277687fb10900d0260e5e3 198B
1addc79ac861bae24ede392cc1bde75da5bec0 54B
1e4876880231d2f365c9782919df0ed68e6bd8 198B
1e73349336836f91b2b8d3f05dd6e3971a52e2 174B
26c8e191b8d14763d6d67577b346d12e270277 380B
32c3013e6f8eb31ed9e029ae790be663bcc9d4 125B
34ea9f5c6c89f8cf9b38139781629fb858222e 1KB
37ed8a9facc5801df23916aaefc54838003506 979B
42247629c486570d3bb2d2e0444c1ef4ca63d0 180B
427345f5aac38d61eec4af202c550ce68f35da 184B
4289df7500a556ea155fdc0d866a5b5fc2d36b 48B
43b2cb5f32baf576797ccf594cef296da9ebd1 1KB
4492169231b24cb6d389a32a1d2f3c46c4f1d4 176B
4823af97eefaf6813eaf4794c6a1fbd2061cbf 60B
48430236911308e411ea468f0f755b140d41fd 162B
4bba2a93aa3973635ac8ce450d85750227165c 2KB
4c40a9125fd5ec11dd33e3a093e2eb185cf5e4 46B
4ceb2dd831c710e32ddcc654817303937e5e06 93B
57a2304858f37cb2300bc1178b936f24130f64 406B
5b4954d3791928b32220887464c240ee662931 47B
61638efd1437b423b270ed41bcd59b7fa6013d 111B
6a718755ef782d2a0e3385740742ef2096cbae 317B
6d59d457068988241915ba240a5c96c67ebbf6 198B
6ef089e2ed1fc989b427c2f3193194aaf09142 155B
72271144c58bd6a584eae01060bd2885ceec77 108B
73a9fc80ec51876acc688104fad2edc5a8a1e1 47B
760b0214b3604065c95c62b3639067b6018db8 1KB
789e332eeaf7b59dbb31c6a69e2aaac6d00716 467B
7d7725aca7c1aa408965892b9128dc7bc4de04 198B
7fb303d77e40a97df1f875563b38415741a032 732B
808b8ddc0290ed39bedce7230b892027288f11 175B
8169bb958579c635a5c09ee2f379cc5956c0c2 56B
82c810b9fd1cd8cddae1c6d0ddc0d12b3cbf7c 445B
88e0dc89c378afd63f3a6011f1578422ae9bcb 46B
890dc0e4a32d27b402e265bb53090747f37238 181B
89cb48937414b89f9e5af03fb344e607e51ee9 329B
8bae935be82e26a76ccee4667d4d9ceaa328b3 318B
8dded7680331e734d00f25f9a060e411921a44 155B
8eb2af6a40e06a9e30843c7972c06f8742c0f4 2KB
8fcf2b51f4de9f3c78d90d6cf66ca07e23ce8a 59B
9019a77f3f04b2c131a0320bb18f4a9719eaec 332B
907aacdfc9dd453981e23171209d9d6ee27ed6 65B
97bbd9a11f7f41586bd60a826d4fcdf37cd5ea 110B
98b428844d9f7d529e2b6fb918d15bf072f3df 54B
9b9ffe3a4cd7360c0a3c2c14a0209d25cca69b 401B
9d0e361be2e0c1c41ce445a22e1f2ff309ca45 292B
9e737b47abc853cdb476a5d02f54bcfde64c62 162B
9ee1d4938a7cce76fe47cc4a12e0a9fdcb909a 180B
a25f7f4cb416c083d265558da75d457237d671 155B
a7ef9cb6ff1b3fe25671f53cdb0b8c58ad48da 45B
acc6b72336f4a09c85d29ebbc6d6c0d248768b 156B
b2169f0c1c27f3a2fdd62f40b1cd2e8f1bd292 901B
b3d64b37674ce7147ebcffa271cf0bdcb77e13 1KB
b4c808db613d3eddad12acfa4e5f5e7f720a49 366B
b735d574493fd74d6d50a192dc9e72cecbb89e 111B
b8d2ff0bed188fc927fee6cbe01b1139e27f70 45B
bad0eb62996e971bddbdbeeb689fb61c153ceb 47B
bd9f89b81cfee27747afb7ebc65da472a0fad3 121B
bdd18dfea9d9641959378bbb93a569e3533ea7 47B
bfc1a872bb763fcb9a27b894c0305ee9282383 46B
c7d726c0bacb971eef9f2ee17f42c29dd4c88d 111B
c8759e0a6fc9f5ca63d6292ba1c4957e40a468 299B
c9ad6ff227dac2d42d00b47f96c587926481e7 164B
cadf9af719673493994d5df87c2c8ee51f168b 60B
cb26b8370239a7685ab0bce9dfcf64e7d334b3 46B
cfd41652f1feb67b2e31e58b4de1827adc4354 441B
Demo.class 3KB
Demo.class 3KB
MyRealm.class 3KB
MyRealm.class 3KB
LoginController.class 3KB
LoginController.class 3KB
UserServiceImpl.class 2KB
UserServiceImpl.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
PasswordHelper.class 2KB
PasswordHelper.class 2KB
UserController.class 2KB
UserController.class 2KB
User.class 2KB
User.class 2KB
IndexController.class 1KB
IndexController.class 1KB
IUserService.class 827B
共 299 条
- 1
- 2
- 3
鑫品
- 粉丝: 132
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0