org.apache.shiro.authz.annotation.Logical Java Examples

The following examples show how to use org.apache.shiro.authz.annotation.Logical. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserController.java    From ShiroJwt with MIT License 6 votes vote down vote up
/**
 * 获取用户列表
 * @param 
 * @return java.util.Map<java.lang.String,java.lang.Object>
 * @author dolyw.com
 * @date 2018/8/30 10:41
 */
@GetMapping
@RequiresPermissions(logical = Logical.AND, value = {"user:view"})
public ResponseBean user(@Validated BaseDto baseDto) {
    if (baseDto.getPage() == null || baseDto.getRows() == null) {
        baseDto.setPage(1);
        baseDto.setRows(10);
    }
    PageHelper.startPage(baseDto.getPage(), baseDto.getRows());
    List<UserDto> userDtos = userService.selectAll();
    PageInfo<UserDto> selectPage = new PageInfo<UserDto>(userDtos);
    if (userDtos == null || userDtos.size() < 0) {
        throw new CustomException("查询失败(Query Failure)");
    }
    Map<String, Object> result = new HashMap<String, Object>(16);
    result.put("count", selectPage.getTotal());
    result.put("data", selectPage.getList());
    return new ResponseBean(HttpStatus.OK.value(), "查询成功(Query was successful)", result);
}
 
Example #2
Source File: UpdateLogController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/delete")
@ResponseBody
@RequiresPermissions(value = {"UPDATE_LOG_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult delete(Long id) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = updateLogService.delete(id);
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #3
Source File: AuthorityGroupController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/doAdd")
@ResponseBody
@RequiresPermissions(value = {"AUTHORITY_GROUP_ADD", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult doAdd(AuthorityGroup authorityGroup) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = authorityGroupService.add(authorityGroup);
        if (!success) {
            result.setSuccess(false);
            result.setMessage("添加失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("添加失败:" + e.getMessage());
    }
    return result;
}
 
Example #4
Source File: AuthorityGroupController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/doEdit")
@ResponseBody
@RequiresPermissions(value = {"AUTHORITY_GROUP_UPDATE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult doEdit(AuthorityGroup authorityGroup) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = authorityGroupService.edit(authorityGroup);
        if (!success) {
            result.setSuccess(false);
            result.setMessage("修改失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("修改失败:" + e.getMessage());
    }
    return result;
}
 
Example #5
Source File: AuthorityGroupController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/delete")
@ResponseBody
@RequiresPermissions(value = {"AUTHORITY_GROUP_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult delete(Long id) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = authorityGroupService.delete(id);
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #6
Source File: AuthorityGroupController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/deleteList")
@ResponseBody
@RequiresPermissions(value = {"AUTHORITY_GROUP_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult deleteList(Long[] ids) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = authorityGroupService.deleteList(Arrays.asList(ids));
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #7
Source File: UpdateLogController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/deleteList")
@ResponseBody
@RequiresPermissions(value = {"UPDATE_LOG_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult deleteList(Long[] ids) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = updateLogService.deleteList(Arrays.asList(ids));
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #8
Source File: AdminIndexController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/welcome")
@RequiresPermissions(value = {"ADMIN_VIEW", Const.role.ROLE_SUPER}, logical = Logical.OR)
public String welcome(Model model) {
    long userCount = userService.countUser();
    model.addAttribute("userCount",userCount);

    long bookSourceCount = bookSourceService.countBookSource();
    model.addAttribute("bookSourceCount",bookSourceCount);

    long donateCount = donateService.countDonate();
    model.addAttribute("donateCount",donateCount);

    long updateLogCount = updateLogService.countUpdateLogs();
    model.addAttribute("updateLogCount",updateLogCount);

    BaseQuery notificationQuery = new BaseQuery();
    notificationQuery.set("order","id desc");
    notificationQuery.setSize(6);
    model.addAttribute("notifications",systemNotificationService.getByQuery(notificationQuery).getList());

    return "admin/welcome";
}
 
Example #9
Source File: UserController.java    From ShiroJwt with MIT License 6 votes vote down vote up
/**
 * 获取在线用户(查询Redis中的RefreshToken)
 * @param 
 * @return com.wang.model.common.ResponseBean
 * @author dolyw.com
 * @date 2018/9/6 9:58
 */
@GetMapping("/online")
@RequiresPermissions(logical = Logical.AND, value = {"user:view"})
public ResponseBean online() {
    List<Object> userDtos = new ArrayList<Object>();
    // 查询所有Redis键
    Set<String> keys = JedisUtil.keysS(Constant.PREFIX_SHIRO_REFRESH_TOKEN + "*");
    for (String key : keys) {
        if (JedisUtil.exists(key)) {
            // 根据:分割key,获取最后一个字符(帐号)
            String[] strArray = key.split(":");
            UserDto userDto = new UserDto();
            userDto.setAccount(strArray[strArray.length - 1]);
            userDto = userService.selectOne(userDto);
            // 设置登录时间
            userDto.setLoginTime(new Date(Long.parseLong(JedisUtil.getObject(key).toString())));
            userDtos.add(userDto);
        }
    }
    if (userDtos == null || userDtos.size() < 0) {
        throw new CustomException("查询失败(Query Failure)");
    }
    return new ResponseBean(HttpStatus.OK.value(), "查询成功(Query was successful)", userDtos);
}
 
Example #10
Source File: AuthorityController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/delete")
@ResponseBody
@RequiresPermissions(value = {"AUTHORITY_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult delete(Long id) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = authorityService.delete(id);
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #11
Source File: EmpUserController.java    From frpMgr with MIT License 6 votes vote down vote up
@RequiresPermissions(value={"sys:empUser:edit","sys:empUser:authRole"}, logical=Logical.OR)
@PostMapping(value = "save")
@ResponseBody
public String save(@Validated EmpUser empUser, String oldLoginCode, String op, HttpServletRequest request) {
	if (User.isSuperAdmin(empUser.getUserCode())) {
		return renderResult(Global.FALSE, "非法操作,不能够操作此用户!");
	}
	if (!EmpUser.USER_TYPE_EMPLOYEE.equals(empUser.getUserType())){
		return renderResult(Global.FALSE, "非法操作,不能够操作此用户!");
	}
	if (!Global.TRUE.equals(userService.checkLoginCode(oldLoginCode, empUser.getLoginCode()/*, null*/))) {
		return renderResult(Global.FALSE, text("保存用户失败,登录账号''{0}''已存在", empUser.getLoginCode()));
	}
	if (StringUtils.inString(op, Global.OP_ADD, Global.OP_EDIT)
			&& UserUtils.getSubject().isPermitted("sys:empUser:edit")){
		empUserService.save(empUser);
	}
	if (StringUtils.inString(op, Global.OP_ADD, Global.OP_AUTH)
			&& UserUtils.getSubject().isPermitted("sys:empUser:authRole")){
		userService.saveAuth(empUser);
	}
	return renderResult(Global.TRUE, text("保存用户''{0}''成功", empUser.getUserName()));
}
 
Example #12
Source File: SystemSettingController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/doEdit")
@ResponseBody
@RequiresPermissions(value = {"SYSTEM_SETTING_UPDATE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult doEdit(SystemSetting setting){
    MvcResult result = MvcResult.create();
    try{
        boolean isSuccess = systemSettingService.edit(setting);
        if (!isSuccess){
            result.setSuccess(false);
            result.setMessage("修改失败:未知原因");
        }
    }catch (Exception e){
        result.setSuccess(false);
        result.setCode(2);
        String message = e.getMessage();
        if (StringUtils.isEmpty(message)){
            message = "未知原因";
        }
        result.setMessage("修改失败:"+message);
    }
    return result;
}
 
Example #13
Source File: AuthorityController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/deleteList")
@ResponseBody
@RequiresPermissions(value = {"AUTHORITY_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult deleteList(Long[] ids) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = authorityService.deleteList(Arrays.asList(ids));
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #14
Source File: BookSourceController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/doTest")
@ResponseBody
@RequiresPermissions(value = {"BOOK_SOURCE_VIEW", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult bookSourceTest(@Param("key") String key, BookSource bookSource, int type) {
    MvcResult result;
    try {
        switch (type) {
            case 0:
                result = bookSourceAnalysisService.searchByName(key, bookSource).get();
                break;
            case 1:
                result = bookSourceAnalysisService.loadBookInfo(key, bookSource).get();
                break;
            case 2:
                result = bookSourceAnalysisService.loadContent(key, bookSource).get();
                break;
            default:
                result = MvcResult.createFail("未知测试类型");
                break;
        }
    } catch (Exception e) {
        result = MvcResult.createFail(2, e.getMessage());
        e.printStackTrace();
    }
    return result;
}
 
Example #15
Source File: SystemNotificationController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/delete")
@ResponseBody
@RequiresPermissions(value = {"SYSTEM_NOTIFICATION_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult delete(Long id) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = systemNotificationService.delete(id);
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #16
Source File: SystemNotificationController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/deleteList")
@ResponseBody
@RequiresPermissions(value = {"SYSTEM_NOTIFICATION_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult deleteList(Long[] ids) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = systemNotificationService.deleteList(Arrays.asList(ids));
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #17
Source File: DonateController.java    From DouBiNovel with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/delete")
@ResponseBody
@RequiresPermissions(value = {"DONATE_DELETE", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult delete(Long id) {
    MvcResult result = MvcResult.create();
    try {
        boolean success = donateService.delete(id);
        if (!success) {
            result.setSuccess(false);
            result.setMessage("删除失败:未知原因");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("删除失败:" + e.getMessage());
    }
    return result;
}
 
Example #18
Source File: AuthorizationResourceFilter.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Authorizes the client for the annotated permissions.  If any authorizations fail an {@link AuthorizationException}
 * will be thrown, otherwise the original request is returned.
 */
@Override
public ContainerRequest filter(ContainerRequest request) {
    Subject subject = ThreadContext.getSubject();

    String[] permissions = resolvePermissions(request);

    if (permissions.length == 1 || _logical == Logical.AND) {
        // Shortcut call to check all permissions at once
        subject.checkPermissions(permissions);
    } else {
        // Check each permission until any passes
        boolean anyPermitted = false;
        int p = 0;
        while (!anyPermitted) {
            try {
                subject.checkPermission(permissions[p]);
                anyPermitted = true;
            } catch (AuthorizationException e) {
                // If this is the last permission then pass the exception along
                if (++p == permissions.length) {
                    throw e;
                }
            }
        }
    }

    return request;
}
 
Example #19
Source File: RoleRestControllerImpl.java    From Goku.Framework.CoreUI with MIT License 5 votes vote down vote up
@Override
@RequestMapping("/save")
@RequiresRoles("admin_sys")
@RequiresPermissions(value={"sys:role:add","sys:role:edit"},logical = Logical.OR)
public String save(@RequestBody SysRole sysRole) {
    int result=sysRoleService.saveRole(sysRole);
    if(result>0) {
        return JSON.toJSONString ("true");
    }else{
        return JSON.toJSONString ("false");
    }
}
 
Example #20
Source File: ModuleRestControllerImpl.java    From Goku.Framework.CoreUI with MIT License 5 votes vote down vote up
@Override
@RequestMapping("/save")
@RequiresRoles("admin_sys")
@RequiresPermissions(value={"sys:module:add","sys:module:edit"},logical = Logical.OR)
public String  save(@RequestBody SysModule symodule)
{
    int result=sysModuleService.saveModule(symodule);
    if(result>0) {
        return JSON.toJSONString ("true");
    }else{
        return JSON.toJSONString ("false");
    }
}
 
Example #21
Source File: MenuRestControllerImpl.java    From Goku.Framework.CoreUI with MIT License 5 votes vote down vote up
@Override
@RequestMapping("/save")
@RequiresRoles("admin_sys")
@RequiresPermissions(value={"sys:menu:add","sys:menu:edit"},logical = Logical.OR)
public String  save(@RequestBody SysMenu symenu)
{
    int result=sysMenuService.saveMenu(symenu);
    if(result>0) {
        return JSON.toJSONString ("true");
    }else{
        return JSON.toJSONString ("false");
    }
}
 
Example #22
Source File: DonateController.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/edit")
@RequiresPermissions(value = {"DONATE_VIEW", Const.role.ROLE_SUPER}, logical = Logical.OR)
public String edit(Long id, Model model) {
    Donate data = donateService.getById(id);
    model.addAttribute("data", data);
    return "admin/donate/edit";
}
 
Example #23
Source File: AuthorityController.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/edit")
@RequiresPermissions(value = {"AUTHORITY_VIEW", Const.role.ROLE_SUPER}, logical = Logical.OR)
public String edit(Long id, Model model) {
    List<AuthorityGroup> groups = authorityGroupService.getAll();
    model.addAttribute("groups", groups);
    model.addAttribute("data", authorityService.getById(id));
    return "admin/authority/edit";
}
 
Example #24
Source File: UserController.java    From ShiroJwt with MIT License 5 votes vote down vote up
/**
 * 剔除在线用户
 * @param id
 * @return com.wang.model.common.ResponseBean
 * @author dolyw.com
 * @date 2018/9/6 10:20
 */
@DeleteMapping("/online/{id}")
@RequiresPermissions(logical = Logical.AND, value = {"user:edit"})
public ResponseBean deleteOnline(@PathVariable("id") Integer id) {
    UserDto userDto = userService.selectByPrimaryKey(id);
    if (JedisUtil.exists(Constant.PREFIX_SHIRO_REFRESH_TOKEN + userDto.getAccount())) {
        if (JedisUtil.delKey(Constant.PREFIX_SHIRO_REFRESH_TOKEN + userDto.getAccount()) > 0) {
            return new ResponseBean(HttpStatus.OK.value(), "剔除成功(Delete Success)", null);
        }
    }
    throw new CustomException("剔除失败,Account不存在(Deletion Failed. Account does not exist.)");
}
 
Example #25
Source File: AuthorityController.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/add")
@RequiresPermissions(value = {"AUTHORITY_VIEW", Const.role.ROLE_SUPER}, logical = Logical.OR)
public String add(Model model) {
    List<AuthorityGroup> groups = authorityGroupService.getAll();
    model.addAttribute("groups", groups);
    return "admin/authority/add";
}
 
Example #26
Source File: AuthorityController.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/listJSON")
@ResponseBody
@RequiresPermissions(value = {"AUTHORITY_VIEW", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult listJSON(BaseQuery query) {
    MvcResult result = MvcResult.create();
    try {
        PageTemplate<Authority> pageTemplate = authorityService.getByQuery(query);
        result.setData(pageTemplate);
    } catch (Exception e) {
        result.setCode(-1);
        result.setSuccess(false);
        result.setMessage("获取出错," + e.getMessage());
    }
    return result;
}
 
Example #27
Source File: AuthorityController.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/list")
@RequiresPermissions(value = {"AUTHORITY_VIEW", Const.role.ROLE_SUPER}, logical = Logical.OR)
public String list(Model model) {
    List<AuthorityGroup> groups = authorityGroupService.getAll();
    model.addAttribute("groups", groups);
    return "admin/authority/list";
}
 
Example #28
Source File: AdminController.java    From songjhh_blog with Apache License 2.0 5 votes vote down vote up
@RequiresRoles(value={"blogger","administrator"},logical = Logical.OR)
@RequestMapping("/checkUserList")
private String checkUserList(UserQueryVo userQueryVo, Model model) {
    List<UserCustom> userList = userService.getUserList(userQueryVo);
    model.addAttribute("userList", userList);
    return "admin/userList";
}
 
Example #29
Source File: RestLinkController.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@RequiresPermissions(value = {"link:batchDelete", "link:delete"}, logical = Logical.OR)
@PostMapping(value = "/remove")
@BussinessLog("删除友情链接")
public ResponseVO remove(Long[] ids) {
    if (null == ids) {
        return ResultUtil.error(500, "请至少选择一条记录");
    }
    for (Long id : ids) {
        linkService.removeByPrimaryKey(id);
    }
    return ResultUtil.success("成功删除 [" + ids.length + "] 个友情链接");
}
 
Example #30
Source File: DonateController.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, value = "/doAdd")
@ResponseBody
@RequiresPermissions(value = {"DONATE_ADD", Const.role.ROLE_SUPER}, logical = Logical.OR)
public MvcResult doAdd(Donate data) {
    MvcResult result = MvcResult.create();
    try {
        if (StringUtils.isEmpty(data.getName())) {
            result.setSuccess(false);
            result.setMessage("添加失败:捐赠人姓名不能为空");
        }else if (StringUtils.isEmpty(data.getNickName())) {
            result.setSuccess(false);
            result.setMessage("添加失败:捐赠人昵称不能为空");
        }else if (StringUtils.isEmpty(data.getDonateMoney())) {
            result.setSuccess(false);
            result.setMessage("添加失败:捐赠金额不能为空");
        } else if (StringUtils.isEmpty(data.getDonateSource())) {
            result.setSuccess(false);
            result.setMessage("添加失败:捐赠方式不能为空");
        } else {
            boolean success = donateService.add(data);
            if (!success) {
                result.setSuccess(false);
                result.setMessage("添加失败:未知原因");
            }
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("添加失败:" + e.getMessage());
    }
    return result;
}