Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
chnmuseum-party
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liqin
chnmuseum-party
Commits
75216294
Commit
75216294
authored
Mar 12, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
c8b6d05c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
15 deletions
+44
-15
pom.xml
pom.xml
+6
-0
MyShiroRealm.java
...cn/wisenergy/chnmuseum/party/auth/realm/MyShiroRealm.java
+0
-2
ShiroConfig.java
...n/java/cn/wisenergy/chnmuseum/party/conf/ShiroConfig.java
+38
-13
No files found.
pom.xml
View file @
75216294
...
@@ -173,6 +173,12 @@
...
@@ -173,6 +173,12 @@
<groupId>
org.crazycake
</groupId>
<groupId>
org.crazycake
</groupId>
<artifactId>
shiro-redis
</artifactId>
<artifactId>
shiro-redis
</artifactId>
<version>
3.3.1
</version>
<version>
3.3.1
</version>
<exclusions>
<exclusion>
<groupId>
org.apache.shiro
</groupId>
<artifactId>
shiro-core
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<!--<dependency>
<!--<dependency>
<groupId>redis.clients</groupId>
<groupId>redis.clients</groupId>
...
...
src/main/java/cn/wisenergy/chnmuseum/party/auth/realm/MyShiroRealm.java
View file @
75216294
...
@@ -70,8 +70,6 @@ public class MyShiroRealm extends AuthorizingRealm {
...
@@ -70,8 +70,6 @@ public class MyShiroRealm extends AuthorizingRealm {
* 认证信息.(身份验证) : Authentication 是用来验证用户身份
* 认证信息.(身份验证) : Authentication 是用来验证用户身份
*
*
* @param auth
* @param auth
* @return
* @throws AuthenticationException
*/
*/
@Override
@Override
protected
AuthenticationInfo
doGetAuthenticationInfo
(
AuthenticationToken
auth
)
throws
AuthenticationException
{
protected
AuthenticationInfo
doGetAuthenticationInfo
(
AuthenticationToken
auth
)
throws
AuthenticationException
{
...
...
src/main/java/cn/wisenergy/chnmuseum/party/conf/ShiroConfig.java
View file @
75216294
...
@@ -7,7 +7,6 @@ import cn.wisenergy.chnmuseum.party.service.PermissionInitService;
...
@@ -7,7 +7,6 @@ import cn.wisenergy.chnmuseum.party.service.PermissionInitService;
import
org.apache.shiro.mgt.DefaultSessionStorageEvaluator
;
import
org.apache.shiro.mgt.DefaultSessionStorageEvaluator
;
import
org.apache.shiro.mgt.DefaultSubjectDAO
;
import
org.apache.shiro.mgt.DefaultSubjectDAO
;
import
org.apache.shiro.mgt.SecurityManager
;
import
org.apache.shiro.mgt.SecurityManager
;
import
org.apache.shiro.mgt.SessionsSecurityManager
;
import
org.apache.shiro.spring.LifecycleBeanPostProcessor
;
import
org.apache.shiro.spring.LifecycleBeanPostProcessor
;
import
org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor
;
import
org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor
;
import
org.apache.shiro.spring.web.ShiroFilterFactoryBean
;
import
org.apache.shiro.spring.web.ShiroFilterFactoryBean
;
...
@@ -22,6 +21,7 @@ import org.springframework.context.annotation.Bean;
...
@@ -22,6 +21,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.DependsOn
;
import
org.springframework.context.annotation.DependsOn
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
redis.clients.jedis.JedisPoolConfig
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.Filter
;
import
javax.servlet.Filter
;
...
@@ -34,21 +34,25 @@ import java.util.Map;
...
@@ -34,21 +34,25 @@ import java.util.Map;
public
class
ShiroConfig
{
public
class
ShiroConfig
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ShiroConfig
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ShiroConfig
.
class
);
private
static
final
String
CACHE_KEY
=
"shiro:cache:"
;
@Resource
@Resource
private
PermissionInitService
permissionInitService
;
private
PermissionInitService
permissionInitService
;
@Value
(
"${spring.redis.host}"
)
@Value
(
"${spring.redis.host}"
)
private
String
host
;
private
String
host
;
@Value
(
"${spring.redis.port}"
)
@Value
(
"${spring.redis.port}"
)
private
int
port
;
private
int
port
;
@Value
(
"${spring.redis.timeout}"
)
@Value
(
"${spring.redis.timeout}"
)
private
int
timeout
;
private
int
timeout
;
@Value
(
"${spring.redis.password}"
)
@Value
(
"${spring.redis.password}"
)
private
String
password
;
private
String
password
;
@Value
(
"${spring.redis.jedis.pool.min-idle}"
)
private
int
minIdle
;
@Value
(
"${spring.redis.jedis.pool.max-idle}"
)
private
int
maxIdle
;
@Value
(
"${spring.redis.jedis.pool.max-active}"
)
private
int
maxActive
;
/**
/**
* ShiroFilterFactoryBean 处理拦截资源文件问题。
* ShiroFilterFactoryBean 处理拦截资源文件问题。
...
@@ -95,13 +99,13 @@ public class ShiroConfig {
...
@@ -95,13 +99,13 @@ public class ShiroConfig {
}
}
@Bean
@Bean
public
Sessions
SecurityManager
securityManager
()
{
public
DefaultWeb
SecurityManager
securityManager
()
{
logger
.
info
(
"ShiroConfiguration.securityManager()"
);
logger
.
info
(
"ShiroConfiguration.securityManager()"
);
DefaultWebSecurityManager
securityManager
=
new
DefaultWebSecurityManager
();
DefaultWebSecurityManager
securityManager
=
new
DefaultWebSecurityManager
();
// 设置realm
// 设置realm
securityManager
.
setRealm
(
myShiroRealm
());
securityManager
.
setRealm
(
myShiroRealm
());
// 自定义缓存实现 使用redis
// 自定义缓存实现 使用redis
securityManager
.
setCacheManager
(
redisC
acheManager
());
securityManager
.
setCacheManager
(
c
acheManager
());
// 关闭shiro自带的session
// 关闭shiro自带的session
DefaultSubjectDAO
subjectDAO
=
new
DefaultSubjectDAO
();
DefaultSubjectDAO
subjectDAO
=
new
DefaultSubjectDAO
();
...
@@ -117,6 +121,20 @@ public class ShiroConfig {
...
@@ -117,6 +121,20 @@ public class ShiroConfig {
*/
*/
@Bean
@Bean
public
MyShiroRealm
myShiroRealm
()
{
public
MyShiroRealm
myShiroRealm
()
{
MyShiroRealm
myShiroRealm
=
myShiroRealm
();
//开启全局缓存配置
myShiroRealm
.
setCachingEnabled
(
true
);
//启用身份验证缓存,即缓存AuthenticationInfo信息,默认false
myShiroRealm
.
setAuthenticationCachingEnabled
(
true
);
//启用授权缓存,即缓存AuthorizationInfo信息,默认false
myShiroRealm
.
setAuthorizationCachingEnabled
(
true
);
//为了方便操作,我们给缓存起个名字
myShiroRealm
.
setAuthenticationCacheName
(
"authcCache"
);
myShiroRealm
.
setAuthorizationCacheName
(
"authzCache"
);
//注入缓存实现
myShiroRealm
.
setCacheManager
(
cacheManager
());
return
new
MyShiroRealm
();
return
new
MyShiroRealm
();
}
}
...
@@ -158,28 +176,35 @@ public class ShiroConfig {
...
@@ -158,28 +176,35 @@ public class ShiroConfig {
}
}
/**
/**
* 配置shiro redisManager
* 配置Redis管理器
* <p>
* @Attention 使用的是shiro-redis开源插件
* 使用的是shiro-redis开源插件
*
* @return
* @return
*/
*/
@Bean
public
RedisManager
redisManager
()
{
public
RedisManager
redisManager
()
{
RedisManager
redisManager
=
new
RedisManager
();
RedisManager
redisManager
=
new
RedisManager
();
redisManager
.
setHost
(
host
);
redisManager
.
setHost
(
host
);
redisManager
.
setTimeout
(
timeout
);
redisManager
.
setTimeout
(
timeout
);
redisManager
.
setPassword
(
password
);
redisManager
.
setPassword
(
password
);
JedisPoolConfig
jedisPoolConfig
=
new
JedisPoolConfig
();
jedisPoolConfig
.
setMaxTotal
(
maxIdle
+
maxActive
);
jedisPoolConfig
.
setMaxIdle
(
maxIdle
);
jedisPoolConfig
.
setMinIdle
(
minIdle
);
redisManager
.
setJedisPoolConfig
(
jedisPoolConfig
);
return
redisManager
;
return
redisManager
;
}
}
/**
/**
* 用户授权信息Cache, 采用Redis
* 用户授权信息Cache, 采用Redis
*
* @return
*/
*/
public
RedisCacheManager
redisCacheManager
()
{
@Bean
public
RedisCacheManager
cacheManager
()
{
RedisCacheManager
redisCacheManager
=
new
RedisCacheManager
();
RedisCacheManager
redisCacheManager
=
new
RedisCacheManager
();
redisCacheManager
.
setRedisManager
(
redisManager
());
redisCacheManager
.
setRedisManager
(
redisManager
());
redisCacheManager
.
setKeyPrefix
(
CACHE_KEY
);
// shiro-redis要求放在session里面的实体类必须有个id标识
//这是组成redis中所存储数据的key的一部分
redisCacheManager
.
setPrincipalIdFieldName
(
"id"
);
return
redisCacheManager
;
return
redisCacheManager
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment