Skip to content

Commit

Permalink
Merge branch 'feature/shibui-2393' of bitbucket.org:unicon/shib-idp-u…
Browse files Browse the repository at this point in the history
…i into feature/shibui-2393
  • Loading branch information
Bill Smith committed Dec 6, 2022
2 parents be3ea5c + 988ac5d commit f0b3462
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.internet2.tier.shibboleth.admin.ui.security.exception.InvalidGroupRegexException;
import edu.internet2.tier.shibboleth.admin.ui.security.model.Group;
import edu.internet2.tier.shibboleth.admin.ui.security.service.IGroupService;
import edu.internet2.tier.shibboleth.admin.ui.service.DynamicRegistrationService;
import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class GroupController {
@Autowired
private EntityDescriptorService entityDescriptorService;

@Autowired
private DynamicRegistrationService dynamicRegistrationService;

@Secured("ROLE_ADMIN")
@PostMapping
@Transactional
Expand Down Expand Up @@ -71,6 +75,7 @@ public ResponseEntity<?> getOne(@PathVariable String resourceId) throws Persiste
public ResponseEntity<?> update(@RequestBody Group group) throws PersistentEntityNotFound, InvalidGroupRegexException {
Group result = groupService.updateGroup(group);
entityDescriptorService.checkApprovalStatusOfEntitiesForGroup(result);
dynamicRegistrationService.checkApprovalStatusOfEntitiesForGroup(result);
return ResponseEntity.ok(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,18 @@ public Collection getPersistentEntities(Authentication ignored, ShibUiPermissibl
case approve:
return getAllDynamicRegistrationInfoObjectsNeedingApprovalBasedOnUserAccess();
case enable:
return getAllDynamicRegistrationNeedingEnabledByUserAccess();
// This particular list is used for an admin function, so the user must be an ADMIN
if (!hasPermission(ignored, null, PermissionType.admin)) {
throw new ForbiddenException();
}
dynamicRegistrationInfoRepository.getDynamicRegistrationsNeedingEnabling();
case fetch:
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<DynamicRegistrationInfo> getAllDynamicRegistrationInfoObjectsNeedingApprovalBasedOnUserAccess() {
List<String> groupsToApprove = userService.getGroupsCurrentUserCanApprove();
return dynamicRegistrationInfoRepository.getAllNeedingApproval(groupsToApprove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
public interface DynamicRegistrationInfoRepository extends JpaRepository<DynamicRegistrationInfo, String> {
List<DynamicRegistrationInfo> findAllByIdOfOwner(String idOfOwner);

@Query(value="SELECT dri.resourceId FROM DynamicRegistrationInfo dri WHERE dri.idOfOwner = :groupId AND dri.enabled = false")
List<String> findAllResourceIdsByIdOfOwnerAndNotEnabled(@Param("groupId") String groupId);

DynamicRegistrationInfo findByResourceId(String id);

@Query(value = "SELECT dri FROM DynamicRegistrationInfo dri " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException;
import edu.internet2.tier.shibboleth.admin.ui.exception.PersistentEntityNotFound;
import edu.internet2.tier.shibboleth.admin.ui.exception.UnsupportedShibUiOperationException;
import edu.internet2.tier.shibboleth.admin.ui.security.model.Group;
import org.springframework.http.HttpStatus;

import java.util.List;
Expand All @@ -14,6 +15,8 @@ public interface DynamicRegistrationService {
DynamicRegistrationRepresentation approveDynamicRegistration(String resourceId, boolean status)
throws PersistentEntityNotFound, ForbiddenException;

void checkApprovalStatusOfEntitiesForGroup(Group result);

DynamicRegistrationRepresentation createNew(DynamicRegistrationRepresentation dynRegRepresentation) throws ObjectIdExistsException,
MissingRequiredFieldsException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +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.oidc.DynamicRegistrationInfo;
import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException;
Expand Down Expand Up @@ -146,6 +147,7 @@ public HttpStatus enableDynamicRegistration(String resourceId) throws Persistent
HttpStatus status = shibRestTemplateDelegate.sendRequest(existingDri);
if (status == HttpStatus.CREATED || status == HttpStatus.OK) {
existingDri.setEnabled(true);
existingDri.setApproved(true);
repository.save(existingDri);
}
return status;
Expand Down Expand Up @@ -236,4 +238,18 @@ public DynamicRegistrationRepresentation updateGroupForDynamicRegistration(Strin
DynamicRegistrationInfo savedEntity = repository.save(existingDri);
return new DynamicRegistrationRepresentation(savedEntity);
}

/**
* Update the approval status of entities that were in some approval state but the group approvers were added/removed.
*/
@Override
public void checkApprovalStatusOfEntitiesForGroup(Group group) {
repository.findAllResourceIdsByIdOfOwnerAndNotEnabled(group.getResourceId()).forEach(id -> {
DynamicRegistrationInfo dri = repository.findByResourceId(id);
int approvedCount = dri.approvedCount(); // total number of approvals so far
List<Approvers> theApprovers = groupService.find(dri.getIdOfOwner()).getApproversList();
dri.setApproved(approvedCount >= theApprovers.size());
dri = repository.save(dri);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import edu.internet2.tier.shibboleth.admin.ui.security.model.Group
import edu.internet2.tier.shibboleth.admin.ui.security.model.Role
import edu.internet2.tier.shibboleth.admin.ui.security.model.User
import edu.internet2.tier.shibboleth.admin.ui.security.repository.GroupsRepository
import edu.internet2.tier.shibboleth.admin.ui.service.DynamicRegistrationService
import edu.internet2.tier.shibboleth.admin.ui.service.JPAEntityDescriptorServiceImpl
import edu.internet2.tier.shibboleth.admin.ui.util.WithMockAdmin
import groovy.json.JsonOutput
Expand All @@ -32,6 +33,9 @@ class GroupsControllerIntegrationTests extends AbstractBaseDataJpaTest {
@Autowired
GroupsRepository groupsRepository

@Autowired
private DynamicRegistrationService dynamicRegistrationService

@Autowired
JPAEntityDescriptorServiceImpl service

Expand All @@ -44,6 +48,7 @@ class GroupsControllerIntegrationTests extends AbstractBaseDataJpaTest {
GroupController groupController = new GroupController().with ({
it.groupService = this.groupService
it.entityDescriptorService = this.service
it.dynamicRegistrationService = this.dynamicRegistrationService
it
})
mockMvc = MockMvcBuilders.standaloneSetup(groupController).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function DynamicRegistrationList ({entities, children, onChangeGroup, onD
className="form-control"
onChange={(event) => onChangeGroup(reg, event.target.value)}
value={reg.idOfOwner ? reg.idOfOwner : ''}
disabled={loadingGroups}
disabled={loadingGroups || reg.enabled}
disablevalidation="true">
<option>Select Group</option>
{groups.map((g, ridx) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function DynamicRegistrationDetail () {
className="form-control form-control-sm"
onChange={({target: {value}}) => changeGroup({ registration: detail, group: value })}
value={detail.idOfOwner}
disabled={loadingGroups}
disabled={loadingGroups || detail.enabled}
disablevalidation="true">
<option>Select Group</option>
{groups.map((g, ridx) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export const DynamicRegistrationApi = createApi({
url: `/DynamicRegistrations`
}),
providesTags: ['DynamicRegistration'],
// transformResponse: (registrations) => [...registrations.map(r => ({...r, enabled: true}))]
}),
selectDynamicRegistration: builder.query({
query: ({id}) => ({
url: `/DynamicRegistration/${id}`
}),
providesTags: ['DynamicRegistration'],
// transformResponse: (reg) => ({...reg, enabled: true})
}),
getDisabledRegistrations: builder.query({
query: () => ({
Expand Down

0 comments on commit f0b3462

Please sign in to comment.