Skip to content

Commit

Permalink
SHIBUI-2393
Browse files Browse the repository at this point in the history
Added endpoints to get the lists for approval and enable (dynamic registration)
  • Loading branch information
chasegawa committed Nov 14, 2022
1 parent ca1f1b1 commit e05148d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ public ResponseEntity<?> getAll() throws ForbiddenException {
return ResponseEntity.ok(dynamicRegistrationService.getAllDynamicRegistrationsBasedOnUserAccess());
}

@GetMapping("/DynamicRegistrations/needsApproval")
@Transactional
public ResponseEntity<?> getAllNeedingApproval() throws ForbiddenException {
return ResponseEntity.ok(dynamicRegistrationService.getAllDynamicRegistrationsNeedingApprovalBasedOnUserAccess());
}

/**
* @throws ForbiddenException This call is used for the admin needs action list, therefore the user must be an admin
*/
@Transactional
@GetMapping(value = "/EntityDescriptor/disabledSources")
public ResponseEntity<?> getDisabledMetadataSources() throws ForbiddenException {
return ResponseEntity.ok(dynamicRegistrationService.getDisabledDynamicRegistrations());
}

@DeleteMapping(value = "/DynamicRegistration/{resourceId}")
@Transactional
public ResponseEntity<?> deleteOne(@PathVariable String resourceId) throws ForbiddenException, PersistentEntityNotFound {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public interface EntityDescriptorRepository extends JpaRepository<EntityDescript
@Query(value = "select new edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorProjection(e.entityID, e.resourceId, e.serviceProviderName, e.createdBy, " +
"e.createdDate, e.serviceEnabled, e.idOfOwner, e.protocol, e.approved) " +
" from EntityDescriptor e " +
" where e.serviceEnabled = false"
)
" where e.serviceEnabled = false")
List<EntityDescriptorProjection> getEntityDescriptorsNeedingEnabling();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public Collection getPersistentEntities(Authentication ignored, ShibUiPermissibl
}
case dynamicRegistrationInfo:
switch (permissionType) {
case approve:
if (!hasPermission(ignored, null, PermissionType.approve)) {
throw new ForbiddenException("User has no access rights to get a list of : " + shibUiType);
}
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();
case fetch:
if (!hasPermission(ignored, null, PermissionType.fetch)) {
throw new ForbiddenException("User has no access rights to get a list of : " + shibUiType);
Expand All @@ -67,6 +77,11 @@ public Collection getPersistentEntities(Authentication ignored, ShibUiPermissibl
return null;
}

private List<DynamicRegistrationInfo> getAllDynamicRegistrationInfoObjectsNeedingApprovalBasedOnUserAccess() {
List<String> groupsToApprove = userService.getGroupsCurrentUserCanApprove();
return dynamicRegistrationInfoRepository.getAllNeedingApproval(groupsToApprove);
}

private List<DynamicRegistrationInfo> getAllDynamicRegistrationInfoObjectsBasedOnUserAccess() {
if (userService.currentUserIsAdmin()) {
return dynamicRegistrationInfoRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

import edu.internet2.tier.shibboleth.admin.ui.domain.oidc.DynamicRegistrationInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Collection;
import java.util.List;

public interface DynamicRegistrationInfoRepository extends JpaRepository<DynamicRegistrationInfo, String> {
List<DynamicRegistrationInfo> findAllByIdOfOwner(String idOfOwner);

DynamicRegistrationInfo findByResourceId(String id);

@Query(value = "SELECT dri FROM DynamicRegistrationInfo dri " +
" WHERE dri.idOfOwner IN (:groupIds)" +
" AND dri.enabled = false" +
" AND dri.approved = false")
List<DynamicRegistrationInfo> getAllNeedingApproval(@Param("groupIds") List<String> groupIds);

@Query(value = "SELECT dri FROM DynamicRegistrationInfo dri WHERE dri.enabled = false")
List<DynamicRegistrationInfo> getDynamicRegistrationsNeedingEnabling();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package edu.internet2.tier.shibboleth.admin.ui.service;

import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.DynamicRegistrationRepresentation;
import edu.internet2.tier.shibboleth.admin.ui.domain.oidc.DynamicRegistrationInfo;
import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException;
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException;
import edu.internet2.tier.shibboleth.admin.ui.exception.PersistentEntityNotFound;

import java.util.List;

public interface DynamicRegistrationService {
DynamicRegistrationRepresentation approveDynamicRegistration(String resourceId, boolean status)
throws PersistentEntityNotFound, ForbiddenException;
Expand All @@ -15,7 +18,11 @@ DynamicRegistrationRepresentation approveDynamicRegistration(String resourceId,

DynamicRegistrationRepresentation enableDynamicRegistration(String resourceId) throws PersistentEntityNotFound, ForbiddenException;

Object getAllDynamicRegistrationsBasedOnUserAccess() throws ForbiddenException;
List<DynamicRegistrationRepresentation> getAllDynamicRegistrationsBasedOnUserAccess() throws ForbiddenException;

List<DynamicRegistrationRepresentation> getAllDynamicRegistrationsNeedingApprovalBasedOnUserAccess() throws ForbiddenException;

List<DynamicRegistrationRepresentation> getDisabledDynamicRegistrations() throws ForbiddenException;

DynamicRegistrationRepresentation update(DynamicRegistrationRepresentation dynRegRepresentation) throws PersistentEntityNotFound, ForbiddenException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.service;

import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor;
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.DynamicRegistrationRepresentation;
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation;
import edu.internet2.tier.shibboleth.admin.ui.domain.oidc.DynamicRegistrationInfo;
import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException;
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException;
Expand All @@ -26,6 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;

Expand Down Expand Up @@ -103,6 +102,12 @@ public DynamicRegistrationRepresentation createNew(DynamicRegistrationRepresenta
return new DynamicRegistrationRepresentation(repository.save(dri));
}

private List<DynamicRegistrationRepresentation> convertToRepresentations(List<DynamicRegistrationInfo> temp) {
List<DynamicRegistrationRepresentation> result = new ArrayList<>();
temp.forEach(dri -> result.add(new DynamicRegistrationRepresentation(dri)));
return result;
}

@Override
public void delete(String resourceId) throws ForbiddenException, PersistentEntityNotFound {
if (!shibUiAuthorizationDelegate.hasPermission(userService.getCurrentUserAuthentication(), null, PermissionType.admin)) {
Expand Down Expand Up @@ -137,8 +142,21 @@ private boolean entityExists(String id) {
}

@Override
public List<DynamicRegistrationInfo> getAllDynamicRegistrationsBasedOnUserAccess() throws ForbiddenException {
return (List<DynamicRegistrationInfo>) shibUiAuthorizationDelegate.getPersistentEntities(userService.getCurrentUserAuthentication(), ShibUiPermissibleType.dynamicRegistrationInfo, PermissionType.fetch);
public List<DynamicRegistrationRepresentation> getAllDynamicRegistrationsBasedOnUserAccess() throws ForbiddenException {
List<DynamicRegistrationInfo> temp = (List<DynamicRegistrationInfo>) shibUiAuthorizationDelegate.getPersistentEntities(userService.getCurrentUserAuthentication(), ShibUiPermissibleType.dynamicRegistrationInfo, PermissionType.fetch);
return convertToRepresentations(temp);
}

@Override
public List<DynamicRegistrationRepresentation> getAllDynamicRegistrationsNeedingApprovalBasedOnUserAccess() throws ForbiddenException {
List<DynamicRegistrationInfo> temp = (List<DynamicRegistrationInfo>) shibUiAuthorizationDelegate.getPersistentEntities(userService.getCurrentUserAuthentication(), ShibUiPermissibleType.dynamicRegistrationInfo, PermissionType.approve);
return convertToRepresentations(temp);
}

@Override
public List<DynamicRegistrationRepresentation> getDisabledDynamicRegistrations() throws ForbiddenException {
List<DynamicRegistrationInfo> temp = (List<DynamicRegistrationInfo>) shibUiAuthorizationDelegate.getPersistentEntities(userService.getCurrentUserAuthentication(), ShibUiPermissibleType.dynamicRegistrationInfo, PermissionType.enable);
return convertToRepresentations(temp);
}

@Override
Expand Down

0 comments on commit e05148d

Please sign in to comment.