1
1
package com .study .config .shiro ;
2
2
3
+ import com .github .pagehelper .PageInfo ;
3
4
import com .github .pagehelper .util .StringUtil ;
4
5
import com .study .model .Resources ;
6
+ import com .study .model .User ;
5
7
import com .study .service .ResourcesService ;
8
+ import com .study .service .UserService ;
6
9
import org .apache .shiro .authc .credential .HashedCredentialsMatcher ;
7
10
import org .apache .shiro .spring .LifecycleBeanPostProcessor ;
8
11
import org .apache .shiro .spring .security .interceptor .AuthorizationAttributeSourceAdvisor ;
9
12
import org .apache .shiro .spring .web .ShiroFilterFactoryBean ;
13
+ import org .springframework .beans .factory .BeanFactory ;
10
14
import org .springframework .beans .factory .annotation .Autowired ;
11
15
import org .springframework .context .annotation .Bean ;
12
16
import org .springframework .context .annotation .Configuration ;
13
17
import org .apache .shiro .web .mgt .DefaultWebSecurityManager ;
14
18
import org .apache .shiro .mgt .SecurityManager ;
19
+ import org .springframework .web .context .support .WebApplicationContextUtils ;
20
+ import tk .mybatis .mapper .entity .Example ;
15
21
16
22
import javax .annotation .Resource ;
17
23
import java .util .LinkedHashMap ;
23
29
*/
24
30
@ Configuration
25
31
public class ShiroConfig {
26
- @ Autowired ( required = false )
32
+ @ Resource
27
33
private ResourcesService resourcesService ;
28
34
35
+ @ Resource
36
+ private UserService userService ;
37
+
29
38
/**
30
39
* ShiroFilterFactoryBean 处理拦截资源文件问题。
31
40
* 注意:单独一个ShiroFilterFactoryBean配置是或报错的,因为在
@@ -47,7 +56,7 @@ public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager){
47
56
// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
48
57
shiroFilterFactoryBean .setLoginUrl ("/login" );
49
58
// 登录成功后要跳转的链接
50
- shiroFilterFactoryBean .setSuccessUrl ("/user " );
59
+ shiroFilterFactoryBean .setSuccessUrl ("/usersPage " );
51
60
//未授权界面;
52
61
shiroFilterFactoryBean .setUnauthorizedUrl ("/403" );
53
62
//拦截器.
@@ -63,15 +72,18 @@ public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager){
63
72
//<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
64
73
filterChainDefinitionMap .put ("/user" , "authc" );
65
74
//自定义加载权限资源关系
66
- List <Resources > resourcesList = resourcesService .selectByExample (new Resources ());
67
- for (Resources resources :resourcesList ){
75
+ /* List<Resources> resourcesList = resourcesService.selectByExample(new Example(Resources.class));*/
76
+ /* PageInfo<Resources> pageInfo = resourcesService.selectByPage(new Resources(), 1, 20);*/
77
+ User user = userService .selectByUsername ("admin" );
78
+ System .out .println (user .getUsername ()+"======" );
79
+ /* for(Resources resources:resourcesList){
68
80
69
81
if (StringUtil.isNotEmpty(resources.getResurl())&& StringUtil.isNotEmpty(resources.getReskey())) {
70
82
String permission = "perms[" + resources.getReskey()+ "]";
71
83
System.out.println(resources.getResurl()+"---"+permission);
72
84
filterChainDefinitionMap.put(resources.getResurl(),permission);
73
85
}
74
- }
86
+ }*/
75
87
filterChainDefinitionMap .put ("/**" , "authc" );
76
88
77
89
@@ -91,7 +103,7 @@ public SecurityManager securityManager(){
91
103
@ Bean
92
104
public MyShiroRealm myShiroRealm (){
93
105
MyShiroRealm myShiroRealm = new MyShiroRealm ();
94
- myShiroRealm .setCredentialsMatcher (hashedCredentialsMatcher ());;
106
+ myShiroRealm .setCredentialsMatcher (hashedCredentialsMatcher ());
95
107
return myShiroRealm ;
96
108
}
97
109
0 commit comments