use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity in project spring-boot-student by wyh-spring-ecosystem-student.
the class JsonSerializeTest method authorityRuleJsonSerializeTest.
@Test
public void authorityRuleJsonSerializeTest() {
AuthorityRuleEntity emptyRule = new AuthorityRuleEntity();
Assert.assertTrue("{}".equals(JSON.toJSONString(emptyRule)));
AuthorityRuleEntity authorityRule = new AuthorityRuleEntity();
AuthorityRule rule = new AuthorityRule();
rule.setStrategy(0).setLimitApp("default").setResource("rs");
authorityRule.setRule(rule);
Assert.assertTrue("{\"rule\":{\"limitApp\":\"default\",\"resource\":\"rs\",\"strategy\":0}}".equals(JSON.toJSONString(authorityRule)));
}
use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity in project RuoYi-Cloud-Plus by JavaLionLi.
the class AuthorityRuleController method apiAddAuthorityRule.
@PostMapping("/rule")
@AuthAction(PrivilegeType.WRITE_RULE)
public Result<AuthorityRuleEntity> apiAddAuthorityRule(@RequestBody AuthorityRuleEntity entity) {
Result<AuthorityRuleEntity> checkResult = checkEntityInternal(entity);
if (checkResult != null) {
return checkResult;
}
entity.setId(null);
Date date = new Date();
entity.setGmtCreate(date);
entity.setGmtModified(date);
try {
entity = repository.save(entity);
} catch (Throwable throwable) {
logger.error("Failed to add authority rule", throwable);
return Result.ofThrowable(-1, throwable);
}
if (!publishRules(entity.getApp(), entity.getIp(), entity.getPort())) {
logger.info("Publish authority rules failed after rule add");
}
return Result.ofSuccess(entity);
}
use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity in project Sentinel by alibaba.
the class AuthorityRuleController method apiUpdateParamFlowRule.
@PutMapping("/rule/{id}")
@AuthAction(PrivilegeType.WRITE_RULE)
public Result<AuthorityRuleEntity> apiUpdateParamFlowRule(@PathVariable("id") Long id, @RequestBody AuthorityRuleEntity entity) {
if (id == null || id <= 0) {
return Result.ofFail(-1, "Invalid id");
}
Result<AuthorityRuleEntity> checkResult = checkEntityInternal(entity);
if (checkResult != null) {
return checkResult;
}
entity.setId(id);
Date date = new Date();
entity.setGmtCreate(null);
entity.setGmtModified(date);
try {
entity = repository.save(entity);
if (entity == null) {
return Result.ofFail(-1, "Failed to save authority rule");
}
} catch (Throwable throwable) {
logger.error("Failed to save authority rule", throwable);
return Result.ofThrowable(-1, throwable);
}
if (!publishRules(entity.getApp(), entity.getIp(), entity.getPort())) {
logger.info("Publish authority rules failed after rule update");
}
return Result.ofSuccess(entity);
}
use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity in project Sentinel by alibaba.
the class AuthorityRuleController method apiAddAuthorityRule.
@PostMapping("/rule")
@AuthAction(PrivilegeType.WRITE_RULE)
public Result<AuthorityRuleEntity> apiAddAuthorityRule(@RequestBody AuthorityRuleEntity entity) {
Result<AuthorityRuleEntity> checkResult = checkEntityInternal(entity);
if (checkResult != null) {
return checkResult;
}
entity.setId(null);
Date date = new Date();
entity.setGmtCreate(date);
entity.setGmtModified(date);
try {
entity = repository.save(entity);
} catch (Throwable throwable) {
logger.error("Failed to add authority rule", throwable);
return Result.ofThrowable(-1, throwable);
}
if (!publishRules(entity.getApp(), entity.getIp(), entity.getPort())) {
logger.info("Publish authority rules failed after rule add");
}
return Result.ofSuccess(entity);
}
use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity in project Sentinel by alibaba.
the class JsonSerializeTest method authorityRuleJsonSerializeTest.
@Test
public void authorityRuleJsonSerializeTest() {
AuthorityRuleEntity emptyRule = new AuthorityRuleEntity();
Assert.assertTrue("{}".equals(JSON.toJSONString(emptyRule)));
AuthorityRuleEntity authorityRule = new AuthorityRuleEntity();
AuthorityRule rule = new AuthorityRule();
rule.setStrategy(0).setLimitApp("default").setResource("rs");
authorityRule.setRule(rule);
Assert.assertTrue("{\"rule\":{\"limitApp\":\"default\",\"resource\":\"rs\",\"strategy\":0}}".equals(JSON.toJSONString(authorityRule)));
}
Aggregations