首页>代码>Spring Boot+layui+Apache Shiro+MyBatis前后端分离版开发通用网站后台管理系统-呕心原创力作>/Easy9/src/main/java/org/colin/aop/aspect/LoginCheckAspect.java
package org.colin.aop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.*; import org.colin.constants.Constant; import org.colin.exception.ServiceException; import org.colin.model.entity.SysUser; import org.colin.service.UserService; import org.colin.utils.JwtTokenUtil; import org.colin.utils.Tool; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; /** * @Description: AOP切面实现登录验证 * @ClassName: LoginCheckAspect * @Author: wujiangbo * @Date: 2020/6/23 0023 10:32 * @Version: 1.1.0 */ @Component @Aspect @Slf4j public class LoginCheckAspect { @Autowired private UserService userService; /** * 此处的切点是注解的方式 */ @Pointcut("@annotation(org.colin.aop.annotation.LoginCheck)") public void pointCut() { } /* * @Author: wujiangbo * @Date: 2020/6/23 0023 11:09 */ @Before(value = "pointCut()") public void before(JoinPoint joinPoint) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); String access_token = request.getHeader(Constant.ACCESS_TOKEN);//获取前端传来的token log.info("北方社区-前端传入access_token={}", access_token); String desc = "未登录,请先登录!"; if(Tool.isBlank(access_token) || "undefined".equalsIgnoreCase(access_token)){ throw new ServiceException(9999, desc); } String user_id = JwtTokenUtil.getUserId(request.getHeader(Constant.ACCESS_TOKEN)); if(Tool.isBlank(user_id)){ throw new ServiceException(9999, desc); }else{ SysUser user = userService.detailInfo(user_id); if(user == null){ throw new ServiceException(9999, desc); } log.info("北方社区-用户[{}]登录校验成功", user.getRealName()); } } }
最近下载更多
adminstort LV3
4月15日
微信网友_6902352269217792 LV3
3月12日
WBelong LV7
2023年12月27日
aaaaooa LV4
2023年11月3日
微信网友_6639255622307840 LV1
2023年9月7日
zhy1989wz LV6
2023年7月6日
GakkiMarryMe LV9
2023年5月20日
哇塞塞哈哈哈 LV8
2023年5月5日
sandihha LV9
2022年12月28日
jiangxiaoyu LV17
2022年11月20日
最近浏览更多
wpsWPS1212 LV1
4月19日
adminstort LV3
4月15日
荣》Cowboy LV12
4月11日
微信网友_6927932988952576 LV12
3月31日
xiaozhi丶 LV14
3月24日
953558449
3月22日
暂无贡献等级
quartz LV7
3月13日
微信网友_6902352269217792 LV3
3月12日
ljhgff LV1
2月8日
heshao LV2
2月7日