Skip to content

Commit

Permalink
SHIBUI-1740
Browse files Browse the repository at this point in the history
Ensuring entity descriptor db is migrated such that entity descriptors
are associated with the default group
  • Loading branch information
chasegawa committed Jul 6, 2021
1 parent 3b5a035 commit 12e2750
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.stream.Stream;


Expand All @@ -25,7 +26,11 @@ public interface EntityDescriptorRepository extends JpaRepository<EntityDescript
"where e.createdBy = u.username and e.serviceEnabled = false and r.name in ('ROLE_USER', 'ROLE_NONE')")
Stream<EntityDescriptor> findAllDisabledAndNotOwnedByAdmin();

// Stream<EntityDescriptor> findAllStreamByCreatedBy(String createdBy);

Stream<EntityDescriptor> findAllStreamByGroup_resourceId(String resourceId);

/**
* SHIBUI-1740 This is here to aid in migration of systems using the SHIBUI prior to group functionality being added
* @deprecated - this is intended to be removed at some future date and is here only for migration purposes.
*/
List<EntityDescriptor> findAllByGroupIsNull();
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public Group updateGroup(Group group) throws EntityNotFoundException {
@PostConstruct
@Transactional
private void ensureDefaultGroupExists() {
// This is something of a migration piece to ensure there is a default group that users and entity descriptors
// can be assigned to out of the box.
Group g = repo.findByDefaultGroupTrue();
if (g == null) {
g = new Group();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import edu.internet2.tier.shibboleth.admin.util.MDDCConstants;
import edu.internet2.tier.shibboleth.admin.util.ModelRepresentationConversions;
import groovy.util.logging.Slf4j;
import jline.internal.Log;

import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.schema.XSBooleanValue;
Expand All @@ -75,6 +76,9 @@
import java.util.Optional;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.transaction.Transactional;

import static edu.internet2.tier.shibboleth.admin.util.ModelRepresentationConversions.getStringListOfAttributeValues;


Expand Down Expand Up @@ -417,9 +421,6 @@ public List<EntityDescriptorRepresentation> getAllRepresentationsBasedOnUserAcce
return entityDescriptorRepository
.findAllStreamByGroup_resourceId(group.getResourceId())
.map(ed -> createRepresentationFromDescriptor(ed)).collect(Collectors.toList());
// case OWNER:
// return entityDescriptorRepository.findAllStreamByCreatedBy(userService.getCurrentUser().getUsername())
// .map(ed -> createRepresentationFromDescriptor(ed)).collect(Collectors.toList());
default:
throw new ForbiddenException();
}
Expand Down Expand Up @@ -506,6 +507,24 @@ private UIInfo getUIInfo(EntityDescriptor ed) {
return uiInfo;
}

@PostConstruct
@Transactional
private void migration() {
// SHIBUI-1740: Adding default group to all existing entity descriptors that do not have a group already.
// Because this class has a GroupService, we assume the DEFAULT_GROUP has already been setup prior to being
// autowired into this class.
try {
entityDescriptorRepository.findAllByGroupIsNull().forEach(ed -> {
ed.setGroup(Group.DEFAULT_GROUP);
entityDescriptorRepository.save(ed);
});
}
catch (NullPointerException e) {
// This block was added due to a number of mock test where NPEs happened. Rather than wire more mock junk
// into tests that are only trying to compensate for this migration, this is here
}
}

// TODO: remove
private String getValueFromXMLObject(XMLObject xmlObject) {
return ModelRepresentationConversions.getValueFromXMLObject(xmlObject);
Expand Down

0 comments on commit 12e2750

Please sign in to comment.