queryUserRoleId(String userid);
+
}
diff --git a/src/main/java/com/fc/v2/satoken/SaTokenConfigure.java b/src/main/java/com/fc/v2/satoken/SaTokenConfigure.java
new file mode 100644
index 0000000000000000000000000000000000000000..f3425b5c5c9ab64203d76f6ae635f6e66bbc928d
--- /dev/null
+++ b/src/main/java/com/fc/v2/satoken/SaTokenConfigure.java
@@ -0,0 +1,111 @@
+package com.fc.v2.satoken;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import com.alibaba.fastjson.JSON;
+import com.fc.v2.common.domain.AjaxResult;
+import com.fc.v2.satoken.dialect.SaTokenDialect;
+
+import cn.dev33.satoken.context.SaHolder;
+import cn.dev33.satoken.exception.NotLoginException;
+import cn.dev33.satoken.filter.SaServletFilter;
+import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
+import cn.dev33.satoken.router.SaRouter;
+import cn.dev33.satoken.stp.StpUtil;
+
+/**
+ * Sa-Token 配置
+ * @author kong
+ *
+ */
+@Configuration
+public class SaTokenConfigure implements WebMvcConfigurer {
+
+ /**
+ * 注册 Sa-Token 的注解拦截器,打开注解式鉴权功能
+ */
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
+ }
+
+ /**
+ * 注册 [Sa-Token全局过滤器]
+ */
+ @Bean
+ public SaServletFilter getSaServletFilter() {
+ return new SaServletFilter()
+
+ // 指定 拦截路由
+ .addInclude("/**")
+
+ // 指定 放行路由
+ .addExclude(
+ "/favicon.ico", "/static/**",
+ // 对所有用户认证
+ "/admin/login",
+ //手机登录
+ "/admin/API/login",
+ // 放验证码
+ "/captcha/**",
+ // 释放 druid 监控画面
+ "/druid/**",
+ // 释放websocket请求
+ "/websocket",
+ // 前端
+ "/", "/index",
+ // 任务调度暂时放开
+ "/quartz/**",
+ // 开放APicontroller
+ "/ApiController/**",
+ "/oss/**", "/druid/**"
+ )
+
+ // 认证函数: 每次请求执行
+ .setAuth(r -> {
+ SaRouter.match("/**", () -> StpUtil.checkLogin());
+ })
+
+ // 异常处理函数:每次认证函数发生异常时执行此函数
+ .setError(e -> {
+ // e.printStackTrace();
+ if(e instanceof NotLoginException) {
+ SaHolder.getResponse().redirect("/admin/login");
+ }
+ return JSON.toJSONString(AjaxResult.error(e.getMessage()));
+ })
+
+ // 前置函数:在每次认证函数之前执行
+ .setBeforeAuth(r -> {
+ // ---------- 设置跨域响应头 ----------
+ SaHolder.getResponse()
+ // 允许指定域访问跨域资源
+ .setHeader("Access-Control-Allow-Origin", "*")
+ // 允许所有请求方式
+ .setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE")
+ // 有效时间
+ .setHeader("Access-Control-Max-Age", "3600")
+ // 允许的header参数
+ .setHeader("Access-Control-Allow-Headers", "x-requested-with,satoken");
+
+ // 如果是预检请求,直接返回
+ if ("OPTIONS".equals(SaHolder.getRequest().getMethod())) {
+ System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
+ SaRouter.back();
+ }
+ })
+ ;
+ }
+
+ /**
+ * 注册 Sa-Token 标签方言
+ */
+ @Bean
+ public SaTokenDialect saTokenDialect() {
+ return new SaTokenDialect();
+ }
+
+}
diff --git a/src/main/java/com/fc/v2/satoken/SaTokenUtil.java b/src/main/java/com/fc/v2/satoken/SaTokenUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..43f8ca25a880fa6d580b2b5a6b60be4bbdcb0e53
--- /dev/null
+++ b/src/main/java/com/fc/v2/satoken/SaTokenUtil.java
@@ -0,0 +1,56 @@
+package com.fc.v2.satoken;
+
+import com.fc.v2.model.auto.TsysUser;
+
+import cn.dev33.satoken.stp.StpUtil;
+
+/**
+ * 封装 Sa-Token 常用操作
+ * @author kong
+ *
+ */
+public class SaTokenUtil {
+
+ /**
+ * 获取登录用户model
+ */
+ public static TsysUser getUser() {
+ return (TsysUser)StpUtil.getSession().get("user");
+ }
+
+ /**
+ * set用户
+ */
+ public static void setUser(TsysUser user) {
+ StpUtil.getSession().set("user", user);
+ }
+
+ /**
+ * 获取登录用户id
+ */
+ public static String getUserId() {
+ return StpUtil.getLoginIdAsString();
+ }
+
+ /**
+ * 获取登录用户name
+ */
+ public static String getLoginName() {
+ TsysUser tsysUser = getUser();
+ if (tsysUser == null){
+ throw new RuntimeException("用户不存在!");
+ }
+ return tsysUser.getUsername();
+ }
+
+ /**
+ * 获取登录用户ip
+ * @return
+ * @author fuce
+ * @Date 2019年11月21日 上午9:58:26
+ */
+ public static String getIp() {
+ return StpUtil.getTokenSession().getString("login_ip");
+ }
+
+}
diff --git a/src/main/java/com/fc/v2/satoken/StpInterfaceImpl.java b/src/main/java/com/fc/v2/satoken/StpInterfaceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..568107821891897e794b40ca20e0b06d1bb7b1e2
--- /dev/null
+++ b/src/main/java/com/fc/v2/satoken/StpInterfaceImpl.java
@@ -0,0 +1,54 @@
+package com.fc.v2.satoken;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.fc.v2.mapper.custom.PermissionDao;
+import com.fc.v2.mapper.custom.RoleDao;
+
+import cn.dev33.satoken.session.SaSession;
+import cn.dev33.satoken.session.SaSessionCustomUtil;
+import cn.dev33.satoken.stp.StpInterface;
+import cn.dev33.satoken.stp.StpUtil;
+
+/**
+ * 自定义权限验证接口扩展
+ */
+@Component
+public class StpInterfaceImpl implements StpInterface {
+
+ @Autowired
+ private PermissionDao permissionDao;//权限dao
+
+ @Autowired
+ private RoleDao roleDao ;//角色dao
+
+ /**
+ * 返回一个账号所拥有的权限码集合
+ * 注:权限变动时需要清除缓存:SaSessionCustomUtil.getSessionById("role-" + roleId).delete("Permission_List");
+ */
+ @Override
+ public List getPermissionList(Object loginId, String loginType) {
+ List permList = new ArrayList<>();
+ for (String roleId : getRoleList(loginId, loginType)) {
+ SaSession roleSession = SaSessionCustomUtil.getSessionById("role-" + roleId);
+ List list = roleSession.get("Permission_List", () -> permissionDao.queryPermsList(roleId));
+ permList.addAll(list);
+ }
+ return permList;
+ }
+
+ /**
+ * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
+ * 注:角色变动时需要清除缓存:StpUtil.getSessionByLoginId(userId).delete("Role_List");
+ */
+ @Override
+ public List getRoleList(Object loginId, String loginType) {
+ SaSession session = StpUtil.getSessionByLoginId(loginId);
+ return session.get("Role_List", () -> roleDao.queryUserRoleId(String.valueOf(loginId)));
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/fc/v2/satoken/dialect/SaTokenDialect.java b/src/main/java/com/fc/v2/satoken/dialect/SaTokenDialect.java
new file mode 100644
index 0000000000000000000000000000000000000000..9ca3651001cba437bcb9adef3c61df823241e45e
--- /dev/null
+++ b/src/main/java/com/fc/v2/satoken/dialect/SaTokenDialect.java
@@ -0,0 +1,50 @@
+package com.fc.v2.satoken.dialect;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.thymeleaf.dialect.AbstractProcessorDialect;
+import org.thymeleaf.processor.IProcessor;
+
+import cn.dev33.satoken.stp.StpUtil;
+
+/**
+ * Sa-Token 标签方言
+ * 参考:https://blog.csdn.net/whatlookingfor/article/details/78459649
+ * @author kong
+ *
+ */
+public class SaTokenDialect extends AbstractProcessorDialect {
+
+ /**
+ * 方言名称
+ */
+ private static final String DIALECT_NAME = "Sa-Token";
+
+ /**
+ * 方言前缀
+ */
+ public static final String DIALECT_PREFIX = "sa";
+
+ /**
+ * 优先级
+ */
+ public static final int PROCESSOR_PRECEDENCE = 1000;
+
+ public SaTokenDialect() {
+ super(DIALECT_NAME, DIALECT_PREFIX, PROCESSOR_PRECEDENCE);
+ }
+
+ /**
+ * 返回所有方言处理器
+ */
+ @Override
+ public Set getProcessors(final String prefix) {
+ return new HashSet(Arrays.asList(
+ new SaTokenTagProcessor(prefix, "hasRole", StpUtil::hasRole),
+ new SaTokenTagProcessor(prefix, "hasPermission", StpUtil::hasPermission)
+ ));
+ }
+
+}
diff --git a/src/main/java/com/fc/v2/satoken/dialect/SaTokenTagProcessor.java b/src/main/java/com/fc/v2/satoken/dialect/SaTokenTagProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..bf472981a6d705d7c6b675570c37d805dc9eba57
--- /dev/null
+++ b/src/main/java/com/fc/v2/satoken/dialect/SaTokenTagProcessor.java
@@ -0,0 +1,45 @@
+package com.fc.v2.satoken.dialect;
+
+import java.util.function.Function;
+
+import org.thymeleaf.context.ITemplateContext;
+import org.thymeleaf.engine.AttributeName;
+import org.thymeleaf.model.IProcessableElementTag;
+import org.thymeleaf.processor.element.AbstractAttributeTagProcessor;
+import org.thymeleaf.processor.element.IElementTagStructureHandler;
+import org.thymeleaf.templatemode.TemplateMode;
+
+/**
+ * 封装 Sa-Token 标签方言处理器
+ * @author kong
+ *
+ */
+public class SaTokenTagProcessor extends AbstractAttributeTagProcessor {
+
+ Function fun;
+
+ public SaTokenTagProcessor(final String dialectPrefix, String arrtName, Function fun) {
+ super(
+ TemplateMode.HTML, // This processor will apply only to HTML mode
+ dialectPrefix, // Prefix to be applied to name for matching
+ null, // No tag name: match any tag name
+ false, // No prefix to be applied to tag name
+ arrtName, // Name of the attribute that will be matched
+ true, // Apply dialect prefix to attribute name
+ 10000, // Precedence (inside dialect's own precedence)
+ true); // Remove the matched attribute afterwards
+ this.fun = fun;
+ }
+
+ @Override
+ protected void doProcess(
+ final ITemplateContext context, final IProcessableElementTag tag,
+ final AttributeName attributeName, final String attributeValue,
+ final IElementTagStructureHandler structureHandler) {
+ // 执行表达式返回值为false,则删除这个标签
+ if(this.fun.apply(attributeValue) == false) {
+ structureHandler.removeElement();
+ };
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/fc/v2/service/SysDictDataService.java b/src/main/java/com/fc/v2/service/SysDictDataService.java
index 62784a22ba19cdd444f3c40e8a0d9ee4e05ef889..3d76ff39307a25316e99ba94d4b5e0d51806c79a 100644
--- a/src/main/java/com/fc/v2/service/SysDictDataService.java
+++ b/src/main/java/com/fc/v2/service/SysDictDataService.java
@@ -1,5 +1,11 @@
package com.fc.v2.service;
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.TSysDictDataMapper;
@@ -8,15 +14,10 @@ import com.fc.v2.model.auto.TSysDictData;
import com.fc.v2.model.auto.TSysDictDataExample;
import com.fc.v2.model.auto.TSysDictType;
import com.fc.v2.model.custom.Tablepar;
-import com.fc.v2.shiro.util.ShiroUtils;
+import com.fc.v2.satoken.SaTokenUtil;
import com.fc.v2.util.SnowflakeIdWorker;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.Date;
-import java.util.List;
/**
* 字典数据表Service
@@ -75,7 +76,7 @@ public class SysDictDataService implements BaseService {
@@ -64,9 +65,9 @@ public class SysFileService implements BaseService {
//获取旧数据
SysFile old_data=sysFileMapper.selectByPrimaryKey(record.getId());
//插入修改人id
- record.setUpdateUserId(ShiroUtils.getUserId());
+ record.setUpdateUserId(SaTokenUtil.getUserId());
//插入修改人name
- record.setUpdateUserName(ShiroUtils.getLoginName());
+ record.setUpdateUserName(SaTokenUtil.getLoginName());
//插入修改时间
record.setUpdateTime(new Date());
return sysFileMapper.updateByPrimaryKey(old_data);
diff --git a/src/main/java/com/fc/v2/service/SysNoticeService.java b/src/main/java/com/fc/v2/service/SysNoticeService.java
index 52dba9f55e720b1660d4dc9b3ff82b03c4987870..684b5ca7f7f9680e5b0f45e79fac28b78b817e91 100644
--- a/src/main/java/com/fc/v2/service/SysNoticeService.java
+++ b/src/main/java/com/fc/v2/service/SysNoticeService.java
@@ -1,23 +1,29 @@
package com.fc.v2.service;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.SysNoticeMapper;
import com.fc.v2.mapper.auto.SysNoticeUserMapper;
-import com.fc.v2.model.auto.*;
+import com.fc.v2.model.auto.SysNotice;
+import com.fc.v2.model.auto.SysNoticeExample;
+import com.fc.v2.model.auto.SysNoticeUser;
+import com.fc.v2.model.auto.SysNoticeUserExample;
import com.fc.v2.model.auto.SysNoticeUserExample.Criteria;
+import com.fc.v2.model.auto.TsysUser;
+import com.fc.v2.model.auto.TsysUserExample;
import com.fc.v2.model.custom.Tablepar;
-import com.fc.v2.shiro.util.ShiroUtils;
+import com.fc.v2.satoken.SaTokenUtil;
import com.fc.v2.util.SnowflakeIdWorker;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
/**
* 公告 SysNoticeService
@@ -130,9 +136,9 @@ public class SysNoticeService implements BaseService noticeUsers= sysNoticeUserMapper.selectByExample(sysNoticeUserExample);
for (SysNoticeUser sysNoticeUser : noticeUsers) {
sysNoticeUser.setState(1);
diff --git a/src/main/java/com/fc/v2/service/SysQuartzJobService.java b/src/main/java/com/fc/v2/service/SysQuartzJobService.java
index f7895ea75226042c627ac11aa371b5f07a5aef3a..bbf71ef3e459dc9bfdef1aeae551a4e2b0663b7f 100644
--- a/src/main/java/com/fc/v2/service/SysQuartzJobService.java
+++ b/src/main/java/com/fc/v2/service/SysQuartzJobService.java
@@ -162,7 +162,7 @@ public class SysQuartzJobService implements BaseService 0)
{
diff --git a/src/main/java/com/fc/v2/service/SysUserService.java b/src/main/java/com/fc/v2/service/SysUserService.java
index 7087cf02f90b174dbb0558cbc0ac033914a97ced..0d46cf871da59fc62f80f6685712e507070e1dbc 100644
--- a/src/main/java/com/fc/v2/service/SysUserService.java
+++ b/src/main/java/com/fc/v2/service/SysUserService.java
@@ -1,5 +1,12 @@
package com.fc.v2.service;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.TSysRoleUserMapper;
@@ -7,7 +14,12 @@ import com.fc.v2.mapper.auto.TsysRoleMapper;
import com.fc.v2.mapper.auto.TsysUserMapper;
import com.fc.v2.mapper.custom.RoleDao;
import com.fc.v2.mapper.custom.TsysUserDao;
-import com.fc.v2.model.auto.*;
+import com.fc.v2.model.auto.TSysRoleUser;
+import com.fc.v2.model.auto.TSysRoleUserExample;
+import com.fc.v2.model.auto.TsysRole;
+import com.fc.v2.model.auto.TsysRoleExample;
+import com.fc.v2.model.auto.TsysUser;
+import com.fc.v2.model.auto.TsysUserExample;
import com.fc.v2.model.custom.RoleVo;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.util.MD5Util;
@@ -15,12 +27,8 @@ import com.fc.v2.util.SnowflakeIdWorker;
import com.fc.v2.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.List;
+import cn.dev33.satoken.stp.StpUtil;
/**
* 系统用户
@@ -240,6 +248,9 @@ public class SysUserService implements BaseService{
tSysRoleUserMapper.insertSelective(tSysRoleUser);
}
}
+ // 清除此用户角色信息缓存
+ StpUtil.getSessionByLoginId(record.getId()).delete("Role_List");
+
//修改用户信息
return tsysUserMapper.updateByPrimaryKeySelective(record);
}
diff --git a/src/main/java/com/fc/v2/service/TSysEmailService.java b/src/main/java/com/fc/v2/service/TSysEmailService.java
index 54a7e0fea3a27b4a3296014028a0204f73e0a44b..4e71033c23b99c19d488f1d9e62a53b9c168d563 100644
--- a/src/main/java/com/fc/v2/service/TSysEmailService.java
+++ b/src/main/java/com/fc/v2/service/TSysEmailService.java
@@ -2,18 +2,20 @@ package com.fc.v2.service;
import java.util.Date;
import java.util.List;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
+
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.TSysEmailMapper;
import com.fc.v2.model.auto.TSysEmail;
import com.fc.v2.model.auto.TSysEmailExample;
import com.fc.v2.model.custom.Tablepar;
-import com.fc.v2.shiro.util.ShiroUtils;
+import com.fc.v2.satoken.SaTokenUtil;
import com.fc.v2.util.SnowflakeIdWorker;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
/**
* 电子邮件Service
@@ -74,8 +76,8 @@ public class TSysEmailService implements BaseService customFilterMap = new LinkedHashMap<>();
- customFilterMap.put("corsAuthenticationFilter", new CORSAuthenticationFilter());
- shiroFilterFactoryBean.setFilters(customFilterMap);
-
- return shiroFilterFactoryBean;
- }
-
- /**
- * web应用管理配置
- *
- * @param shiroRealm
- * @param cacheManager
- * @param manager
- * @return
- */
- @Bean
- public DefaultWebSecurityManager securityManager(Realm shiroRealm, CacheManager cacheManager,
- RememberMeManager manager) {
- DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
- securityManager.setCacheManager(cacheManager);
- securityManager.setRememberMeManager(manager);// 记住Cookie
- securityManager.setRealm(shiroRealm);
- securityManager.setSessionManager(sessionManager());
- return securityManager;
- }
-// /**
-// * session过期控制
-// * @return
-// * @author fuce
-// * @Date 2019年11月2日 下午12:49:49
-// */
-// @Bean
-// public DefaultWebSessionManager sessionManager() {
-// DefaultWebSessionManager defaultWebSessionManager=new DefaultWebSessionManager();
-// // 设置session过期时间3600s
-// Long timeout=60L*1000*60;//毫秒级别
-// defaultWebSessionManager.setGlobalSessionTimeout(timeout);
-// return defaultWebSessionManager;
-// }
-
- /**
- * 自定义的 shiro session 缓存管理器,用于跨域等情况下使用 token 进行验证,不依赖于sessionId
- *
- * @return
- */
- @Bean
- public SessionManager sessionManager() {
- // 将我们继承后重写的shiro session 注册
- ShiroSession shiroSession = new ShiroSession();
- // 如果后续考虑多tomcat部署应用,可以使用shiro-redis开源插件来做session 的控制,或者nginx 的负载均衡
- EnterpriseCacheSessionDAO sessionDAO = new EnterpriseCacheSessionDAO();
- sessionDAO.setSessionIdGenerator(new UuidSessionIdGenerator());
- shiroSession.setSessionDAO(sessionDAO);
- return shiroSession;
- }
-
- /**
- * 加密算法
- *
- * @return
- */
- @Bean
- public HashedCredentialsMatcher hashedCredentialsMatcher() {
- HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
- hashedCredentialsMatcher.setHashAlgorithmName("MD5");// 采用MD5 进行加密
- hashedCredentialsMatcher.setHashIterations(1);// 加密次数
- return hashedCredentialsMatcher;
- }
-
- /**
- * 记住我的配置
- *
- * @return
- */
- @Bean
- public RememberMeManager rememberMeManager() {
- Cookie cookie = new SimpleCookie("rememberMe");
- cookie.setHttpOnly(true);// 通过js脚本将无法读取到cookie信息
- cookie.setMaxAge(60 * 60 * 24);// cookie保存一天
- CookieRememberMeManager manager = new CookieRememberMeManager();
- manager.setCookie(cookie);
- return manager;
- }
-
- /**
- * 缓存配置
- *
- * @return
- */
- @Bean
- public CacheManager cacheManager() {
- MemoryConstrainedCacheManager cacheManager = new MemoryConstrainedCacheManager();// 使用内存缓存
- return cacheManager;
- }
-
- /**
- * 配置realm,用于认证和授权
- *
- * @param hashedCredentialsMatcher
- * @return
- */
- @Bean
- public AuthorizingRealm shiroRealm(HashedCredentialsMatcher hashedCredentialsMatcher) {
- MyShiroRealm shiroRealm = new MyShiroRealm();
- // 校验密码用到的算法
- shiroRealm.setCredentialsMatcher(hashedCredentialsMatcher);
- return shiroRealm;
- }
-
- /**
- * 启用shiro方言,这样能在页面上使用shiro标签
- *
- * @return
- */
- @Bean
- public ShiroDialect shiroDialect() {
- return new ShiroDialect();
- }
-
- /**
- * 启用shiro注解 加入注解的使用,不加入这个注解不生效
- */
- @Bean
- public AuthorizationAttributeSourceAdvisor getAuthorizationAttributeSourceAdvisor(
- org.apache.shiro.mgt.SecurityManager securityManager) {
- AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
- advisor.setSecurityManager(securityManager);
- return advisor;
- }
-
-}
diff --git a/src/main/java/com/fc/v2/shiro/config/ShiroFilterMapFactory.java b/src/main/java/com/fc/v2/shiro/config/ShiroFilterMapFactory.java
deleted file mode 100644
index 1a3ebeaa2ea686df85d3b74fabc16ccf15c85eb2..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/config/ShiroFilterMapFactory.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.fc.v2.shiro.config;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * @ClassName: ShiroFilterMapFactory
- * @author fuce
- * @date 2018年8月26日
- *
- */
-public class ShiroFilterMapFactory {
-
- /**
- * anon:例子/admins/**=anon 没有参数,表示可以匿名使用。
- *
- * authc:例如/admins/user/**=authc表示需要认证(登录)才能使用,没有参数
- *
- * roles(角色):例子/admins/user/**=roles[admin],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,当有多个参数时,例如admins/user/**=roles["admin,guest"],每个参数通过才算通过,相当于hasAllRoles()方法。
- *
- * perms(权限):例子/admins/user/**=perms[user:add:*],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,例如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。
- *
- * rest:例子/admins/user/**=rest[user],根据请求的方法,相当于/admins/user/**=perms[user:method]
- * ,其中method为post,get,delete等。
- *
- * port:例子/admins/user/**=port[8081],当请求的url的端口不是8081是跳转到schemal://serverName:8081?queryString,其中schmal是协议http或https等,serverName是你访问的host,8081是url配置里port的端口,queryString
- *
- * 是你访问的url里的?后面的参数。
- *
- * authcBasic:例如/admins/user/**=authcBasic没有参数表示httpBasic认证
- *
- * ssl:例子/admins/user/**=ssl没有参数,表示安全的url请求,协议为https
- *
- * user:例如/admins/user/**=user没有参数表示必须存在用户,当登入操作时不做检查
- *
- */
-
- public static Map shiroFilterMap() {
-// 设置路径映射,注意这里要用LinkedHashMap 保证有序
- LinkedHashMap filterChainDefinitionMap = new LinkedHashMap<>();
- // 对所有用户认证
- filterChainDefinitionMap.put("/static/**", "anon");
- filterChainDefinitionMap.put("/admin/login", "anon");
- filterChainDefinitionMap.put("/admin/logout", "logout");
- //手机登录
- filterChainDefinitionMap.put("/admin/API/login", "anon");
- // 放验证码
- filterChainDefinitionMap.put("/captcha/**", "anon");
- // 释放 druid 监控画面
- filterChainDefinitionMap.put("/druid/**", "anon");
- // 释放websocket请求
- filterChainDefinitionMap.put("/websocket", "anon");
- // 前端
- filterChainDefinitionMap.put("/", "anon");
- filterChainDefinitionMap.put("/index", "anon");
- // 任务调度暂时放开
- filterChainDefinitionMap.put("/quartz/**", "anon");
-
- // 开放APicontroller
- filterChainDefinitionMap.put("/ApiController/**", "anon");
-
- filterChainDefinitionMap.put("/oss/**", "anon");
- filterChainDefinitionMap.put("/druid/**", "anon");
-
- // 对所有页面进行认证
- filterChainDefinitionMap.put("/**", "user");
- return filterChainDefinitionMap;
- }
-}
diff --git a/src/main/java/com/fc/v2/shiro/service/CORSAuthenticationFilter.java b/src/main/java/com/fc/v2/shiro/service/CORSAuthenticationFilter.java
deleted file mode 100644
index c2e01f9c610dfdfa0bdd2b7eaa8139e7fb2205de..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/service/CORSAuthenticationFilter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.fc.v2.shiro.service;
-
-import cn.hutool.json.JSONUtil;
-import com.fc.v2.common.domain.AjaxResult;
-import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.PrintWriter;
-
-/**
- * @author :LX
- * 创建时间: 2019/5/31. 10:25
- * 地点:广州
- * 目的: 过滤OPTIONS请求 继承shiro 的form表单过滤器,对
- * OPTIONS 请求进行过滤。 前后端分离项目中,由于跨域,会导致复杂请求,即会发送preflighted
- * request,这样会导致在GET/POST等请求之前会先发一个OPTIONS请求,但OPTIONS请求并不带shiro
- * 的'authToken'字段(shiro的SessionId),即OPTIONS请求不能通过shiro验证,会返回未认证的信息。
- *
- *备注说明: 需要在 shiroConfig 进行注册
- */
-public class CORSAuthenticationFilter extends FormAuthenticationFilter {
-
- /**
- * 直接过滤可以访问的请求类型
- */
- private static final String REQUET_TYPE = "OPTIONS";
-
- public CORSAuthenticationFilter() {
- super();
- }
-
- @Override
- public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
- if (((HttpServletRequest) request).getMethod().toUpperCase().equals(REQUET_TYPE)) {
- return true;
- }
- return super.isAccessAllowed(request, response, mappedValue);
- }
-
- @Override
- protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
- HttpServletResponse res = (HttpServletResponse) response;
- res.setHeader("Access-Control-Allow-Origin", "*");
- res.setStatus(HttpServletResponse.SC_OK);
- res.setCharacterEncoding("UTF-8");
- PrintWriter writer = res.getWriter();
-// ResultJson resultJson = new ResultJson(Constant.ERROR_CODE_NO_LOGIN, ResultEnum.ERROR.getStatus(), "请先登录系统!", null);
- writer.write(JSONUtil.toJsonStr(AjaxResult.error(500, "请先登录系统!")));
- writer.close();
- return false;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/fc/v2/shiro/service/ExtendRolesAuthorizationFilter.java b/src/main/java/com/fc/v2/shiro/service/ExtendRolesAuthorizationFilter.java
deleted file mode 100644
index 5bb0e58c00a70aa7a86180633ad3e0439e814a98..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/service/ExtendRolesAuthorizationFilter.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.fc.v2.shiro.service;
-
-import org.apache.shiro.web.filter.authz.RolesAuthorizationFilter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * 通过角色验证权限
- * @ClassName: ExtendRolesAuthorizationFilter
- * @author fuce
- * @date 2018年8月26日
- *
- */
-public class ExtendRolesAuthorizationFilter extends RolesAuthorizationFilter{
-
- public boolean isAccessAllowed(HttpServletRequest request, HttpServletResponse response, Object mappedValue) throws IOException {
-//
-// System.out.println(ExtendRolesAuthorizationFilter.class.toString());
-// Subject subject = getSubject(request, response);
-// String[] rolesArray = (String[]) mappedValue;
-//
-// if (rolesArray == null || rolesArray.length == 0) {
-// //no roles specified, so nothing to check - allow access.
-// return true;
-// }
-// //AbstractFilter
-// Set roles = CollectionUtils.asSet(rolesArray);
-//
-// boolean flag=false;
-// for(String role: roles){
-// if(subject.hasRole(role)){
-// flag=true;
-// break;
-// }
-// }
- return true;
- }
-}
diff --git a/src/main/java/com/fc/v2/shiro/service/MyShiroRealm.java b/src/main/java/com/fc/v2/shiro/service/MyShiroRealm.java
deleted file mode 100644
index ab265f1693bc9b0a7bbc1caf810ad69480b473bc..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/service/MyShiroRealm.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package com.fc.v2.shiro.service;
-
-import com.fc.v2.mapper.custom.PermissionDao;
-import com.fc.v2.mapper.custom.RoleDao;
-import com.fc.v2.mapper.custom.TsysUserDao;
-import com.fc.v2.model.auto.TsysPermission;
-import com.fc.v2.model.auto.TsysRole;
-import com.fc.v2.model.auto.TsysUser;
-import com.fc.v2.util.StringUtils;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.authc.AuthenticationException;
-import org.apache.shiro.authc.AuthenticationInfo;
-import org.apache.shiro.authc.AuthenticationToken;
-import org.apache.shiro.authc.SimpleAuthenticationInfo;
-import org.apache.shiro.authz.AuthorizationException;
-import org.apache.shiro.authz.AuthorizationInfo;
-import org.apache.shiro.authz.SimpleAuthorizationInfo;
-import org.apache.shiro.realm.AuthorizingRealm;
-import org.apache.shiro.subject.PrincipalCollection;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-/**
- * 身份校验核心类
- *
- * @ClassName: MyShiroRealm
- * @author fuce
- * @date 2018年8月25日
- *
- */
-@Service
-public class MyShiroRealm extends AuthorizingRealm {
-
- @Autowired
- private TsysUserDao tsysUserDao;
-
- @Autowired
- private PermissionDao permissionDao;//权限dao
-
- @Autowired
- private RoleDao roleDao ;//角色dao
-
-
- /**
- * 认证登陆
- */
- @SuppressWarnings("unused")
- @Override
- protected AuthenticationInfo doGetAuthenticationInfo(
- AuthenticationToken token) throws AuthenticationException {
-
- //加这一步的目的是在Post请求的时候会先进认证,然后在到请求
- if (token.getPrincipal() == null) {
- return null;
- }
- String username = (String) token.getPrincipal();
- String password = new String((char[]) token.getCredentials());
- // 通过username从数据库中查找 User对象,如果找到,没找到.
- // 实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法
- TsysUser userInfo = tsysUserDao.queryUserName(username);
-// System.out.println(userInfo);
-// System.out.println("----->>userInfo=" + userInfo.getUsername() + "---"+ userInfo.getPassword());
- if (userInfo == null)
- return null;
- else{
- SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
- userInfo, // 用户对象
- userInfo.getPassword(), // 密码
- getName() // realm name
- );
- return authenticationInfo;
- }
-
- }
-
- /**
- * 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用.
- */
- @Override
- protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
- //System.out.println("权限配置-->MyShiroRealm.doGetAuthorizationInfo()");
- if(principals == null){
- throw new AuthorizationException("principals should not be null");
- }
- SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
- TsysUser userinfo = (TsysUser)principals.getPrimaryPrincipal();
- String uid=userinfo.getId();
- List tsysRoles= roleDao.queryUserRole(uid);
- for(TsysRole userrole:tsysRoles){
- //System.out.println("角色名字:"+gson.toJson(userrole));
- String rolid=userrole.getId();//角色id
- authorizationInfo.addRole(userrole.getName());//添加角色名字
- List permissions=permissionDao.queryRoleId(rolid);
- for(TsysPermission p:permissions){
- //System.out.println("角色下面的权限:"+gson.toJson(p));
- if(StringUtils.isNotEmpty(p.getPerms())){
- authorizationInfo.addStringPermission(p.getPerms());
- }
-
- }
- }
-
- return authorizationInfo;
- }
-
- /**
- * 清理缓存权限
- */
- public void clearCachedAuthorizationInfo()
- {
- this.clearCachedAuthorizationInfo(SecurityUtils.getSubject().getPrincipals());
- }
-
-}
diff --git a/src/main/java/com/fc/v2/shiro/service/ShiroSession.java b/src/main/java/com/fc/v2/shiro/service/ShiroSession.java
deleted file mode 100644
index 80e2c41a1ad8f4c0d485dfcce27073ec9c5d5c92..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/service/ShiroSession.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.fc.v2.shiro.service;
-
-import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
-import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
-import org.apache.shiro.web.util.WebUtils;
-import cn.hutool.core.util.StrUtil;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.Serializable;
-
-/**
- * 原文链接:https://my.oschina.net/sprouting/blog/3059282
- *
- * @author :LX
- * 创建时间: 2019/5/30. 18:08
- * 地点:广州
- * 目的: shiro 的 session 管理
- * 自定义session规则,实现前后分离,在跨域等情况下使用token 方式进行登录验证才需要,否则没必须使用本类。 shiro默认使用
- * ServletContainerSessionManager 来做 session 管理,它是依赖于浏览器的 cookie 来维护
- * session 的,调用 storeSessionId 方法保存sesionId 到 cookie中 为了支持无状态会话,我们就需要继承
- * DefaultWebSessionManager 自定义生成sessionId 则要实现 SessionIdGenerator
- * 备注说明:
- */
-public class ShiroSession extends DefaultWebSessionManager {
-
- /**
- * 定义的请求头中使用的标记key,用来传递 token
- */
- private static final String AUTH_TOKEN = "authToken";
-
- private static final String REFERENCED_SESSION_ID_SOURCE = "Stateless request";
-
- public ShiroSession() {
- super();
- // 设置 shiro session 失效时间,默认为30分钟,这里现在设置为15分钟
- setGlobalSessionTimeout(MILLIS_PER_MINUTE * 30);
- }
-
- /**
- * 获取sessionId,原本是根据sessionKey来获取一个sessionId
- * 重写的部分多了一个把获取到的token设置到request的部分。这是因为app调用登陆接口的时候,是没有token的,登陆成功后,产生了token,我们把它放到request中,返回结
- * 果给客户端的时候,把它从request中取出来,并且传递给客户端,客户端每次带着这个token过来,就相当于是浏览器的cookie的作用,也就能维护会话了
- *
- * @param request
- * @param response
- * @return
- */
- @Override
- protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
- // 获取请求头中的 AUTH_TOKEN 的值,如果请求头中有 AUTH_TOKEN 则其值为sessionId。shiro就是通过sessionId
- // 来控制的
- String sessionId = WebUtils.toHttp(request).getHeader(AUTH_TOKEN);
- if (StrUtil.isEmpty(sessionId)) {
- // 如果没有携带id参数则按照父类的方式在cookie进行获取sessionId
- return super.getSessionId(request, response);
-
- } else {
- // 请求头中如果有 authToken, 则其值为sessionId
- request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE, REFERENCED_SESSION_ID_SOURCE);
- // sessionId
- request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, sessionId);
- request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
- return sessionId;
- }
- }
-
-}
diff --git a/src/main/java/com/fc/v2/shiro/service/URLPermissionsFilter.java b/src/main/java/com/fc/v2/shiro/service/URLPermissionsFilter.java
deleted file mode 100644
index ae875aeaee3a245de02547438bd3d23e536ed28d..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/service/URLPermissionsFilter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
-* @Title: URLPermissionsFilter.java
-* @Package com.fc.v2.shiro.service
-* @author Administrator
-* @date 2018年8月26日
-* @version V1.0
-*/
-package com.fc.v2.shiro.service;
-
-import org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * 通过字符串验证权限
- * @ClassName: URLPermissionsFilter
- * @author fuce
- * @date 2018年8月26日
- *
- */
-public class URLPermissionsFilter extends PermissionsAuthorizationFilter {
- /**
- * mappedValue 访问该url时需要的权限
- * subject.isPermitted 判断访问的用户是否拥有mappedValue权限
- * 重写拦截器,只要符合配置的一个权限,即可通过
- */
- public boolean isAccessAllowed(HttpServletRequest request, HttpServletResponse response, Object mappedValue)
- throws IOException {
- /*System.out.println(URLPermissionsFilter.class.toString());
- Subject subject = getSubject(request, response);
- // DefaultFilterChainManager
- // PathMatchingFilterChainResolver
- String[] perms = (String[]) mappedValue;
- boolean isPermitted = false;
- if (perms != null && perms.length > 0) {
- for (String str : perms) {
- if (subject.isPermitted(str)) {
- isPermitted = true;
- }
- }
- }*/
-
- return true;
- }
-}
diff --git a/src/main/java/com/fc/v2/shiro/service/UuidSessionIdGenerator.java b/src/main/java/com/fc/v2/shiro/service/UuidSessionIdGenerator.java
deleted file mode 100644
index aed189bca3973f635b30f445121081c2edbfab38..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/service/UuidSessionIdGenerator.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.fc.v2.shiro.service;
-
-import org.apache.shiro.session.Session;
-import org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator;
-import org.apache.shiro.session.mgt.eis.SessionIdGenerator;
-
-import java.io.Serializable;
-
-public class UuidSessionIdGenerator implements SessionIdGenerator {
-
- @Override
- public Serializable generateId(Session session) {
- // TODO Auto-generated method stub
- Serializable uuid = new JavaUuidSessionIdGenerator().generateId(session);
- return uuid;
- }
-
-}
diff --git a/src/main/java/com/fc/v2/shiro/util/ShiroUtils.java b/src/main/java/com/fc/v2/shiro/util/ShiroUtils.java
deleted file mode 100644
index 0472368c267ff07ec8f472f98735b0b8950de3dd..0000000000000000000000000000000000000000
--- a/src/main/java/com/fc/v2/shiro/util/ShiroUtils.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package com.fc.v2.shiro.util;
-
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.mgt.RealmSecurityManager;
-import org.apache.shiro.session.Session;
-import org.apache.shiro.subject.PrincipalCollection;
-import org.apache.shiro.subject.SimplePrincipalCollection;
-import org.apache.shiro.subject.Subject;
-import com.fc.v2.model.auto.TsysUser;
-import com.fc.v2.shiro.service.MyShiroRealm;
-import com.fc.v2.util.BeanUtils;
-import com.fc.v2.util.StringUtils;
-
-
-/**
- * shiro 工具类
- *
- * @author fuce
- */
-public class ShiroUtils {
-
- private ShiroUtils(){}
-
- /**
- * 获取shiro subject
- * @return
- * @author fuce
- * @Date 2019年11月21日 上午10:00:55
- */
- public static Subject getSubjct()
- {
- return SecurityUtils.getSubject();
- }
-
- /**
- * 获取登录session
- * @return
- * @author fuce
- * @Date 2019年11月21日 上午10:00:41
- */
- public static Session getSession()
- {
- return SecurityUtils.getSubject().getSession();
- }
-
- /**
- * 退出登录
- * @author fuce
- * @Date 2019年11月21日 上午10:00:24
- */
- public static void logout()
- {
- getSubjct().logout();
- }
-
- /**
- * 获取登录用户model
- * @return
- * @author fuce
- * @Date 2019年11月21日 上午10:00:10
- */
- public static TsysUser getUser()
- {
- TsysUser user = null;
- Object obj = getSubjct().getPrincipal();
- if (StringUtils.isNotNull(obj))
- {
- user = new TsysUser();
- BeanUtils.copyBeanProp(user, obj);
- }
- return user;
- }
-
- /**
- * set用户
- * @param user
- * @author fuce
- * @Date 2019年11月21日 上午9:59:52
- */
- public static void setUser(TsysUser user)
- {
- Subject subject = getSubjct();
- PrincipalCollection principalCollection = subject.getPrincipals();
- String realmName = principalCollection.getRealmNames().iterator().next();
- PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
- // 重新加载Principal
- subject.runAs(newPrincipalCollection);
- }
-
- /**
- * 清除授权信息
- * @author fuce
- * @Date 2019年11月21日 上午9:59:37
- */
- public static void clearCachedAuthorizationInfo()
- {
- RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
- MyShiroRealm realm = (MyShiroRealm) rsm.getRealms().iterator().next();
- realm.clearCachedAuthorizationInfo();
- }
-
- /**
- * 获取登录用户id
- * @return
- * @author fuce
- * @Date 2019年11月21日 上午9:58:55
- */
- public static String getUserId()
- {
- TsysUser tsysUser = getUser();
- if (tsysUser == null || tsysUser.getId() == null){
- throw new RuntimeException("用户不存在!");
- }
- return tsysUser.getId().trim();
- }
-
- /**
- * 获取登录用户name
- * @return
- * @author fuce
- * @Date 2019年11月21日 上午9:58:48
- */
- public static String getLoginName()
- {
- TsysUser tsysUser = getUser();
- if (tsysUser == null){
- throw new RuntimeException("用户不存在!");
- }
- return tsysUser.getUsername();
- }
-
- /**
- * 获取登录用户ip
- * @return
- * @author fuce
- * @Date 2019年11月21日 上午9:58:26
- */
- public static String getIp()
- {
- return getSubjct().getSession().getHost();
- }
-
- /**
- * 获取登录用户sessionid
- * @return
- * @author fuce
- * @Date 2019年11月21日 上午9:58:37
- */
- public static String getSessionId()
- {
- return String.valueOf(getSubjct().getSession().getId());
- }
-}
diff --git a/src/main/java/com/fc/v2/util/ServletUtils.java b/src/main/java/com/fc/v2/util/ServletUtils.java
index 8d9cee8f5ecb30de3481c4fbcc17ab5f6852d5a1..01317f7956257d3222a726d4256c78143a4b71c7 100644
--- a/src/main/java/com/fc/v2/util/ServletUtils.java
+++ b/src/main/java/com/fc/v2/util/ServletUtils.java
@@ -9,6 +9,8 @@ import javax.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
+
+import cn.dev33.satoken.util.SaFoxUtil;
import cn.hutool.core.convert.Convert;
/**
@@ -136,4 +138,24 @@ public class ServletUtils
return false;
}
+
+
+ private static boolean checkIp(String ip) {
+ return !SaFoxUtil.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip);
+ }
+
+ /**
+ * 返回请求端的IP地址
+ * @param request /
+ * @return ip
+ */
+ public static String getIP(HttpServletRequest request) {
+ String ip = request.getHeader("x-forwarded-for");
+ ip = checkIp(ip) ? ip : (
+ checkIp(ip = request.getHeader("Proxy-Client-IP")) ? ip : (
+ checkIp(ip = request.getHeader("WL-Proxy-Client-IP")) ? ip :
+ request.getRemoteAddr()));
+ return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;
+ }
+
}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 7145aa220953c7e6561bc4e62343c5e44b11a017..4df8968cfec4d10ed0512260871f034a6f1004a3 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -27,7 +27,7 @@ server :
# context-path : /demo
tomcat :
uri-encoding : UTF-8
- #shiro 报错修改的地方
+ #xx 报错修改的地方
max-connections: 200000
max-http-form-post-size: 9000000
threads:
@@ -45,7 +45,7 @@ spring :
max-request-size: 100MB
#单个文件大小
maxFileSize : 30MB
- #shiro 报错修改的地方
+ #xx 报错修改的地方
max-connections: 200000
max-http-post-size: 9000000
#热部署模块
diff --git a/src/main/resources/auto_code/controller/EntityController.java.vm b/src/main/resources/auto_code/controller/EntityController.java.vm
index 7cb86889f9f02880a1f4027103b9bf0c6b59645c..379dc4bf7a48f9d846cfa2f34d218e2d6c20c7c4 100644
--- a/src/main/resources/auto_code/controller/EntityController.java.vm
+++ b/src/main/resources/auto_code/controller/EntityController.java.vm
@@ -9,7 +9,7 @@ import ${parentPack}.service.${tableInfo.javaTableName}Service;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
+import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
@@ -54,7 +54,7 @@ public class ${tableInfo.javaTableName}Controller extends BaseController{
*/
@ApiOperation(value = "分页跳转", notes = "分页跳转")
@GetMapping("/view")
- @RequiresPermissions("gen:${tableInfo.javaTableName_a}:view")
+ @SaCheckPermission("gen:${tableInfo.javaTableName_a}:view")
#if($isupload==true)
@OssConfig
#end
@@ -72,7 +72,7 @@ public class ${tableInfo.javaTableName}Controller extends BaseController{
//@Log(title = "${tableInfo.tableComment}", action = "111")
@ApiOperation(value = "分页跳转", notes = "分页跳转")
@GetMapping("/list")
- @RequiresPermissions("gen:${tableInfo.javaTableName_a}:list")
+ @SaCheckPermission("gen:${tableInfo.javaTableName_a}:list")
@ResponseBody
public ResultTable list(Tablepar tablepar,${tableInfo.javaTableName} ${tableInfo.javaTableName_a}){
PageInfo<${tableInfo.javaTableName}> page=${tableInfo.javaTableName_a}Service.list(tablepar,${tableInfo.javaTableName_a}) ;
@@ -100,7 +100,7 @@ public class ${tableInfo.javaTableName}Controller extends BaseController{
//@Log(title = "${tableInfo.tableComment}新增", action = "111")
@ApiOperation(value = "新增", notes = "新增")
@PostMapping("/add")
- @RequiresPermissions("gen:${tableInfo.javaTableName_a}:add")
+ @SaCheckPermission("gen:${tableInfo.javaTableName_a}:add")
@ResponseBody
public AjaxResult add(${tableInfo.javaTableName} ${tableInfo.javaTableName_a}){
int b=${tableInfo.javaTableName_a}Service.insertSelective(${tableInfo.javaTableName_a});
@@ -119,7 +119,7 @@ public class ${tableInfo.javaTableName}Controller extends BaseController{
//@Log(title = "${tableInfo.tableComment}删除", action = "111")
@ApiOperation(value = "删除", notes = "删除")
@DeleteMapping("/remove")
- @RequiresPermissions("gen:${tableInfo.javaTableName_a}:remove")
+ @SaCheckPermission("gen:${tableInfo.javaTableName_a}:remove")
@ResponseBody
public AjaxResult remove(String ids){
int b=${tableInfo.javaTableName_a}Service.deleteByPrimaryKey(ids);
@@ -154,7 +154,7 @@ public class ${tableInfo.javaTableName}Controller extends BaseController{
*/
//@Log(title = "${tableInfo.tableComment}修改", action = "111")
@ApiOperation(value = "修改保存", notes = "修改保存")
- @RequiresPermissions("gen:${tableInfo.javaTableName_a}:edit")
+ @SaCheckPermission("gen:${tableInfo.javaTableName_a}:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(${tableInfo.javaTableName} ${tableInfo.javaTableName_a})
diff --git a/src/main/resources/auto_code/html/list.html.vm b/src/main/resources/auto_code/html/list.html.vm
index 39bf1516c2c1e44efe25e31d7c3b6b64b3619867..238137bf76a2fc55e505075541dd7ce186b80218 100644
--- a/src/main/resources/auto_code/html/list.html.vm
+++ b/src/main/resources/auto_code/html/list.html.vm
@@ -1,5 +1,5 @@
-
+
@@ -32,21 +32,21 @@
diff --git a/src/main/resources/mybatis/custom/TsysPremissionMapper.xml b/src/main/resources/mybatis/custom/TsysPremissionMapper.xml
index 114b4c4c95c3d68940a741dbabfa4c71d1b3e5c6..477b929e22bd1290536ee6527b5aa860cee67963 100644
--- a/src/main/resources/mybatis/custom/TsysPremissionMapper.xml
+++ b/src/main/resources/mybatis/custom/TsysPremissionMapper.xml
@@ -38,6 +38,13 @@
+
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/custom/TsysRoleMapper.xml b/src/main/resources/mybatis/custom/TsysRoleMapper.xml
index 82227eeac7aedbe2f2cd8e49a4c06c1e3bbc110b..75102a216cc03b5fd85feadfcd0ad8600f8683de 100644
--- a/src/main/resources/mybatis/custom/TsysRoleMapper.xml
+++ b/src/main/resources/mybatis/custom/TsysRoleMapper.xml
@@ -6,12 +6,20 @@
-
- id, name
-
-
+
+
+ select r.id from t_sys_role r
+ LEFT JOIN t_sys_role_user ru ON r.id=ru.sys_role_id
+ where ru.sys_user_id=#{userid}
+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/admin/dict_data/list.html b/src/main/resources/templates/admin/dict_data/list.html
index 49a055cf130331c67d424bbfad368259b3c005e1..1ec872d2c3c483e2589c7204a3521c4ca3811cb4 100644
--- a/src/main/resources/templates/admin/dict_data/list.html
+++ b/src/main/resources/templates/admin/dict_data/list.html
@@ -1,5 +1,5 @@
-
+
@@ -32,25 +32,25 @@
diff --git a/src/main/resources/templates/admin/dict_type/list.html b/src/main/resources/templates/admin/dict_type/list.html
index ffefe3f256985302265ef25f3430f77cb148b75e..ffc98971c3bf48c44b95a160405bb1cd44982535 100644
--- a/src/main/resources/templates/admin/dict_type/list.html
+++ b/src/main/resources/templates/admin/dict_type/list.html
@@ -1,5 +1,5 @@
-
+
@@ -32,11 +32,11 @@
diff --git a/src/main/resources/templates/admin/email/list.html b/src/main/resources/templates/admin/email/list.html
index 21f0cfffeb4b73f6de65f9d9c60ec8ad648b5b07..44d4319c3cef0c3d2b6a0df9386d740a02078ee7 100644
--- a/src/main/resources/templates/admin/email/list.html
+++ b/src/main/resources/templates/admin/email/list.html
@@ -1,5 +1,5 @@
-
+
@@ -32,11 +32,11 @@
diff --git a/src/main/resources/templates/admin/permission/list.html b/src/main/resources/templates/admin/permission/list.html
index a2d46002a263f68b69098589f0f62a98186e24f2..66681a4f6e3311a8895a0562c06df2a35ed75c1e 100644
--- a/src/main/resources/templates/admin/permission/list.html
+++ b/src/main/resources/templates/admin/permission/list.html
@@ -1,5 +1,5 @@
-
+
@@ -31,20 +31,20 @@
diff --git a/src/main/resources/templates/admin/province/list.html b/src/main/resources/templates/admin/province/list.html
index 534c7c3ac18af9c0b73d3c946f73d009f20943e4..f745f7a2beae42bc68197256863dac12ae81af1a 100644
--- a/src/main/resources/templates/admin/province/list.html
+++ b/src/main/resources/templates/admin/province/list.html
@@ -1,5 +1,5 @@
-
+
diff --git a/src/main/resources/templates/admin/province/sysArea/list.html b/src/main/resources/templates/admin/province/sysArea/list.html
index 68b0329d99130be697ae94af9ce4ebc077a955ac..f38ccc9258a8e2eb925f97de78ca4a551ffda1ba 100644
--- a/src/main/resources/templates/admin/province/sysArea/list.html
+++ b/src/main/resources/templates/admin/province/sysArea/list.html
@@ -1,5 +1,5 @@
-
+
@@ -32,11 +32,11 @@
diff --git a/src/main/resources/templates/admin/province/sysProvince/list.html b/src/main/resources/templates/admin/province/sysProvince/list.html
index 53fa833f390d49fe7aadde457c9a1ca821c79e0f..4bf0d60b4676dcc6c7d8168305705670c2b612d0 100644
--- a/src/main/resources/templates/admin/province/sysProvince/list.html
+++ b/src/main/resources/templates/admin/province/sysProvince/list.html
@@ -1,5 +1,5 @@
-
+
@@ -32,11 +32,11 @@
diff --git a/src/main/resources/templates/admin/sysDepartment/list.html b/src/main/resources/templates/admin/sysDepartment/list.html
index 3778268c766e7877ee8a4f164b3f8d52a19c00cd..0205dd9021646d2afdbc11e61ac38e1836aec9a4 100644
--- a/src/main/resources/templates/admin/sysDepartment/list.html
+++ b/src/main/resources/templates/admin/sysDepartment/list.html
@@ -1,5 +1,5 @@
-
+
@@ -31,20 +31,20 @@
diff --git a/src/main/resources/templates/admin/sysInterUrl/list.html b/src/main/resources/templates/admin/sysInterUrl/list.html
index 501ef14f404723125720497266b303fa55cef97e..9ba5d20a706fd3ce602889ca10d1154392532951 100644
--- a/src/main/resources/templates/admin/sysInterUrl/list.html
+++ b/src/main/resources/templates/admin/sysInterUrl/list.html
@@ -1,5 +1,5 @@
-
+
@@ -32,11 +32,11 @@
diff --git a/src/main/resources/templates/admin/user/list.html b/src/main/resources/templates/admin/user/list.html
index e324acf51c2f7f17065e1a3deddfcd6eaad3b7af..6e7b7557097549ecca15be809f129c0931cae600 100644
--- a/src/main/resources/templates/admin/user/list.html
+++ b/src/main/resources/templates/admin/user/list.html
@@ -1,5 +1,5 @@
-
+
@@ -32,11 +32,11 @@