| | |
| | | package com.ruoyi.gateway.filter; |
| | | |
| | | import com.ruoyi.common.core.exception.auth.NotPermissionException; |
| | | import com.ruoyi.gateway.config.properties.AntiShakeProperties; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | /** |
| | | * 防抖处理 |
| | | */ |
| | | public void antiShake(ServerHttpRequest request) throws Exception{ |
| | | public void antiShake(ServerHttpRequest request) { |
| | | HttpMethod method = request.getMethod(); |
| | | if(HttpMethod.OPTIONS == method || !antiShakeProperties.getEnable()){ |
| | | return; |
| | |
| | | /** |
| | | * 验证token |
| | | * @param request |
| | | * @throws Exception |
| | | */ |
| | | public void verifyToken(ServerHttpRequest request) throws Exception{ |
| | | public void verifyToken(ServerHttpRequest request) { |
| | | String token = getToken(request); |
| | | if (StringUtils.isEmpty(token)) { |
| | | throw new RuntimeException("令牌不能为空"); |
| | | throw new NotPermissionException("令牌不能为空"); |
| | | } |
| | | Claims claims = JwtUtils.parseToken(token); |
| | | if (claims == null) { |
| | | throw new RuntimeException("令牌已过期或验证不正确!"); |
| | | throw new NotPermissionException("令牌已过期或验证不正确!"); |
| | | } |
| | | String userid = JwtUtils.getUserId(claims); |
| | | if (StringUtils.isEmpty(userid)) { |
| | | throw new RuntimeException("令牌验证失败"); |
| | | throw new NotPermissionException("令牌验证失败"); |
| | | } |
| | | } |
| | | |