| | |
| | | |
| | | Class<?> beanType = handlerMethod.getBeanType(); |
| | | Boolean checkFlag = false; |
| | | if(!( |
| | | beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class) |
| | | || beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class)) |
| | | ){ |
| | | return true; |
| | | } |
| | | // 有 @LoginRequired 注解,需要登录认证 客户端使用 |
| | | if ((beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class))) { |
| | | if (!checkFlag && (beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class))) { |
| | | String token = request.getHeader(JwtTokenUtil.HEADER_KEY); |
| | | if(StringUtils.isBlank(token)){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | |
| | | if (StringUtils.isNotBlank(token)) { |
| | | checkFlag = checkLogin(request,response,token); |
| | | } |
| | | // 有 @UserLoginRequired 注解,需要登录认证 内部人员使用 |
| | | } |
| | | if(beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class)){ |
| | | if(!checkFlag && (beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class))){ |
| | | String token = request.getHeader(JwtTokenUtil.HEADER_KEY); |
| | | if(StringUtils.isBlank(token)){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | |
| | | if (StringUtils.isNotBlank(token)) { |
| | | checkFlag = checkPersonnelLogin(request,response,token); |
| | | } |
| | | } |
| | | if(!checkFlag){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | public Boolean checkLogin(HttpServletRequest request, HttpServletResponse response,String token){ |
| | | try { |
| | | String tokenRedis = (String) redisTemplate.opsForValue().get(ZTConstants.CUSTOMER+"_"+token); |
| | | if(StringUtils.isNotBlank(tokenRedis)){ |
| | | if(!tokenRedis.equals(token)){ |
| | | throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录"); |
| | | } |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录"); |
| | | if(StringUtils.isBlank(tokenRedis)){ |
| | | return false; |
| | | } |
| | | Long memberId = getTokenId(token); |
| | | Member member = dao.queryForObject(" select * from `member` where id = ? limit 1 ", new BeanPropertyRowMapper<>(Member.class),memberId); |
| | |
| | | public Boolean checkPersonnelLogin(HttpServletRequest request, HttpServletResponse response,String token){ |
| | | try { |
| | | String tokenRedis = (String) redisTemplate.opsForValue().get(ZTConstants.BUSINESS+"_"+token); |
| | | if(StringUtils.isNotBlank(tokenRedis)){ |
| | | if(!tokenRedis.equals(token)){ |
| | | throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录"); |
| | | } |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录"); |
| | | if(StringUtils.isBlank(tokenRedis)){ |
| | | return false; |
| | | } |
| | | Long userId = getTokenId(token); |
| | | Users users = dao.queryForObject(" select * from `users` where id = ? limit 1 ", new BeanPropertyRowMapper<>(Users.class),userId); |
| | |
| | | public Long getTokenId(String token){ |
| | | try { |
| | | Integer lastIndex = token.lastIndexOf("_")+1; |
| | | Long tokenId = Long.valueOf(token.substring(0,lastIndex)); |
| | | Long tokenId = Long.valueOf(token.substring(lastIndex)); |
| | | return tokenId; |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |