diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/permission/ShibUiPermissionDelegate.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/permission/ShibUiPermissionDelegate.java index 534f60307..fb1df5ac5 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/permission/ShibUiPermissionDelegate.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/permission/ShibUiPermissionDelegate.java @@ -59,20 +59,24 @@ public Collection getPersistentEntities(Authentication ignored, ShibUiPermissibl case approve: return getAllDynamicRegistrationInfoObjectsNeedingApprovalBasedOnUserAccess(); case enable: - if (!hasPermission(ignored, null, PermissionType.enable)) { - throw new ForbiddenException("User has no access rights to get a list of : " + shibUiType); - } - return dynamicRegistrationInfoRepository.getDynamicRegistrationsNeedingEnabling(); + return getAllDynamicRegistrationNeedingEnabledByUserAccess(); case fetch: - if (!hasPermission(ignored, null, PermissionType.fetch)) { - throw new ForbiddenException("User has no access rights to get a list of : " + shibUiType); - } return getAllDynamicRegistrationInfoObjectsBasedOnUserAccess(); } } return null; } + private Collection getAllDynamicRegistrationNeedingEnabledByUserAccess() throws ForbiddenException { + if (userService.currentUserIsAdmin()) { + return dynamicRegistrationInfoRepository.getDynamicRegistrationsNeedingEnabling(); + } else if (userService.currentUserCanEnable()) { + return dynamicRegistrationInfoRepository.getDynamicRegistrationsNeedingEnabling(userService.getCurrentUser().getGroupId()); + } + throw new ForbiddenException("User has no access rights to enable"); + + } + private List getAllDynamicRegistrationInfoObjectsNeedingApprovalBasedOnUserAccess() { List groupsToApprove = userService.getGroupsCurrentUserCanApprove(); return dynamicRegistrationInfoRepository.getAllNeedingApproval(groupsToApprove); @@ -110,7 +114,7 @@ public boolean hasPermission(Authentication ignored, Object targetDomainObject, return targetDomainObject instanceof IApprovable ? userService.getGroupsCurrentUserCanApprove().contains(((IApprovable)targetDomainObject).getIdOfOwner()) : false; case enable: return targetDomainObject instanceof IActivatable ? currentUserCanEnable((IActivatable) targetDomainObject) : false; - case fetch: + case fetch: // we don't care about one object, just the user's ability to fetch data return userService.currentUserIsAdmin() || userService.getCurrentUserAccess().equals(UserAccess.GROUP); case viewOrEdit: return userService.canViewOrEditTarget((Ownable) targetDomainObject); diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/repository/DynamicRegistrationInfoRepository.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/repository/DynamicRegistrationInfoRepository.java index 40eecf6c6..21f95be6c 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/repository/DynamicRegistrationInfoRepository.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/repository/DynamicRegistrationInfoRepository.java @@ -1,6 +1,7 @@ package edu.internet2.tier.shibboleth.admin.ui.security.repository; import edu.internet2.tier.shibboleth.admin.ui.domain.oidc.DynamicRegistrationInfo; +import edu.internet2.tier.shibboleth.admin.ui.security.model.Group; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -20,4 +21,10 @@ public interface DynamicRegistrationInfoRepository extends JpaRepository getDynamicRegistrationsNeedingEnabling(); + + @Query(value = "SELECT dri FROM DynamicRegistrationInfo dri " + + " WHERE dri.idOfOwner = :groupId" + + " AND dri.enabled = false" + + " AND dri.approved = true") + List getDynamicRegistrationsNeedingEnabling(@Param("groupId") String groupId); } \ No newline at end of file diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/service/UserService.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/service/UserService.java index c26526df8..429dfa6c2 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/service/UserService.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/service/UserService.java @@ -232,4 +232,8 @@ public void updateUserRole(User user) { throw new RuntimeException(String.format("User with username [%s] has no role defined and therefore cannot be updated!", user.getUsername())); } } + + public boolean currentUserCanEnable() { + return getCurrentUser().getRole().equals("ROLE_ENABLE"); + } } \ No newline at end of file