CasbinService 添加 reload

重载 casbin policy
This commit is contained in:
Shikong 2023-05-08 11:51:02 +08:00
parent 45df167315
commit 37598e44fc
5 changed files with 17 additions and 1 deletions

View File

@ -88,4 +88,11 @@ public class TestController {
@RequestParam String method) { @RequestParam String method) {
return JsonResponse.success(casbinService.enforce(identify, system, url, method)); return JsonResponse.success(casbinService.enforce(identify, system, url, method));
} }
@PostJson("/casbin")
@Operation(summary = "重新加载 casbin policy")
public JsonResponse<Void> reloadCasbin(){
casbinService.reload();
return JsonResponse.success(null);
}
} }

View File

@ -36,4 +36,6 @@ public interface CasbinService {
List<String> getRelationForRoleInSystem(String role, String system); List<String> getRelationForRoleInSystem(String role, String system);
boolean delRole(String role, String system); boolean delRole(String role, String system);
void reload();
} }

View File

@ -89,4 +89,9 @@ public class CasbinServiceImpl implements CasbinService {
enforcer.removeFilteredNamedPolicy("p", 0, Permission.Identify.getRoleName(Permission.Identify.ROLE, role), system); enforcer.removeFilteredNamedPolicy("p", 0, Permission.Identify.getRoleName(Permission.Identify.ROLE, role), system);
return true; return true;
} }
@Override
public void reload() {
enforcer.loadPolicy();
}
} }

View File

@ -3,7 +3,9 @@ package cn.skcks.matrix.v2;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Lazy;
@Lazy
@SpringBootApplication(exclude= DataSourceAutoConfiguration.class) @SpringBootApplication(exclude= DataSourceAutoConfiguration.class)
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -50,5 +50,5 @@
</root> </root>
<logger name="cn.skcks.matrix.v2.config" level="DEBUG" /> <logger name="cn.skcks.matrix.v2.config" level="DEBUG" />
<logger name="cn.skcks.matrix.v2.utils.redis" level="DEBUG" /> <logger name="cn.skcks.matrix.v2.utils.redis.RedisUtil" level="DEBUG" />
</configuration> </configuration>