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
public class MyJdbcAuthzService implements JdbcAuthzService {
@Override
public Map
//加载数据库的url配置
Map
// Map
// new Comparator
// public int compare(String k1, String k2) {
// return new Integer(k2.length()).compareTo(k1.length());
// }
//
// });
//遍历角色
List
List
for (Role role : roles) {
//角色可用
if (role.getDate("daleted_at") == null) {
permissions = Permission.dao.findByRole("", role.get("id"));
//遍历权限
for (Permission permission : permissions) {
//权限可用
if (permission.getDate("daleted_at") == null) {
if (permission.getStr("url") != null && !permission.getStr("url").isEmpty()) {
authzJdbcMaps.put(permission.getStr("url"), new JdbcPermissionAuthzHandler(permission.getStr("value")));
}
}
}
}
}
return authzJdbcMaps;
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--create role--
INSERT INTO sec_role(id,name, value, intro, pid,left_code,right_code,created_at)
VALUES (sec_role_id_seq.nextval,'超级管理员','R_ADMIN','',0,1,8, current_timestamp),
(sec_role_id_seq.nextval,'系统管理员','R_MANAGER','',1,2,7,current_timestamp),
(sec_role_id_seq.nextval,'会员','R_MEMBER','',2,3,4,current_timestamp),
(sec_role_id_seq.nextval,'普通用户','R_USER','',2,5,6,current_timestamp);
--create permission--
INSERT INTO sec_permission(id, name, value, url, intro,pid,left_code,right_code, created_at)
VALUES (sec_permission_id_seq.nextval,'管理员目录','P_D_ADMIN','/admin/**','',0,1,6,current_timestamp),
(sec_permission_id_seq.nextval,'角色权限管理','P_ROLE','/admin/role/**','',1,2,3,current_timestamp),
(sec_permission_id_seq.nextval,'用户管理','P_USER','/admin/user/**','',1,4,5,current_timestamp),
(sec_permission_id_seq.nextval,'会员目录','P_D_MEMBER','/member/**','',0,9,10,current_timestamp),
(sec_permission_id_seq.nextval,'普通用户目录','P_D_USER','/user/**','',0,11,12,current_timestamp);
//如果系统不重启需要加载新权限到全局过滤
ShiroKit.addJdbcAuthz(authority.getStr("url"),authority.getStr("auth_key"));