Hzero@Permission注解解析
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package io.choerodon.swagger.annotation;
import iam.ResourceLevel;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import swagger.PermissionStatus;
import org.springframework.http.HttpMethod;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Permission {
String code()default"";
String[]roles()default{};
opportunity怎么读
ResourceLevel level()default ResourceLevel.PROJECT;
boolean permissionLogin()default fal;
boolean permissionPublic()default fal;
boolean permissionWithin()default fal;
hayabusaboolean permissionSign()default fal;
String[]tags()default{};
PermissionStatus[]status()default{PermissionStatus.NONE};
pengliString upgradeApiPath()default"";
HttpMethod upgradeApiMethod()default HttpMethod.GET;
}
这个注解与@EnableChoerodonResourceServer注解相结合,去除了curity的基本认证,加⼊了⼀个JwtTokenFilter过滤器进⾏⽤户权限的拦截。并且这个过滤器与@Permission联系起来,通过获取注解的配置来判断是否需要拦截请求
public void doFilter(ServletRequest request, ServletRespon respon, FilterChain chain)throws IOException, ServletException {
HttpServletRequest httpRequest =(HttpServletRequest)request;
String[] var5 =this.skipPath;
int var6 = var5.length;
for(int var7 =0; var7 < var6;++var7){
String path = var5[var7];
if(path.RequestURI())){
chain.doFilter(request, respon);
return;
}
}
Iterator var14 =this.publicPermissions.iterator();
while(var14.hasNext()){
PublicPermission publicPermission =(();
if(MATCHER.match(publicPermission.path, RequestURI())&& hod.Method())){ chain.doFilter(request, respon);
return;
}
}
try{
Authentication authentication =act(httpRequest);
欧盟的英文缩写if(authentication == null){
if(this.isAuthenticated()){
LOGGER.debug("Clearing curity context.");
SecurityContextHolder.clearContext();
}
LOGGER.debug("No Jwt token in request, will continue chain.");
((HttpServletRespon)respon).ndError(401,"No Jwt token in request.");
return;
}
request.tAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE, Principal());
if(authentication instanceof AbstractAuthenticationToken){
AbstractAuthenticationToken needsDetails =(AbstractAuthenticationToken)authentication;
needsDetails.tDetails(new OAuth2AuthenticationDetails(httpRequest));
}
Authentication authResult =this.authenticate(authentication);
LOGGER.debug("Authentication success: {}", authResult);
chain.doFilter(request, respon);
}catch(OAuth2Exception var12){
LOGGER.debug("Authentication request failed: ", var12);
((HttpServletRespon)respon).ndError(401,"Invalid JWT token.");
}finally{
SecurityContextHolder.clearContext();
linsky}
}
@Permission注解的解析主要由ApplicationPermissionParrImpl这个类进⾏解析
private void findAndParController(){
List<PermissionData> permissionDataList =new ArrayList();
String[] beanNames =BeanNamesForType(Object.class);
if(ArrayUtils.isNotEmpty(beanNames)){
Class<?> beanType = null;
String[] var4 = beanNames;
int var5 = beanNames.length;
for(int var6 =0; var6 < var5;++var6){
String beanName = var4[var6];
if(!beanName.startsWith("scopedTarget.")){
try{
beanType =Type(beanName);
if(ClassUtils.isCglibProxyClass(beanType)){
beanType = Superclass();
}
}catch(Throwable var9){
if(LOGGER.isDebugEnabled()){
LOGGER.debug("Could not resolve target class for bean with name '"+ beanName +"'", var9);
}
}
Null(beanType)&&this.isHandler(beanType)){
permissionDataList.addAll(this.ServiceName(beanType), beanName, beanType));//解析controller }
信件英文
}
}
this.applicationPermissionRepository.overwrite(permissionDataList);
this.applicationContext.publishEvent(new ApplicationPermissionPardEvent(this));
}
}
private List<PermissionData>parController(String rviceName, String controllerName, Class<?> clazz){
LOGGER.debug("Start Par Service [{}] : Controller [{}] Permission", rviceName, controllerName);
List<PermissionData> permissionDataList =new ArrayList();
Api controllerApi =(Api)AnnotatedElementUtils.findMergedAnnotation(clazz, Api.class);
String resourceCode =ResourceCode(controllerApi, SimpleName());
if(StringUtils.isBlank(resourceCode)){
LOGGER.warn("Controller's Resource Code Is Empty, Skip Par Permission");
ptyList();
}el{
RequestMapping controllerMapping =(RequestMapping)AnnotatedElementUtils.findMergedAnnotation(clazz, RequestMapping.class); String[] controllerPaths = null;
Null(controllerMapping)){
controllerPaths = controllerMapping.value();
}
if(ArrayUtils.isEmpty(controllerPaths)){
controllerPaths =new String[]{""};
}
Method[] var9 = Methods();
int var10 = var9.length;
for(int var11 =0; var11 < var10;++var11){
Method method = var9[var11];
permissionDataList.addAll(this.parMethod(rviceName, method, resourceCode, controllerPaths));//解析⽅法}
LOGGER.debug("Finished Par Service [{}] : Controller [{}] Permission", rviceName, controllerName);
return permissionDataList;
}bedbug
}
private List<PermissionData>parMethod(String rviceName, Method method, String resourceCode, String[] controllerPaths){
List<PermissionData> permissionDataList =new ArrayList();
RequestMapping methodMapping =(RequestMapping)AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
Null(methodMapping)){
the rockPermission permission =(Permission)AnnotationUtils.findAnnotation(method, Permission.class);
if(Objects.isNull(permission)){
LOGGER.warn("Method [{}.{}] Without @{} Annotation, U Default Parameters To Define Permissio
n Data",new Object[]{DeclaringC lass().getCanonicalName(), Name(), CanonicalName()});
ptyList();
}
String[] methodPaths = methodMapping.value();
if(ArrayUtils.isEmpty(methodPaths)){
methodPaths =new String[]{""};
}
RequestMethod[] requestMethods = hod();
if(ArrayUtils.isEmpty(requestMethods)){
requestMethods = RequestMethod.values();
}
ApiOperation operation =(ApiOperation)AnnotationUtils.findAnnotation(method, ApiOperation.class);
String description = null;
Null(operation)){
description = operation.value();
}
String methodName = Name();
RequestMethod[] var15 = requestMethods;
int var16 = requestMethods.length;
for(int var17 =0; var17 < var16;++var17){
RequestMethod requestMethod = var15[var17];
String requestMethodString = requestMethod.name().toLowerCa();
int index =0;
String[] var19 = controllerPaths;
int var20 = controllerPaths.length;
for(int var21 =0; var21 < var20;++var21){
String controllerPath = var19[var21];
String[] var23 = methodPaths;
ca western rerve universityint var24 = methodPaths.length;
for(int var25 =0; var25 < var24;++var25){
String methodPath = var23[var25];
++index;
permissionDataList.add(this.builtPermissionData(rviceName, resourceCode, controllerPaths.lengt
h, methodPaths.length, requestMethods .length, description, permission, methodName, requestMethodString, index, controllerPath, methodPath));
}
}
}
}
帝释天英文return permissionDataList;
}