1
1
package com .study .config ;
2
2
3
+ import at .pollux .thymeleaf .shiro .dialect .ShiroDialect ;
3
4
import com .github .pagehelper .util .StringUtil ;
4
5
import com .study .model .Resources ;
5
6
import com .study .service .ResourcesService ;
6
7
import com .study .shiro .MyShiroRealm ;
7
8
import org .apache .shiro .authc .credential .HashedCredentialsMatcher ;
8
9
import org .apache .shiro .mgt .SecurityManager ;
9
- import org .apache .shiro .spring .LifecycleBeanPostProcessor ;
10
10
import org .apache .shiro .spring .security .interceptor .AuthorizationAttributeSourceAdvisor ;
11
11
import org .apache .shiro .spring .web .ShiroFilterFactoryBean ;
12
12
import org .apache .shiro .web .mgt .DefaultWebSecurityManager ;
13
13
import org .springframework .beans .factory .annotation .Autowired ;
14
14
import org .springframework .context .annotation .Bean ;
15
15
import org .springframework .context .annotation .Configuration ;
16
- import tk .mybatis .mapper .entity .Example ;
17
16
18
17
import java .util .LinkedHashMap ;
19
18
import java .util .List ;
@@ -27,6 +26,14 @@ public class ShiroConfig {
27
26
@ Autowired (required = false )
28
27
private ResourcesService resourcesService ;
29
28
29
+ /**
30
+ * ShiroDialect,为了在thymeleaf里使用shiro的标签的bean
31
+ * @return
32
+ */
33
+ @ Bean
34
+ public ShiroDialect shiroDialect () {
35
+ return new ShiroDialect ();
36
+ }
30
37
/**
31
38
* ShiroFilterFactoryBean 处理拦截资源文件问题。
32
39
* 注意:单独一个ShiroFilterFactoryBean配置是或报错的,因为在
@@ -62,14 +69,12 @@ public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager){
62
69
filterChainDefinitionMap .put ("/font-awesome/**" ,"anon" );
63
70
//<!-- 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
64
71
//<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
65
- filterChainDefinitionMap .put ("/user" , "authc" );
66
72
//自定义加载权限资源关系
67
73
List <Resources > resourcesList = resourcesService .queryAll ();
68
74
for (Resources resources :resourcesList ){
69
75
70
- if (StringUtil .isNotEmpty (resources .getResurl ())&& StringUtil .isNotEmpty (resources .getReskey ())) {
71
- String permission = "perms[" + resources .getReskey ()+ "]" ;
72
- System .out .println (resources .getResurl ()+"---" +permission );
76
+ if (StringUtil .isNotEmpty (resources .getResurl ())) {
77
+ String permission = "perms[" + resources .getResurl ()+ "]" ;
73
78
filterChainDefinitionMap .put (resources .getResurl (),permission );
74
79
}
75
80
}
@@ -127,5 +132,15 @@ public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(S
127
132
return authorizationAttributeSourceAdvisor ;
128
133
}
129
134
135
+ /**
136
+ * cacheManager 缓存 redis实现
137
+ * 使用的是shiro-redis开源插件
138
+ * @return
139
+ */
140
+ public RedisCacheManager cacheManager () {
141
+ RedisCacheManager redisCacheManager = new RedisCacheManager ();
142
+ redisCacheManager .setRedisManager (redisManager ());
143
+ return redisCacheManager ;
144
+ }
130
145
131
146
}
0 commit comments