Changeset 15540 for branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
- Timestamp:
- 12/18/17 17:38:05 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r15530 r15540 72 72 } 73 73 74 // authorize if user is admin or resource owner 74 75 public void AuthorizeForResourceAdministration(Guid resourceId) { 75 76 var pm = PersistenceManager; … … 78 79 var resource = resourceDao.GetById(resourceId); 79 80 if (resource == null) throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); 81 80 82 if (resource.OwnerUserId != UserManager.CurrentUserId 81 83 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { … … 85 87 } 86 88 89 // authorize if user is admin, project owner or owner of a parent project 87 90 public void AuthorizeForProjectAdministration(Guid projectId) { 88 91 var pm = PersistenceManager; 89 92 var projectDao = pm.ProjectDao; 90 93 pm.UseTransaction(() => { 94 // check if project exists (not necessary) 91 95 var project = projectDao.GetById(projectId); 92 96 if (project == null) throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); 93 97 94 var project Tree= projectDao.GetCurrentAndParentProjectsById(projectId);95 if(!project Tree.Select(x => x.OwnerUserId).Contains(UserManager.CurrentUserId)98 var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId); 99 if(!projectBranch.Select(x => x.OwnerUserId).Contains(UserManager.CurrentUserId) 96 100 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { 97 101 throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); 102 } 103 }); 104 } 105 106 // authorize if user is admin, or owner of a parent project, for which the resources are assigned to 107 public void AuthorizeForProjectResourceAdministration(Guid projectId, IEnumerable<Guid> resourceIds) { 108 var pm = PersistenceManager; 109 var projectDao = pm.ProjectDao; 110 var resourceDao = pm.ResourceDao; 111 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 112 pm.UseTransaction(() => { 113 // check if project exists (not necessary) 114 var project = projectDao.GetById(projectId); 115 if (project == null) throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); 116 117 // check if resourceIds exist 118 if (!resourceDao.CheckExistence(resourceIds)) 119 throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); 120 121 // check if user is admin 122 if (RoleVerifier.IsInRole(HiveRoles.Administrator)) return; 123 124 // check if user is owner of a parent project and... 125 // check if the all argument resourceIds are among the assigned resources of the owned projects 126 var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, UserManager.CurrentUserId); 127 if(resourceIds.Except(grantedResourceIds).Any()) { 128 throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); 98 129 } 99 130 });
Note: See TracChangeset
for help on using the changeset viewer.