- Timestamp:
- 01/05/18 15:13:25 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r15552 r15577 75 75 // authorize if user is admin or resource owner 76 76 public void AuthorizeForResourceAdministration(Guid resourceId) { 77 var currentUserId = UserManager.CurrentUserId; 77 78 var pm = PersistenceManager; 78 79 var resourceDao = pm.ResourceDao; … … 81 82 if (resource == null) throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); 82 83 83 if (resource.OwnerUserId != UserManager.CurrentUserId84 if (resource.OwnerUserId != currentUserId 84 85 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { 85 86 throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); … … 90 91 // authorize if user is admin, project owner or owner of a parent project 91 92 public void AuthorizeForProjectAdministration(Guid projectId) { 93 if (projectId == null) return; 94 var currentUserId = UserManager.CurrentUserId; 92 95 var pm = PersistenceManager; 93 96 var projectDao = pm.ProjectDao; … … 98 101 99 102 var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId); 100 if(!projectBranch.Select(x => x.OwnerUserId).Contains( UserManager.CurrentUserId)103 if(!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId) 101 104 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { 102 105 throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); … … 107 110 // authorize if user is admin, or owner of a parent project, for which the resources are assigned to 108 111 public void AuthorizeForProjectResourceAdministration(Guid projectId, IEnumerable<Guid> resourceIds) { 112 if (projectId == null) return; 113 var currentUserId = UserManager.CurrentUserId; 109 114 var pm = PersistenceManager; 110 115 var projectDao = pm.ProjectDao; … … 117 122 118 123 // check if resourceIds exist 119 if ( !resourceDao.CheckExistence(resourceIds))124 if (resourceIds != null && resourceIds.Any() && !resourceDao.CheckExistence(resourceIds)) 120 125 throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); 121 126 … … 123 128 if (RoleVerifier.IsInRole(HiveRoles.Administrator)) return; 124 129 125 // check if user is owner of a parent project and... 130 // check if user is owner of a parent project 131 var projectBranch = projectDao.GetParentProjectsById(projectId); 132 if (!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId) 133 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { 134 throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); 135 } 136 126 137 // check if the all argument resourceIds are among the assigned resources of the owned projects 127 var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, UserManager.CurrentUserId);138 var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, currentUserId); 128 139 if(resourceIds.Except(grantedResourceIds).Any()) { 129 140 throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); … … 134 145 // Check if a project is authorized to use a list of resources 135 146 public void AuthorizeProjectForResourcesUse(Guid projectId, IEnumerable<Guid> resourceIds) { 147 if (projectId == null || resourceIds == null || !resourceIds.Any()) return; 136 148 var pm = PersistenceManager; 137 149 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; … … 143 155 // note: administrators and project owner are NOT automatically granted 144 156 public void AuthorizeUserForProjectUse(Guid userId, Guid projectId) { 157 if (userId == null || projectId == null) return; 145 158 var pm = PersistenceManager; 146 159 // collect current and group membership Ids … … 166 179 167 180 private void AuthorizeJob(IPersistenceManager pm, Guid jobId, DT.Permission requiredPermission) { 181 var currentUserId = UserManager.CurrentUserId; 168 182 var requiredPermissionEntity = requiredPermission.ToEntity(); 169 DA.Permission permission = GetPermissionForJob(pm, jobId, UserManager.CurrentUserId);183 DA.Permission permission = GetPermissionForJob(pm, jobId, currentUserId); 170 184 if (permission == Permission.NotAllowed 171 185 || ((permission != requiredPermissionEntity) && requiredPermissionEntity == Permission.Full)) {
Note: See TracChangeset
for help on using the changeset viewer.