增加相关权限注解

This commit is contained in:
godchao 2019-08-14 16:06:51 +08:00
parent 18bcde186d
commit f34364ab13
2 changed files with 17 additions and 1 deletions

View File

@ -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);
}

View File

@ -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<Dictionary> 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){