mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
submitToken 注解处理
This commit is contained in:
13
src/main/java/cn/lihongjie/coal/annotation/SubmitToken.java
Normal file
13
src/main/java/cn/lihongjie/coal/annotation/SubmitToken.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package cn.lihongjie.coal.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
public @interface SubmitToken {
|
||||
|
||||
boolean value() default true;
|
||||
}
|
||||
@@ -81,6 +81,10 @@ public class ResourceEntity extends CommonEntity {
|
||||
private Boolean rateLimit;
|
||||
|
||||
|
||||
@Comment("是否校验提交token")
|
||||
private Boolean submitToken;
|
||||
|
||||
|
||||
|
||||
private static String getParent(String path) {
|
||||
log.debug("getParent {}", path);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cn.lihongjie.coal.resource.service;
|
||||
|
||||
import cn.lihongjie.coal.annotation.Anonymous;
|
||||
import cn.lihongjie.coal.annotation.RateLimit;
|
||||
import cn.lihongjie.coal.annotation.SignCheck;
|
||||
import cn.lihongjie.coal.annotation.SubmitToken;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
@@ -202,13 +204,22 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
entity.setType("3");
|
||||
entity.setName("");
|
||||
entity.setUrl(allUrl._1);
|
||||
entity.setAnonymous(StringUtils.equalsAny(allUrl._1, "/login", "/logout", "/genCaptcha"));
|
||||
|
||||
Anonymous anonymous = allUrl._2.getMethodAnnotation(Anonymous.class);
|
||||
|
||||
entity.setAnonymous(
|
||||
StringUtils.equalsAny(allUrl._1, "/login", "/logout", "/genCaptcha")
|
||||
|| (anonymous != null && anonymous.value()));
|
||||
|
||||
RateLimit rateLimit = allUrl._2.getMethodAnnotation(RateLimit.class);
|
||||
entity.setRateLimit(rateLimit == null || rateLimit.value());
|
||||
|
||||
SignCheck signCheck = allUrl._2.getMethodAnnotation(SignCheck.class);
|
||||
entity.setSignCheck(signCheck == null || signCheck.value());
|
||||
|
||||
SubmitToken submitToken = allUrl._2.getMethodAnnotation(SubmitToken.class);
|
||||
entity.setSubmitToken(submitToken == null || submitToken.value());
|
||||
|
||||
root.addChildren(entity);
|
||||
}
|
||||
|
||||
@@ -249,18 +260,12 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
.findAny();
|
||||
}
|
||||
|
||||
|
||||
@Cacheable(cacheNames = Constants.CACHE_RESOURCE_BY_URL_2, key = "#url")
|
||||
public Optional<ResourceDto> findUrlFromCache2(String url) {
|
||||
|
||||
|
||||
|
||||
return Optional.ofNullable(repository.findByCodeAndType(url, "3"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void clearCache() {
|
||||
|
||||
cacheManager.getCache(Constants.CACHE_RESOURCE).clear();
|
||||
|
||||
Reference in New Issue
Block a user