|
@@ -1,22 +1,20 @@
|
|
|
package cn.gygxzc.envir.config.shiro
|
|
|
|
|
|
-import cn.gygxzc.envir.config.jwt.JwtConfig
|
|
|
-import cn.gygxzc.envir.config.shiro.cache.JwtRedisCache
|
|
|
import cn.gygxzc.envir.config.shiro.cache.RedisConfiguration
|
|
|
-import cn.gygxzc.envir.config.shiro.cache.ShiroRedisSessionDAO
|
|
|
-import cn.gygxzc.envir.config.shiro.filter.*
|
|
|
+import cn.gygxzc.envir.config.shiro.filter.AjaxAuthorizationFilter
|
|
|
+import cn.gygxzc.envir.config.shiro.filter.UrlPermissionsFilter
|
|
|
+import cn.gygxzc.envir.config.shiro.filter.ZenCorsAnonymousFilter
|
|
|
+import cn.gygxzc.envir.config.shiro.filter.ZenCorsPathMatchingFilter
|
|
|
import cn.gygxzc.envir.config.shiro.realm.ZenShiroRealm
|
|
|
-import cn.gygxzc.envir.config.shiro.session.ZenWebSessionManager
|
|
|
import org.apache.shiro.authc.credential.HashedCredentialsMatcher
|
|
|
import org.apache.shiro.cache.CacheManager
|
|
|
import org.apache.shiro.mgt.SecurityManager
|
|
|
import org.apache.shiro.realm.AuthorizingRealm
|
|
|
-import org.apache.shiro.session.mgt.SessionManager
|
|
|
import org.apache.shiro.spring.LifecycleBeanPostProcessor
|
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean
|
|
|
import org.apache.shiro.web.filter.authc.AnonymousFilter
|
|
|
import org.apache.shiro.web.mgt.DefaultWebSecurityManager
|
|
|
-import org.apache.shiro.web.servlet.SimpleCookie
|
|
|
+import org.apache.shiro.web.session.mgt.ServletContainerSessionManager
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean
|
|
|
import org.springframework.context.annotation.Bean
|
|
@@ -61,31 +59,13 @@ class ShiroConfig {
|
|
|
return shiroRealm
|
|
|
}
|
|
|
|
|
|
- @Bean(name = ["sessionManager"])
|
|
|
- fun defaultWebSessionManager(redisCacheManager: CacheManager,
|
|
|
- redisSessionDAO: ShiroRedisSessionDAO): ZenWebSessionManager {
|
|
|
- return ZenWebSessionManager().apply {
|
|
|
- setCacheManager(redisCacheManager)
|
|
|
- globalSessionTimeout = 604800 * 1000
|
|
|
- isDeleteInvalidSessions = true
|
|
|
- isSessionValidationSchedulerEnabled = true
|
|
|
- isDeleteInvalidSessions = true
|
|
|
- sessionDAO = redisSessionDAO
|
|
|
- sessionIdCookie = SimpleCookie(ZenHttpSession.DEFAULT_SESSION_ID_NAME).apply {
|
|
|
- isHttpOnly = true
|
|
|
- maxAge = 604800
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Bean(name = ["securityManager"])
|
|
|
fun securityManager(userRealm: AuthorizingRealm,
|
|
|
- redisCacheManager: CacheManager,
|
|
|
- sessionManager: SessionManager): DefaultWebSecurityManager {
|
|
|
+ redisCacheManager: CacheManager): DefaultWebSecurityManager {
|
|
|
return DefaultWebSecurityManager().apply {
|
|
|
setRealm(userRealm)
|
|
|
cacheManager = redisCacheManager
|
|
|
- setSessionManager(sessionManager)
|
|
|
+ sessionManager = ServletContainerSessionManager()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -102,8 +82,7 @@ class ShiroConfig {
|
|
|
|
|
|
@Bean(name = ["shiroFilter"])
|
|
|
@Order(2)
|
|
|
- fun shiroFilter(securityManager: SecurityManager,
|
|
|
- config: JwtConfig, jwtRedisCache: JwtRedisCache): ShiroFilterFactoryBean {
|
|
|
+ fun shiroFilter(securityManager: SecurityManager): ShiroFilterFactoryBean {
|
|
|
return ShiroFilterFactoryBean().apply {
|
|
|
setSecurityManager(securityManager)
|
|
|
|
|
@@ -112,8 +91,7 @@ class ShiroConfig {
|
|
|
"cors" to ZenCorsPathMatchingFilter(),
|
|
|
"perms" to UrlPermissionsFilter(),
|
|
|
"authc" to AjaxAuthorizationFilter(),
|
|
|
- "anon" to AnonymousFilter(),
|
|
|
- "jwt" to JwtPathMatchingFilter(config, jwtRedisCache)
|
|
|
+ "anon" to AnonymousFilter()
|
|
|
)
|
|
|
/**
|
|
|
* anon(匿名) org.apache.shiro.web.filter.authc.AnonymousFilter
|
|
@@ -153,7 +131,7 @@ class ShiroConfig {
|
|
|
"/eureka/**" to "anon",
|
|
|
"/v1/sys" to "anon",
|
|
|
////////////////////// 静态资源 /////////////////////
|
|
|
- "/**" to "cors,jwt,authc" // 对于其他未配置的所有url 先设置cors头 再进行登陆判定 最后判定权限
|
|
|
+ "/**" to "cors,authc" // 对于其他未配置的所有url 先设置cors头 再进行登陆判定 最后判定权限
|
|
|
)
|
|
|
}
|
|
|
}
|