mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-08 17:03:39 +08:00
增加swagger3 支持
This commit is contained in:
@@ -11,5 +11,5 @@ import java.lang.reflect.Method;
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface AopMethodAuthorizeDefinitionCustomizerParser {
|
||||
AuthorizeDefinition parse(Class target, Method method, MethodInterceptorContext context);
|
||||
AuthorizeDefinition parse(Class<?> target, Method method, MethodInterceptorContext context);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ public interface AopMethodAuthorizeDefinitionParser {
|
||||
* @param method method
|
||||
* @return 权限控制定义, 如果不进行权限控制则返回{@code null}
|
||||
*/
|
||||
AuthorizeDefinition parse(Class target, Method method, MethodInterceptorContext context);
|
||||
AuthorizeDefinition parse(Class<?> target, Method method, MethodInterceptorContext context);
|
||||
|
||||
default AuthorizeDefinition parse(Class target, Method method) {
|
||||
default AuthorizeDefinition parse(Class<?> target, Method method) {
|
||||
return parse(target, method, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.hswebframework.web.authorization.basic.aop;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.web.aop.MethodInterceptorContext;
|
||||
import org.hswebframework.web.authorization.annotation.Authorize;
|
||||
@@ -29,11 +30,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@Slf4j
|
||||
public class DefaultAopMethodAuthorizeDefinitionParser implements AopMethodAuthorizeDefinitionParser {
|
||||
|
||||
private Map<CacheKey, AuthorizeDefinition> cache = new ConcurrentHashMap<>();
|
||||
private final Map<CacheKey, AuthorizeDefinition> cache = new ConcurrentHashMap<>();
|
||||
|
||||
private List<AopMethodAuthorizeDefinitionCustomizerParser> parserCustomizers;
|
||||
|
||||
private static Set<String> excludeMethodName = new HashSet<>(Arrays.asList("toString", "clone", "hashCode", "getClass"));
|
||||
private static final Set<String> excludeMethodName = new HashSet<>(Arrays.asList("toString", "clone", "hashCode", "getClass"));
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setParserCustomizers(List<AopMethodAuthorizeDefinitionCustomizerParser> parserCustomizers) {
|
||||
@@ -47,7 +48,7 @@ public class DefaultAopMethodAuthorizeDefinitionParser implements AopMethodAutho
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public AuthorizeDefinition parse(Class target, Method method, MethodInterceptorContext context) {
|
||||
public AuthorizeDefinition parse(Class<?> target, Method method, MethodInterceptorContext context) {
|
||||
if (excludeMethodName.contains(method.getName())) {
|
||||
return null;
|
||||
}
|
||||
@@ -87,28 +88,19 @@ public class DefaultAopMethodAuthorizeDefinitionParser implements AopMethodAutho
|
||||
}
|
||||
}
|
||||
|
||||
public CacheKey buildCacheKey(Class target, Method method) {
|
||||
public CacheKey buildCacheKey(Class<?> target, Method method) {
|
||||
return new CacheKey(ClassUtils.getUserClass(target), method);
|
||||
}
|
||||
|
||||
class CacheKey {
|
||||
private Class type;
|
||||
private Method method;
|
||||
@EqualsAndHashCode
|
||||
static class CacheKey {
|
||||
private final Class<?> type;
|
||||
private final Method method;
|
||||
|
||||
public CacheKey(Class type, Method method) {
|
||||
public CacheKey(Class<?> type, Method method) {
|
||||
this.type = type;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.asList(type, method).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null && this.hashCode() == obj.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.hswebframework.web.authorization.define.AopAuthorizeDefinition;
|
||||
import org.hswebframework.web.authorization.define.ResourceActionDefinition;
|
||||
import org.hswebframework.web.authorization.define.ResourceDefinition;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -24,15 +25,15 @@ public class AopAuthorizeDefinitionParser {
|
||||
DataAccessType.class
|
||||
));
|
||||
|
||||
private Set<Annotation> methodAnnotation;
|
||||
private final Set<Annotation> methodAnnotation;
|
||||
|
||||
private Set<Annotation> classAnnotation;
|
||||
private final Set<Annotation> classAnnotation;
|
||||
|
||||
private Map<Class<? extends Annotation>, List<Annotation>> classAnnotationGroup;
|
||||
private final Map<Class<? extends Annotation>, List<Annotation>> classAnnotationGroup;
|
||||
|
||||
private Map<Class<? extends Annotation>, List<Annotation>> methodAnnotationGroup;
|
||||
private final Map<Class<? extends Annotation>, List<Annotation>> methodAnnotationGroup;
|
||||
|
||||
private DefaultBasicAuthorizeDefinition definition;
|
||||
private final DefaultBasicAuthorizeDefinition definition;
|
||||
|
||||
AopAuthorizeDefinitionParser(Class<?> targetClass, Method method) {
|
||||
definition = new DefaultBasicAuthorizeDefinition();
|
||||
@@ -77,7 +78,7 @@ public class AopAuthorizeDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void initClassDataAccessAnnotation(){
|
||||
private void initClassDataAccessAnnotation() {
|
||||
for (Annotation annotation : classAnnotation) {
|
||||
if (annotation instanceof DataAccessType ||
|
||||
annotation instanceof DataAccess) {
|
||||
@@ -135,7 +136,11 @@ public class AopAuthorizeDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
AopAuthorizeDefinition parse() {
|
||||
AopAuthorizeDefinition parse() {
|
||||
//没有任何注解
|
||||
if (CollectionUtils.isEmpty(classAnnotation) && CollectionUtils.isEmpty(methodAnnotation)) {
|
||||
return EmptyAuthorizeDefinition.instance;
|
||||
}
|
||||
initClassAnnotation();
|
||||
initClassDataAccessAnnotation();
|
||||
initMethodAnnotation();
|
||||
|
||||
@@ -30,7 +30,6 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
|
||||
@JsonIgnore
|
||||
private Class<?> targetClass;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
private Method targetMethod;
|
||||
|
||||
@@ -56,7 +55,9 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
|
||||
));
|
||||
|
||||
public static AopAuthorizeDefinition from(Class<?> targetClass, Method method) {
|
||||
return new AopAuthorizeDefinitionParser(targetClass,method).parse();
|
||||
AopAuthorizeDefinitionParser parser = new AopAuthorizeDefinitionParser(targetClass, method);
|
||||
|
||||
return parser.parse();
|
||||
}
|
||||
|
||||
public void putAnnotation(Authorize ann) {
|
||||
@@ -118,7 +119,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
|
||||
}
|
||||
DataAccessTypeDefinition typeDefinition = new DataAccessTypeDefinition();
|
||||
for (DataAccessType dataAccessType : ann.type()) {
|
||||
if(dataAccessType.ignore()){
|
||||
if (dataAccessType.ignore()) {
|
||||
continue;
|
||||
}
|
||||
typeDefinition.setId(dataAccessType.id());
|
||||
@@ -127,7 +128,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
|
||||
typeDefinition.setConfiguration(dataAccessType.configuration());
|
||||
typeDefinition.setDescription(String.join("\n", dataAccessType.description()));
|
||||
}
|
||||
if(StringUtils.isEmpty(typeDefinition.getId())){
|
||||
if (StringUtils.isEmpty(typeDefinition.getId())) {
|
||||
return;
|
||||
}
|
||||
definition.getDataAccess()
|
||||
@@ -136,7 +137,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
|
||||
}
|
||||
|
||||
public void putAnnotation(ResourceActionDefinition definition, DataAccessType dataAccessType) {
|
||||
if(dataAccessType.ignore()){
|
||||
if (dataAccessType.ignore()) {
|
||||
return;
|
||||
}
|
||||
DataAccessTypeDefinition typeDefinition = new DataAccessTypeDefinition();
|
||||
|
||||
@@ -4,11 +4,13 @@ import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hswebframework.web.authorization.define.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class EmptyAuthorizeDefinition implements AuthorizeDefinition {
|
||||
public class EmptyAuthorizeDefinition implements AopAuthorizeDefinition {
|
||||
|
||||
public static EmptyAuthorizeDefinition instance = new EmptyAuthorizeDefinition();
|
||||
|
||||
@@ -40,4 +42,14 @@ public class EmptyAuthorizeDefinition implements AuthorizeDefinition {
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getTargetClass() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method getTargetMethod() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user