From f34364ab13b5264521025f20bec3772d907df085 Mon Sep 17 00:00:00 2001 From: godchao Date: Wed, 14 Aug 2019 16:06:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=B8=E5=85=B3=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/example/controller/DepartmentController.java | 9 ++++++++- .../diboot/example/controller/DictionaryController.java | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/diboot-example/src/main/java/com/diboot/example/controller/DepartmentController.java b/diboot-example/src/main/java/com/diboot/example/controller/DepartmentController.java index 9aa4b66..e3a8c6d 100644 --- a/diboot-example/src/main/java/com/diboot/example/controller/DepartmentController.java +++ b/diboot-example/src/main/java/com/diboot/example/controller/DepartmentController.java @@ -15,6 +15,8 @@ import com.diboot.example.entity.Organization; import com.diboot.example.entity.Tree; import com.diboot.example.service.DepartmentService; import com.diboot.example.vo.DepartmentVO; +import com.diboot.shiro.authz.annotation.AuthorizationPrefix; +import com.diboot.shiro.authz.annotation.AuthorizationWrapper; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.ModelMap; @@ -32,6 +34,7 @@ import java.util.List; */ @RestController @RequestMapping("/department") +@AuthorizationPrefix(name = "部门管理", code = "department", prefix = "department") public class DepartmentController extends BaseCrudRestController { @Autowired @@ -46,8 +49,8 @@ public class DepartmentController extends BaseCrudRestController { * @return * @throws Exception */ - @RequiresPermissions("department:list") @GetMapping("/list") + @AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表") public JsonResult getVOList(Long orgId, Department department, Pagination pagination, HttpServletRequest request) throws Exception{ if(V.isEmpty(orgId)){ return new JsonResult(Status.FAIL_OPERATION, "请先选择所属公司").bindPagination(pagination); @@ -98,6 +101,7 @@ public class DepartmentController extends BaseCrudRestController { * @throws Exception */ @PostMapping("/") + @AuthorizationWrapper(value = @RequiresPermissions("create"), name = "新建") public JsonResult createEntity(@RequestBody Department entity, BindingResult result, HttpServletRequest request) throws Exception{ boolean success = departmentService.createEntity(entity); @@ -114,6 +118,7 @@ public class DepartmentController extends BaseCrudRestController { * @throws Exception */ @GetMapping("/{id}") + @AuthorizationWrapper(value = @RequiresPermissions("read"), name = "读取") public JsonResult getModel(@PathVariable("id")Long id, HttpServletRequest request) throws Exception{ DepartmentVO vo = departmentService.getViewObject(id, DepartmentVO.class); @@ -127,6 +132,7 @@ public class DepartmentController extends BaseCrudRestController { * @throws Exception */ @PutMapping("/{id}") + @AuthorizationWrapper(value = @RequiresPermissions("update"), name = "更新") public JsonResult updateModel(@PathVariable("id")Long id, @RequestBody Department entity, BindingResult result, HttpServletRequest request) throws Exception{ entity.setId(id); @@ -144,6 +150,7 @@ public class DepartmentController extends BaseCrudRestController { * @throws Exception */ @DeleteMapping("/{id}") + @AuthorizationWrapper(value = @RequiresPermissions("delete"), name = "删除") public JsonResult deleteModel(@PathVariable("id")Long id, HttpServletRequest request) throws Exception{ return super.deleteEntity(id); } diff --git a/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java b/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java index 1e3d5ee..540f351 100644 --- a/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java +++ b/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java @@ -13,6 +13,9 @@ import com.diboot.core.vo.Status; import com.diboot.example.service.DictionaryService; import com.diboot.example.vo.DictionaryListVO; import com.diboot.example.vo.DictionaryVO; +import com.diboot.shiro.authz.annotation.AuthorizationPrefix; +import com.diboot.shiro.authz.annotation.AuthorizationWrapper; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +26,7 @@ import java.util.List; @RestController @RequestMapping("/dictionary") +@AuthorizationPrefix(name = "数据字典", code = "dictionary", prefix = "dictionary") public class DictionaryController extends BaseCrudRestController { private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class); @@ -38,6 +42,7 @@ public class DictionaryController extends BaseCrudRestController { * 获取列表页数据 * */ @GetMapping("/list") + @AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表") public JsonResult list(Dictionary dictionary, Pagination pagination, HttpServletRequest request) throws Exception { //构建查询条件 QueryWrapper queryWrapper = super.buildQueryWrapper(dictionary); @@ -55,6 +60,7 @@ public class DictionaryController extends BaseCrudRestController { * 获取entity详细数据 * */ @GetMapping("/{id}") + @AuthorizationWrapper(value = @RequiresPermissions("read"), name = "读取") public JsonResult getEntity(@PathVariable("id") Long id, HttpServletRequest request){ DictionaryVO vo = dictionaryService.getViewObject(id, DictionaryVO.class); return new JsonResult(vo); @@ -64,6 +70,7 @@ public class DictionaryController extends BaseCrudRestController { * 新建 * */ @PostMapping("/") + @AuthorizationWrapper(value = @RequiresPermissions("create"), name = "新建") public JsonResult create(@RequestBody DictionaryVO entityVO, HttpServletRequest request){ boolean success = dictionaryService.createDictionary(entityVO); if(success){ @@ -77,6 +84,7 @@ public class DictionaryController extends BaseCrudRestController { * 更新 * */ @PutMapping("/{id}") + @AuthorizationWrapper(value = @RequiresPermissions("update"), name = "更新") public JsonResult update(@PathVariable("id")Long id, @RequestBody DictionaryVO entityVO, HttpServletRequest request){ entityVO.setId(id); boolean success = dictionaryService.updateDictionary(entityVO); @@ -91,6 +99,7 @@ public class DictionaryController extends BaseCrudRestController { * 删除 * */ @DeleteMapping("/{id}") + @AuthorizationWrapper(value = @RequiresPermissions("delete"), name = "删除") public JsonResult delete(@PathVariable("id") Long id){ boolean success = dictionaryService.deleteDictionary(id); if(success){