|
@@ -2,14 +2,10 @@ package com.gis.admin.shiro;
|
|
|
|
|
|
import com.gis.admin.shiro.filters.CustomShiroFilterFactoryBean;
|
|
|
import com.gis.admin.shiro.filters.JwtFilter;
|
|
|
-import com.gis.admin.shiro.realm.UserJwtRealm;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy;
|
|
|
-import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
|
|
|
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
|
|
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
|
|
import org.apache.shiro.mgt.SecurityManager;
|
|
|
-import org.apache.shiro.realm.Realm;
|
|
|
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
|
|
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
|
@@ -36,18 +32,13 @@ import java.util.*;
|
|
|
@Configuration
|
|
|
public class ShiroConfig {
|
|
|
|
|
|
-// @Value("${jeecg.shiro.excludeUrls}")
|
|
|
+ // @Value("${jeecg.shiro.excludeUrls}")
|
|
|
// private String excludeUrls;
|
|
|
@Resource
|
|
|
LettuceConnectionFactory lettuceConnectionFactory;
|
|
|
@Autowired
|
|
|
private Environment env;
|
|
|
|
|
|
- @Autowired
|
|
|
- UserJwtRealm userJwtRealm;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* Filter Chain定义说明
|
|
@@ -62,7 +53,32 @@ public class ShiroConfig {
|
|
|
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
|
|
// 拦截器
|
|
|
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
|
|
-
|
|
|
+// if(oConvertUtils.isNotEmpty(excludeUrls)){
|
|
|
+// String[] permissionUrl = excludeUrls.split(",");
|
|
|
+// for(String url : permissionUrl){
|
|
|
+// filterChainDefinitionMap.put(url,"anon");
|
|
|
+// }
|
|
|
+// }
|
|
|
+ // 配置不会被拦截的链接 顺序判断
|
|
|
+// filterChainDefinitionMap.put("/sys/cas/client/validateLogin", "anon"); //cas验证登录
|
|
|
+//// filterChainDefinitionMap.put("/sys/randomImage/**", "anon"); //登录验证码接口排除
|
|
|
+//// filterChainDefinitionMap.put("/sys/checkCaptcha", "anon"); //登录验证码接口排除
|
|
|
+//// filterChainDefinitionMap.put("/sys/login", "anon"); //登录接口排除
|
|
|
+//// filterChainDefinitionMap.put("/sys/mLogin", "anon"); //登录接口排除
|
|
|
+//// filterChainDefinitionMap.put("/sys/logout", "anon"); //登出接口排除
|
|
|
+//// filterChainDefinitionMap.put("/sys/thirdLogin/**", "anon"); //第三方登录
|
|
|
+//// filterChainDefinitionMap.put("/sys/getEncryptedString", "anon"); //获取加密串
|
|
|
+//// filterChainDefinitionMap.put("/sys/sms", "anon");//短信验证码
|
|
|
+//// filterChainDefinitionMap.put("/sys/phoneLogin", "anon");//手机登录
|
|
|
+//// filterChainDefinitionMap.put("/sys/user/checkOnlyUser", "anon");//校验用户是否存在
|
|
|
+//// filterChainDefinitionMap.put("/sys/user/register", "anon");//用户注册
|
|
|
+//// filterChainDefinitionMap.put("/sys/user/querySysUser", "anon");//根据手机号获取用户信息
|
|
|
+//// filterChainDefinitionMap.put("/sys/user/phoneVerification", "anon");//用户忘记密码验证手机号
|
|
|
+//// filterChainDefinitionMap.put("/sys/user/passwordChange", "anon");//用户更改密码
|
|
|
+//// filterChainDefinitionMap.put("/auth/2step-code", "anon");//登录验证码
|
|
|
+//// filterChainDefinitionMap.put("/sys/common/static/**", "anon");//图片预览 &下载文件不限制token
|
|
|
+//// filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览
|
|
|
+//// filterChainDefinitionMap.put("/generic/**", "anon");//pdf预览需要文件
|
|
|
|
|
|
// 不拦截
|
|
|
filterChainDefinitionMap.put("/login", "anon");
|
|
@@ -72,7 +88,6 @@ public class ShiroConfig {
|
|
|
filterChainDefinitionMap.put("/test/**", "anon");
|
|
|
filterChainDefinitionMap.put("/api/**", "anon");
|
|
|
filterChainDefinitionMap.put("/web/**", "anon");
|
|
|
- filterChainDefinitionMap.put("/db/**", "anon");
|
|
|
|
|
|
filterChainDefinitionMap.put("/", "anon");
|
|
|
filterChainDefinitionMap.put("/doc.html", "anon");
|
|
@@ -113,6 +128,9 @@ public class ShiroConfig {
|
|
|
|
|
|
//测试示例
|
|
|
filterChainDefinitionMap.put("/test/bigScreen/**", "anon"); //大屏模板例子
|
|
|
+ //filterChainDefinitionMap.put("/test/jeecgDemo/rabbitMqClientTest/**", "anon"); //MQ测试
|
|
|
+ //filterChainDefinitionMap.put("/test/jeecgDemo/html", "anon"); //模板页面
|
|
|
+ //filterChainDefinitionMap.put("/test/jeecgDemo/redis/**", "anon"); //redis测试
|
|
|
|
|
|
//websocket排除
|
|
|
filterChainDefinitionMap.put("/websocket/**", "anon");//系统通知和公告
|
|
@@ -127,13 +145,13 @@ public class ShiroConfig {
|
|
|
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
|
|
|
//如果cloudServer为空 则说明是单体 需要加载跨域配置
|
|
|
Object cloudServer = env.getProperty("");
|
|
|
- filterMap.put("user_jwt", new JwtFilter(cloudServer==null));
|
|
|
+ filterMap.put("jwt", new JwtFilter(cloudServer==null));
|
|
|
shiroFilterFactoryBean.setFilters(filterMap);
|
|
|
// <!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边
|
|
|
// filterChainDefinitionMap.put("/**", "jwt");
|
|
|
- filterChainDefinitionMap.put("/sys/**", "user_jwt");
|
|
|
- filterChainDefinitionMap.put("/cms/**", "user_jwt");
|
|
|
-// filterChainDefinitionMap.put("/api/**", "app_jwt");
|
|
|
+ filterChainDefinitionMap.put("/sys/**", "jwt");
|
|
|
+ filterChainDefinitionMap.put("/cms/**", "jwt");
|
|
|
+ filterChainDefinitionMap.put("/db/**", "jwt");
|
|
|
|
|
|
// 未授权界面返回JSON
|
|
|
shiroFilterFactoryBean.setUnauthorizedUrl("/sys/common/403");
|
|
@@ -142,17 +160,10 @@ public class ShiroConfig {
|
|
|
return shiroFilterFactoryBean;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Bean("securityManager")
|
|
|
- public DefaultWebSecurityManager securityManager(UserJwtRealm userRealm) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ public DefaultWebSecurityManager securityManager(ShiroRealm myRealm) {
|
|
|
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
|
|
- securityManager.setRealm(userRealm);
|
|
|
-
|
|
|
+ securityManager.setRealm(myRealm);
|
|
|
|
|
|
/*
|
|
|
* 关闭shiro自带的session,详情见文档
|
|
@@ -169,47 +180,6 @@ public class ShiroConfig {
|
|
|
return securityManager;
|
|
|
}
|
|
|
|
|
|
-// @Bean("securityManager")
|
|
|
-//// public DefaultWebSecurityManager securityManager(UserJwtRealm myRealm) {
|
|
|
-// public DefaultWebSecurityManager securityManager() {
|
|
|
-//
|
|
|
-// List<Realm> realms = new ArrayList<>();
|
|
|
-// realms.add(userJwtRealm);
|
|
|
-//
|
|
|
-//
|
|
|
-// DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
|
|
-//// securityManager.setRealm(myRealm);
|
|
|
-// securityManager.setRealms(realms);
|
|
|
-//
|
|
|
-//
|
|
|
-// //设置realm.
|
|
|
-// securityManager.setAuthenticator(modularRealmAuthenticator());
|
|
|
-//
|
|
|
-// /*
|
|
|
-// * 关闭shiro自带的session,详情见文档
|
|
|
-// * http://shiro.apache.org/session-management.html#SessionManagement-
|
|
|
-// * StatelessApplications%28Sessionless%29
|
|
|
-// */
|
|
|
-// DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
|
|
-// DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
|
|
-// defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
|
|
-// subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
|
|
|
-// securityManager.setSubjectDAO(subjectDAO);
|
|
|
-// //自定义缓存实现,使用redis
|
|
|
-//// securityManager.setCacheManager(redisCacheManager());
|
|
|
-// return securityManager;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-// @Bean
|
|
|
-// public ModularRealmAuthenticator modularRealmAuthenticator() {
|
|
|
-// //自己重写的ShiroModularRealmAuthenticator
|
|
|
-// ShiroModularRealmAuthenticator modularRealmAuthenticator = new ShiroModularRealmAuthenticator();
|
|
|
-// modularRealmAuthenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
|
|
|
-// return modularRealmAuthenticator;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 下面的代码是添加注解支持
|
|
|
* @return
|