package com.wanzi.interceptor;
import java.lang.reflect.Method;
import com.wanzi.annotation.MenuAuth;
import com.wanzi.annotation.UnAuth;
import com.wanzi.bean.SysLoginAdmin;
import com.wanzi.entity.SysAdmin;
import com.wanzi.service.SysAdminService;
import com.wanzi.util.WebUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 系统端权限登录校验
*/
@Slf4j
public class SysAuthInterceptor extends HandlerInterceptorAdapter {
@Autowired
private SysAdminService adminService;
/**
* This implementation always returns {@code true}.
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
MenuAuth menuAuth = null;
log.error("后端权限开始判断");
HandlerMethod handlerMethod = (HandlerMethod) handler;
Class clasz = handlerMethod.getBean().getClass();
//不需要检验授权的可以跳过
if (clasz.isAnnotationPresent(UnAuth.class)) {
return true;
}
//通过匹配找到url匹配的需要检验的方法注解MenuAuth
Method[] methods = clasz.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(RequestMapping.class)) {
if (method.isAnnotationPresent(UnAuth.class)) {
RequestMapping mapping = method.getAnnotation(RequestMapping.class);
for (String str : mapping.path()) {
if (request.getRequestURI().indexOf(str) != -1) {
return true;
}
}
} else if (method.isAnnotationPresent(MenuAuth.class)) { // 菜单校验获取菜单
RequestMapping mapping = method.getAnnotation(RequestMapping.class);
for (String str : mapping.path()) {
if (request.getRequestURI().indexOf(str) != -1) {
menuAuth = method.getAnnotation(MenuAuth.class);
break;
}
}
if (menuAuth == null) {
for (String str : mapping.value()) {
if (request.getRequestURI().indexOf(str) != -1) {
menuAuth = method.getAnnotation(MenuAuth.class);
break;
}
}
}
if (menuAuth != null) {
break;
}
}
}
}
log.error("进入权限判断");
SysLoginAdmin loginAdmin = WebUtils.getSysLoginAdmin();
if (loginAdmin != null) {
SysAdmin sysAdmin = adminService.getSysAdminById(loginAdmin.getId());
if (sysAdmin != null) {
if (sysAdmin.getStatus() == SysAdmin.STATUS_DISABLE) {
throw new Exception("账号已停用,请联系管理员");
}
if (menuAuth != null
&& !loginAdmin.checkMenuAuth(request.getRequestURI(), menuAuth)) {
throw new Exception("无访问权限");
}
return true;
}
throw new Exception("账号不存在,请重新登录");
}
throw new Exception("账号未登录,请重新登录");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
spring-web搭建项目
共147个文件
jar:69个
xml:32个
class:24个
需积分: 0 0 下载量 139 浏览量
2024-01-31
10:42:58
上传
评论
收藏 37.06MB ZIP 举报
温馨提示
这是文章的https://blog.csdn.net/weixin_36667844/article/details/135926225的案例
资源推荐
资源详情
资源评论
收起资源包目录
spring-web搭建项目 (147个子文件)
SysAdmin.class 6KB
SysAdmin.class 6KB
SysAuthInterceptor.class 4KB
SysAuthInterceptor.class 4KB
ExceptionHandler.class 2KB
ExceptionHandler.class 2KB
TestController.class 2KB
TestController.class 2KB
SimpleHibernateTemplate.class 2KB
SimpleHibernateTemplate.class 2KB
SysAdminService.class 1KB
SysAdminService.class 1KB
MenuAuth.class 1KB
MenuAuth.class 1KB
WebUtils.class 1KB
WebUtils.class 1KB
SysAdminDao.class 916B
SysAdminDao.class 916B
SysLoginAdmin.class 835B
SysLoginAdmin.class 835B
Constant.class 395B
Constant.class 395B
UnAuth.class 294B
UnAuth.class 294B
spring-web.iml 2KB
hibernate-core-5.0.9.Final.jar 5.34MB
hibernate-core-5.0.9.Final.jar 5.34MB
tomcat-embed-core-8.5.4.jar 2.84MB
lombok-1.18.24.jar 1.88MB
lombok-1.18.24.jar 1.88MB
spring-core-5.2.3.RELEASE.jar 1.37MB
spring-core-5.2.3.RELEASE.jar 1.37MB
spring-web-5.2.3.RELEASE.jar 1.36MB
spring-web-5.2.3.RELEASE.jar 1.36MB
spring-context-5.2.3.RELEASE.jar 1.16MB
spring-context-5.2.3.RELEASE.jar 1.16MB
mysql-connector-java-5.1.39.jar 966KB
mysql-connector-java-5.1.39.jar 966KB
spring-webmvc-5.2.3.RELEASE.jar 924KB
spring-webmvc-5.2.3.RELEASE.jar 924KB
javassist-3.20.0-GA.jar 733KB
javassist-3.20.0-GA.jar 733KB
spring-beans-5.2.3.RELEASE.jar 669KB
spring-beans-5.2.3.RELEASE.jar 669KB
spring-test-5.2.3.RELEASE.jar 663KB
spring-test-5.2.3.RELEASE.jar 663KB
spring-messaging-5.2.3.RELEASE.jar 530KB
spring-messaging-5.2.3.RELEASE.jar 530KB
log4j-1.2.17.jar 478KB
log4j-1.2.17.jar 478KB
spring-jdbc-5.2.3.RELEASE.jar 397KB
spring-jdbc-5.2.3.RELEASE.jar 397KB
spring-aop-5.2.3.RELEASE.jar 364KB
spring-aop-5.2.3.RELEASE.jar 364KB
spring-tx-5.2.3.RELEASE.jar 307KB
spring-tx-5.2.3.RELEASE.jar 307KB
dom4j-1.6.1.jar 307KB
dom4j-1.6.1.jar 307KB
spring-expression-5.2.3.RELEASE.jar 275KB
spring-expression-5.2.3.RELEASE.jar 275KB
spring-jms-5.2.3.RELEASE.jar 256KB
spring-jms-5.2.3.RELEASE.jar 256KB
spring-orm-5.2.3.RELEASE.jar 196KB
spring-orm-5.2.3.RELEASE.jar 196KB
spring-context-support-5.2.3.RELEASE.jar 178KB
spring-context-support-5.2.3.RELEASE.jar 178KB
commons-dbcp2-2.1.1.jar 170KB
commons-dbcp2-2.1.1.jar 170KB
hibernate-jpa-2.1-api-1.0.0.Final.jar 111KB
hibernate-jpa-2.1-api-1.0.0.Final.jar 111KB
commons-pool2-2.4.2.jar 109KB
commons-pool2-2.4.2.jar 109KB
hibernate-commons-annotations-5.0.1.Final.jar 74KB
hibernate-commons-annotations-5.0.1.Final.jar 74KB
commons-fileupload-1.3.1.jar 67KB
commons-fileupload-1.3.1.jar 67KB
jboss-logging-3.3.0.Final.jar 65KB
jboss-logging-3.3.0.Final.jar 65KB
spring-oxm-5.2.3.RELEASE.jar 62KB
spring-oxm-5.2.3.RELEASE.jar 62KB
commons-logging-1.2.jar 60KB
commons-logging-1.2.jar 60KB
spring-aspects-5.2.3.RELEASE.jar 46KB
spring-aspects-5.2.3.RELEASE.jar 46KB
slf4j-api-1.7.36.jar 40KB
slf4j-api-1.7.36.jar 40KB
javax.transaction-api-1.2.jar 30KB
javax.transaction-api-1.2.jar 30KB
slf4j-log4j12-1.7.25.jar 12KB
slf4j-log4j12-1.7.25.jar 12KB
spring-instrument-5.2.3.RELEASE.jar 7KB
spring-instrument-5.2.3.RELEASE.jar 7KB
aopalliance-1.0.jar 4KB
aopalliance-1.0.jar 4KB
SysAuthInterceptor.java 3KB
MenuAuth.java 2KB
SimpleHibernateTemplate.java 1KB
ExceptionHandler.java 1KB
SysAdmin.java 1KB
TestController.java 1KB
共 147 条
- 1
- 2
资源评论
明夕何夕帅
- 粉丝: 98
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab实现车牌识别程序,和论文,自己做的,做毕业设计的可以看看 .rar
- Windows系统下安装与配置Neo4j的步骤
- 基于matlab实现潮流计算和最优潮流计算的程序1,对毕业设计有一定用处.rar
- 基于大数据学习资源推荐系统的设计与实现(部署视频)-kaic.mp4
- 哈工大形式语言和自动机2022期末含答案
- Windows系统下安装与配置Neo4j的步骤
- 哈希算法(Hash Algorithm)是一种将任意长度的二进制数据映射为较短的、固定长度的二进制值的函数.txt
- Windows系统下安装与配置Neo4j的步骤
- 在二叉树或更复杂的树形结构中,先序输出叶结点.txt
- 列出所有祖先结点的概念通常与树形结构或图论中的节点相关.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功