|
@@ -1,83 +0,0 @@
|
|
|
-package cn.iselab.mooctest.site.permission;
|
|
|
|
|
-
|
|
|
|
|
-import cn.iselab.mooctest.site.models.User;
|
|
|
|
|
-import cn.iselab.mooctest.site.service.AssignedTaskService;
|
|
|
|
|
-import cn.iselab.mooctest.site.service.TaskService;
|
|
|
|
|
-import cn.iselab.mooctest.site.service.UserService;
|
|
|
|
|
-import org.apache.shiro.SecurityUtils;
|
|
|
|
|
-import org.apache.shiro.authz.Permission;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @author sean
|
|
|
|
|
- * @date 2017-06-25.
|
|
|
|
|
- */
|
|
|
|
|
-public class TaskPermission implements Permission {
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private AssignedTaskService assignedTaskService;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private TaskService taskService;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private UserService userService;
|
|
|
|
|
-
|
|
|
|
|
- private String resource;
|
|
|
|
|
-
|
|
|
|
|
- private String operation;
|
|
|
|
|
-
|
|
|
|
|
- private String instanceId;
|
|
|
|
|
-
|
|
|
|
|
- public TaskPermission() {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public TaskPermission(String permissionStr) {
|
|
|
|
|
- String[] strs = permissionStr.split("\\+");
|
|
|
|
|
- if (strs.length > 1) {
|
|
|
|
|
- this.resource = strs[1];
|
|
|
|
|
- }
|
|
|
|
|
- if (this.resource == null || "".equals(this.resource)) {
|
|
|
|
|
- this.resource = "*";
|
|
|
|
|
- }
|
|
|
|
|
- if (strs.length > 2) {
|
|
|
|
|
- this.operation = strs[2];
|
|
|
|
|
- }
|
|
|
|
|
- if (strs.length > 3) {
|
|
|
|
|
- this.instanceId = strs[3];
|
|
|
|
|
- }
|
|
|
|
|
- if (this.instanceId == null || "".equals(this.instanceId)) {
|
|
|
|
|
- this.instanceId = "*";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean implies(Permission p) {
|
|
|
|
|
- if (!(p instanceof TaskPermission)) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- TaskPermission tp = (TaskPermission) p;
|
|
|
|
|
- String username = SecurityUtils.getSubject().getPrincipal().toString();
|
|
|
|
|
- User user = userService.findByUsername(username);
|
|
|
|
|
-
|
|
|
|
|
- if (!"*".equals(tp.resource) && !this.resource.equals(tp.resource)) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- if (!"*".equals(tp.operation) && !this.operation.equals(tp.operation)) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- //for worker:
|
|
|
|
|
- if (assignedTaskService.getAssignedTask((Long.valueOf(instanceId)), user.getId()) == null) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- //for manager
|
|
|
|
|
- if (taskService.getTask(Long.valueOf(instanceId)).getOwnerId() != user.getId()) {
|
|
|
|
|
- return false;
|
|
|
|
|
- } else {
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|