Merge branch 'main' of D:\CF_work\ideaWorkSpace\business-card with conflicts.

This commit is contained in:
ly19960718 2021-01-28 17:26:31 +08:00
parent d7e624fd95
commit c7212662b1
2 changed files with 8 additions and 40 deletions

View File

@ -3,24 +3,18 @@ package cn.com.tenlion.config;
import cn.com.tenlion.accesstokenmanager.AccessTokenManager; import cn.com.tenlion.accesstokenmanager.AccessTokenManager;
import cn.com.tenlion.pojo.dtos.carduser.CardUserDTO; import cn.com.tenlion.pojo.dtos.carduser.CardUserDTO;
import cn.com.tenlion.pojo.vos.carduser.CardUserVO;
import cn.com.tenlion.service.carduser.ICardUserService; import cn.com.tenlion.service.carduser.ICardUserService;
import cn.com.tenlion.util.AesUtil; import cn.com.tenlion.util.AesUtil;
import cn.com.tenlion.util.annotation.AccessRightsCheck;
import cn.com.tenlion.util.enumeration.Auth;
import com.github.pagehelper.util.StringUtil; import com.github.pagehelper.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.lang.annotation.Annotation; import java.io.IOException;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Method;
/** /**
* TODO * TODO
@ -44,33 +38,8 @@ public class CheckAuth implements HandlerInterceptor {
if(path.contains("release")){ if(path.contains("release")){
return true; return true;
} }
/**
* 2021年1月28日10:28:38
* CBC Start
* 通过Controller中方法上的注解进行权限控制与放行
*/
// 获得类的请求
HandlerMethod handlerMethod = null;
if(handler instanceof HandlerMethod) {
handlerMethod = (HandlerMethod) handler;
}else{
return true;
}
// 权限校验的注解
Method m = handlerMethod.getMethod();
AccessRightsCheck accessRightsCheck = m.getAnnotation(AccessRightsCheck.class);
if(accessRightsCheck != null) {
if(accessRightsCheck != null) {
// 不校验
if(Auth.NOCHECK.equals(accessRightsCheck.auth())) {
return true;
}
}
}
/**
* 2021年1月28日10:34:47
* CBC End
*/
String token = request.getHeader("token"); String token = request.getHeader("token");
if(token == null || StringUtil.isEmpty(token)){ if(token == null || StringUtil.isEmpty(token)){
// response.setStatus(response.SC_METHOD_NOT_ALLOWED); // response.setStatus(response.SC_METHOD_NOT_ALLOWED);

View File

@ -1,6 +1,5 @@
package cn.com.tenlion.config; package cn.com.tenlion.config;
import org.apache.catalina.startup.UserConfig;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
@ -14,7 +13,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @date 2021/1/27 12:34 * @date 2021/1/27 12:34
*/ */
@Configuration @Configuration
public class LoginConfig implements WebMvcConfigurer { public class LoginConfigInterceptors implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
@ -24,8 +23,8 @@ public class LoginConfig implements WebMvcConfigurer {
} }
@Bean @Bean
private static CheckAuth checkAuth() { private static CheckAuthInterceptor checkAuth() {
return new CheckAuth(); return new CheckAuthInterceptor();
} }
} }