From b68c821de3a1357e72077d7280e9c9604681b625 Mon Sep 17 00:00:00 2001 From: chasegawa Date: Tue, 17 Aug 2021 20:40:56 -0700 Subject: [PATCH] SHIBUI-2024 slight refactoring of names --- ...tadataResolverValidationConfiguration.java | 8 +++--- .../EntityDescriptorController.java | 16 +++-------- ...yDescriptorControllerExceptionHandler.java | 6 ++-- .../InvalidPatternMatchException.java | 7 +++++ .../exception/InvalidUrlMatchException.java | 7 ----- .../ui/service/EntityDescriptorService.java | 11 ++++---- .../JPAEntityDescriptorServiceImpl.java | 14 +++++----- .../EntityDescriptorControllerTests.groovy | 28 ++----------------- 8 files changed, 33 insertions(+), 64 deletions(-) create mode 100644 backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidPatternMatchException.java delete mode 100644 backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidUrlMatchException.java diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/MetadataResolverValidationConfiguration.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/MetadataResolverValidationConfiguration.java index f41b47eaa..fdf63e9e0 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/MetadataResolverValidationConfiguration.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/MetadataResolverValidationConfiguration.java @@ -11,8 +11,8 @@ @Configuration public class MetadataResolverValidationConfiguration { - @Bean ResourceBackedIMetadataResolverValidator resourceBackedMetadataResolverValidator() { - return new ResourceBackedIMetadataResolverValidator(); + @Bean DurationMetadataResolverValidator durationMetadataResolverValidator() { + return new DurationMetadataResolverValidator(); } @Bean DynamicHttpMetadataResolverValidator dynamicHttpMetadataResolverValidator(IGroupService groupService, UserService userService) { @@ -30,7 +30,7 @@ MetadataResolverValidationService metadataResolverValidationService(List create(@RequestBody EntityDescriptorRepresentation edRepresentation) - throws ForbiddenException, EntityIdExistsException, InvalidUrlMatchException { + throws ForbiddenException, EntityIdExistsException, InvalidPatternMatchException { EntityDescriptorRepresentation persistedEd = entityDescriptorService.createNew(edRepresentation); return ResponseEntity.created(getResourceUriFor(persistedEd.getId())).body(persistedEd); } @@ -148,7 +139,8 @@ public void initRestTemplate() { @PutMapping("/EntityDescriptor/{resourceId}") @Transactional public ResponseEntity update(@RequestBody EntityDescriptorRepresentation edRepresentation, @PathVariable String resourceId) - throws ForbiddenException, ConcurrentModificationException, EntityNotFoundException, InvalidUrlMatchException { + throws ForbiddenException, ConcurrentModificationException, EntityNotFoundException, + InvalidPatternMatchException { edRepresentation.setId(resourceId); // This should be the same already, but just to be safe... EntityDescriptorRepresentation result = entityDescriptorService.update(edRepresentation); return ResponseEntity.ok().body(result); diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerExceptionHandler.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerExceptionHandler.java index 7eae86cb5..6ec47a82a 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerExceptionHandler.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerExceptionHandler.java @@ -3,7 +3,7 @@ import edu.internet2.tier.shibboleth.admin.ui.exception.EntityIdExistsException; import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException; -import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidUrlMatchException; +import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidPatternMatchException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -43,8 +43,8 @@ public ResponseEntity handleForbiddenAccess(ForbiddenException e, WebRequest return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ErrorResponse(HttpStatus.FORBIDDEN, e.getMessage())); } - @ExceptionHandler({ InvalidUrlMatchException.class }) - public ResponseEntity handleInvalidUrlMatchException(InvalidUrlMatchException e, WebRequest request) { + @ExceptionHandler({ InvalidPatternMatchException.class }) + public ResponseEntity handleInvalidUrlMatchException(InvalidPatternMatchException e, WebRequest request) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(HttpStatus.BAD_REQUEST, e.getMessage())); } } \ No newline at end of file diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidPatternMatchException.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidPatternMatchException.java new file mode 100644 index 000000000..57cdfcd42 --- /dev/null +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidPatternMatchException.java @@ -0,0 +1,7 @@ +package edu.internet2.tier.shibboleth.admin.ui.exception; + +public class InvalidPatternMatchException extends Exception { + public InvalidPatternMatchException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidUrlMatchException.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidUrlMatchException.java deleted file mode 100644 index ea2d463c7..000000000 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/InvalidUrlMatchException.java +++ /dev/null @@ -1,7 +0,0 @@ -package edu.internet2.tier.shibboleth.admin.ui.exception; - -public class InvalidUrlMatchException extends Exception { - public InvalidUrlMatchException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/EntityDescriptorService.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/EntityDescriptorService.java index 54fe65ddd..0d070d43d 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/EntityDescriptorService.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/EntityDescriptorService.java @@ -6,7 +6,7 @@ import edu.internet2.tier.shibboleth.admin.ui.exception.EntityIdExistsException; import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException; -import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidUrlMatchException; +import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidPatternMatchException; import java.util.ConcurrentModificationException; import java.util.List; @@ -33,7 +33,7 @@ public interface EntityDescriptorService { * @throws EntityIdExistsException If any EntityDescriptor already exists with the same EntityId */ EntityDescriptorRepresentation createNew(EntityDescriptor ed) - throws ForbiddenException, EntityIdExistsException, InvalidUrlMatchException; + throws ForbiddenException, EntityIdExistsException, InvalidPatternMatchException; /** * @param edRepresentation Incoming representation to save @@ -42,7 +42,7 @@ EntityDescriptorRepresentation createNew(EntityDescriptor ed) * @throws EntityIdExistsException If the entity already exists */ EntityDescriptorRepresentation createNew(EntityDescriptorRepresentation edRepresentation) - throws ForbiddenException, EntityIdExistsException, InvalidUrlMatchException; + throws ForbiddenException, EntityIdExistsException, InvalidPatternMatchException; /** * Map from opensaml implementation of entity descriptor model to front-end data representation of entity descriptor @@ -99,10 +99,11 @@ EntityDescriptorRepresentation createNew(EntityDescriptorRepresentation edRepres * @throws ForbiddenException If the user is not permitted to perform the action * @throws EntityNotFoundException If the entity doesn't already exist in the database * @throws ConcurrentModificationException IF the entity is being modified in another session - * @throws InvalidUrlMatchException If the entity id or the ACS location urls don't match the supplied regex + * @throws InvalidPatternMatchException If the entity id or the ACS location urls don't match the supplied regex */ EntityDescriptorRepresentation update(EntityDescriptorRepresentation edRepresentation) - throws ForbiddenException, EntityNotFoundException, ConcurrentModificationException, InvalidUrlMatchException; + throws ForbiddenException, EntityNotFoundException, ConcurrentModificationException, + InvalidPatternMatchException; /** * Update an instance of entity descriptor with information from the front-end representation diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java index f6a979e2d..04b33bf76 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java @@ -5,7 +5,7 @@ import edu.internet2.tier.shibboleth.admin.ui.exception.EntityIdExistsException; import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException; -import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidUrlMatchException; +import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidPatternMatchException; import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects; import edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorRepository; import edu.internet2.tier.shibboleth.admin.ui.security.model.Group; @@ -73,13 +73,13 @@ public EntityDescriptor createDescriptorFromRepresentation(final EntityDescripto @Override public EntityDescriptorRepresentation createNew(EntityDescriptor ed) - throws ForbiddenException, EntityIdExistsException, InvalidUrlMatchException { + throws ForbiddenException, EntityIdExistsException, InvalidPatternMatchException { return createNew(createRepresentationFromDescriptor(ed)); } @Override public EntityDescriptorRepresentation createNew(EntityDescriptorRepresentation edRep) - throws ForbiddenException, EntityIdExistsException, InvalidUrlMatchException { + throws ForbiddenException, EntityIdExistsException, InvalidPatternMatchException { if (edRep.isServiceEnabled() && !userService.currentUserIsAdmin()) { throw new ForbiddenException("You do not have the permissions necessary to enable this service."); } @@ -368,7 +368,7 @@ public Map getRelyingPartyOverridesRepresentationFromAttributeLi @Override public EntityDescriptorRepresentation update(EntityDescriptorRepresentation edRep) - throws ForbiddenException, EntityNotFoundException, InvalidUrlMatchException { + throws ForbiddenException, EntityNotFoundException, InvalidPatternMatchException { EntityDescriptor existingEd = entityDescriptorRepository.findByResourceId(edRep.getId()); if (existingEd == null) { throw new EntityNotFoundException(String.format("The entity descriptor with entity id [%s] was not found for update.", edRep.getId())); @@ -397,17 +397,17 @@ public void updateDescriptorFromRepresentation(org.opensaml.saml.saml2.metadata. buildDescriptorFromRepresentation((EntityDescriptor) entityDescriptor, representation); } - private void validateEntityIdAndACSUrls(EntityDescriptorRepresentation edRep) throws InvalidUrlMatchException { + private void validateEntityIdAndACSUrls(EntityDescriptorRepresentation edRep) throws InvalidPatternMatchException { // Check the entity id first if (!groupService.doesStringMatchGroupPattern(edRep.getIdOfOwner(), edRep.getEntityId())) { - throw new InvalidUrlMatchException("EntityId is not a pattern match to the group"); + throw new InvalidPatternMatchException("EntityId is not a pattern match to the group"); } // Check the ACS locations if (edRep.getAssertionConsumerServices() != null && edRep.getAssertionConsumerServices().size() > 0) { for (AssertionConsumerServiceRepresentation acs : edRep.getAssertionConsumerServices()) { if (!groupService.doesStringMatchGroupPattern(edRep.getIdOfOwner(), acs.getLocationUrl())) { - throw new InvalidUrlMatchException( + throw new InvalidPatternMatchException( "ACS location [ " + acs.getLocationUrl() + " ] is not a pattern match to the group"); } } diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy index 717aeb155..5e514763b 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy @@ -11,7 +11,7 @@ import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRe import edu.internet2.tier.shibboleth.admin.ui.exception.EntityIdExistsException import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException -import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidUrlMatchException +import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidPatternMatchException import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects import edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorRepository import edu.internet2.tier.shibboleth.admin.ui.security.model.Group @@ -24,35 +24,18 @@ import edu.internet2.tier.shibboleth.admin.ui.security.repository.RoleRepository import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository import edu.internet2.tier.shibboleth.admin.ui.security.service.GroupServiceForTesting import edu.internet2.tier.shibboleth.admin.ui.security.service.GroupServiceImpl -import edu.internet2.tier.shibboleth.admin.ui.security.service.IGroupService import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService -import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorService import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorVersionService import edu.internet2.tier.shibboleth.admin.ui.service.EntityService import edu.internet2.tier.shibboleth.admin.ui.service.JPAEntityDescriptorServiceImpl -import edu.internet2.tier.shibboleth.admin.ui.service.JPAEntityServiceImpl import edu.internet2.tier.shibboleth.admin.ui.util.RandomGenerator -import edu.internet2.tier.shibboleth.admin.ui.util.TestHelpers import edu.internet2.tier.shibboleth.admin.ui.util.TestObjectGenerator import edu.internet2.tier.shibboleth.admin.util.EntityDescriptorConversionUtils -import groovy.json.JsonOutput -import groovy.json.JsonSlurper - -import org.skyscreamer.jsonassert.Customization -import org.skyscreamer.jsonassert.JSONAssert -import org.skyscreamer.jsonassert.JSONCompareMode -import org.skyscreamer.jsonassert.ValueMatcher -import org.skyscreamer.jsonassert.comparator.CustomComparator -import org.skyscreamer.jsonassert.comparator.JSONCompareUtil import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.support.RootBeanDefinition import org.springframework.boot.autoconfigure.domain.EntityScan import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Profile -import org.springframework.context.support.StaticApplicationContext import org.springframework.data.jpa.repository.config.EnableJpaRepositories import org.springframework.security.core.Authentication import org.springframework.security.core.context.SecurityContext @@ -65,17 +48,10 @@ import org.springframework.test.context.ContextConfiguration import org.springframework.test.web.servlet.setup.MockMvcBuilders import org.springframework.transaction.annotation.Transactional import org.springframework.web.client.RestTemplate -import org.springframework.web.servlet.config.annotation.EnableWebMvc -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport -import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver import org.springframework.web.util.NestedServletException -import spock.lang.Ignore -import spock.lang.Shared import spock.lang.Specification import spock.lang.Subject -import java.time.LocalDateTime - import javax.persistence.EntityManager import static org.hamcrest.CoreMatchers.containsString @@ -341,7 +317,7 @@ class EntityDescriptorControllerTests extends Specification { mockMvc.perform(post('/api/EntityDescriptor').contentType(APPLICATION_JSON).content(edRepJson)) false } catch (NestedServletException expected) { - expected.getCause() instanceof InvalidUrlMatchException + expected.getCause() instanceof InvalidPatternMatchException } }