diff --git a/pom.xml b/pom.xml index 78d47991f19cde06175a514734ba69bbf1842185..620436914f2b65df4e38fea74d6a8eef0a3486d3 100644 --- a/pom.xml +++ b/pom.xml @@ -646,34 +646,6 @@ </dependencies> </plugin> - - <!-- integration tests, failsafe plugin --> - <!-- plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <version>2.19.1</version> - <configuration> - <reportsDirectory>${basedir}/target/code-coverage/failsafe-reports</reportsDirectory> - </configuration> - <executions> - <execution> - <id>integration-tests</id> - <phase>integration-test</phase> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.maven.surefire</groupId> - <artifactId>surefire-junit47</artifactId> - <version>2.19.1</version> - </dependency> - </dependencies> - </plugin --> - <!-- jacoco start --> <plugin> <groupId>org.jacoco</groupId> diff --git a/smp-api/pom.xml b/smp-api/pom.xml index 259f891896d1b823a20e513d535e8337b42bcbde..cd69fc7973c4d5f97b26c699753faf3378ff74cd 100644 --- a/smp-api/pom.xml +++ b/smp-api/pom.xml @@ -46,6 +46,7 @@ <dependency> <groupId>pl.pragmatists</groupId> <artifactId>JUnitParams</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>commons-io</groupId> diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupService.java index ec52ce985f945a51386b6398ab11127a05b41b42..8956298b164bacea5980700974fc2b7c30026def 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupService.java @@ -29,10 +29,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import static eu.europa.ec.edelivery.smp.data.ui.ServiceGroupValidationRO.*; import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.*; @@ -115,6 +112,26 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service return convertToRo(dbServiceGroup); } + @Transactional + public ServiceGroupRO getOwnedServiceGroupById(Long userId, Long serviceGroupId) { + DBServiceGroup dbServiceGroup = getDatabaseDao().find(serviceGroupId); + if (isServiceGroupOwner(userId,dbServiceGroup )){ + convertToRo(dbServiceGroup); + } + return null; + } + + /** + * Method validates if any of the service group users contains userID + * @param userId + * @param dbServiceGroup + * @return + */ + protected boolean isServiceGroupOwner(Long userId, DBServiceGroup dbServiceGroup){ + return dbServiceGroup!=null && + dbServiceGroup.getUsers().stream().filter(user ->user.getId().equals(userId)).findAny().isPresent(); + } + @Transactional public ServiceGroupValidationRO getServiceGroupExtensionById(Long serviceGroupId) { ServiceGroupValidationRO ex = new ServiceGroupValidationRO(); @@ -140,16 +157,20 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service } @Transactional - public List<ParticipantSMLRecord> updateServiceGroupList(List<ServiceGroupRO> lst) { + public List<ParticipantSMLRecord> updateServiceGroupList(List<ServiceGroupRO> lst, boolean serviceGroupAdmin) { boolean suc = false; List<ParticipantSMLRecord> lstRecords = new ArrayList<>(); for (ServiceGroupRO dRo : lst) { if (dRo.getStatus() == EntityROStatus.NEW.getStatusNumber()) { - lstRecords.addAll(addNewServiceGroup(dRo)); + if (serviceGroupAdmin) { + lstRecords.addAll(addNewServiceGroup(dRo)); + } } else if (dRo.getStatus() == EntityROStatus.UPDATED.getStatusNumber()) { - lstRecords.addAll(updateServiceGroup(dRo)); + lstRecords.addAll(updateServiceGroup(dRo, serviceGroupAdmin)); } else if (dRo.getStatus() == EntityROStatus.REMOVE.getStatusNumber()) { - lstRecords.addAll(removeServiceGroup(dRo)); + if (serviceGroupAdmin) { + lstRecords.addAll(removeServiceGroup(dRo)); + } } } // register/unregister participants from domain @@ -308,18 +329,20 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service * * @param serviceGroupRO */ - protected List<ParticipantSMLRecord> updateServiceGroup(ServiceGroupRO serviceGroupRO) { + protected List<ParticipantSMLRecord> updateServiceGroup(ServiceGroupRO serviceGroupRO, boolean serviceGroupAdmin) { // normalize identifiers normalizeIdentifiers(serviceGroupRO); // find and validate service group DBServiceGroup dbServiceGroup = findAndValidateServiceGroup(serviceGroupRO); + List<ParticipantSMLRecord> participantSMLRecordList = Collections.emptyList(); + if (serviceGroupAdmin) { + // update users + updateUsersOnServiceGroup(serviceGroupRO, dbServiceGroup); - // update users - updateUsersOnServiceGroup(serviceGroupRO, dbServiceGroup); - - // update domain - List<ParticipantSMLRecord> participantSMLRecordList = updateDomainsForServiceGroup(serviceGroupRO, dbServiceGroup); + // update domain + participantSMLRecordList = updateDomainsForServiceGroup(serviceGroupRO, dbServiceGroup); + } //update service metadata List<ServiceMetadataRO> serviceMetadataROList = serviceGroupRO.getServiceMetadata(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceIntegrationTest.java index 0ee530d0f41ada025dc62c4235b33ce17f2edd40..c73107d0a15f5c1c224994ac63249ae0e22b6699 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceIntegrationTest.java @@ -117,7 +117,7 @@ public class UIServiceGroupServiceIntegrationTest extends AbstractServiceIntegra sgnew.getServiceMetadata().add(mtro); //when - testInstance.updateServiceGroupList(Collections.singletonList(sgnew)); + testInstance.updateServiceGroupList(Collections.singletonList(sgnew), true); // then ServiceResult<ServiceGroupRO> res = testInstance.getTableList(-1, -1, null, null, null); @@ -171,7 +171,7 @@ public class UIServiceGroupServiceIntegrationTest extends AbstractServiceIntegra sgChange.getServiceMetadata().get(0).setXmlContent(newMetadataXML); //when - testInstance.updateServiceGroupList(Collections.singletonList(sgChange)); + testInstance.updateServiceGroupList(Collections.singletonList(sgChange), true); // then res = testInstance.getTableList(-1, -1, null, null, null); @@ -227,7 +227,7 @@ public class UIServiceGroupServiceIntegrationTest extends AbstractServiceIntegra smdToChange.setStatus(EntityROStatus.UPDATED.getStatusNumber()); smdToChange.setDomainCode(testDomain02.getDomainCode()); smdToChange.setSmlSubdomain(testDomain02.getSmlSubdomain()); - testInstance.updateServiceGroupList(Collections.singletonList(sgChanged)); + testInstance.updateServiceGroupList(Collections.singletonList(sgChanged), true); res = testInstance.getTableList(-1, -1, null, null, null); ServiceGroupRO sgUpdated = res.getServiceEntities().get(0); @@ -270,7 +270,7 @@ public class UIServiceGroupServiceIntegrationTest extends AbstractServiceIntegra smdToChange.setStatus(EntityROStatus.UPDATED.getStatusNumber()); smdToChange.setDomainCode(testDomain02.getDomainCode()); smdToChange.setSmlSubdomain(testDomain02.getSmlSubdomain()); - testInstance.updateServiceGroupList(Collections.singletonList(sgChanged)); + testInstance.updateServiceGroupList(Collections.singletonList(sgChanged), true); res = testInstance.getTableList(-1, -1, null, null, null); ServiceGroupRO sgUpdated = res.getServiceEntities().get(0); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceUpdateListIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceUpdateListIntegrationTest.java index 7405afc4bd91e410debbeb63249e4f1cb027bbfd..61a8c583adf45e8393aba9aab04ae4944f9ba49f 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceUpdateListIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceGroupServiceUpdateListIntegrationTest.java @@ -139,7 +139,7 @@ public class UIServiceGroupServiceUpdateListIntegrationTest extends AbstractServ ServiceGroupRO roToUpdate = testInstance.getServiceGroupById(dbServiceGroup.getId()); // when ServiceGroupDomainRO dro = roToUpdate.getServiceGroupDomains().remove(0); - List<ParticipantSMLRecord> lst = testInstance.updateServiceGroup(roToUpdate); + List<ParticipantSMLRecord> lst = testInstance.updateServiceGroup(roToUpdate, true); // then assertEquals(1, lst.size()); assertEquals(SMLStatusEnum.UNREGISTER, lst.get(0).getStatus()); @@ -165,7 +165,7 @@ public class UIServiceGroupServiceUpdateListIntegrationTest extends AbstractServ sgr.setSmlSubdomain(dbDomain2.getSmlSubdomain()); sgr.setDomainId(dbDomain2.getId()); roToUpdate.getServiceGroupDomains().add(sgr); - List<ParticipantSMLRecord> lst = testInstance.updateServiceGroup(roToUpdate); + List<ParticipantSMLRecord> lst = testInstance.updateServiceGroup(roToUpdate, true); // then assertEquals(1, lst.size()); assertEquals(SMLStatusEnum.REGISTER, lst.get(0).getStatus()); diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/ServiceGroupResource.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/ServiceGroupResource.java index f0b73d770a1eac1dfafccc2f9adeb68cf0634fd9..0c4b9a354c4972d47b3366ef2c6f94bbd36a46e6 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/ServiceGroupResource.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/ServiceGroupResource.java @@ -87,7 +87,15 @@ public class ServiceGroupResource { @Secured({SMPAuthority.S_AUTHORITY_TOKEN_SMP_ADMIN, SMPAuthority.S_AUTHORITY_TOKEN_SERVICE_GROUP_ADMIN}) public ServiceGroupRO getServiceGroupById(@PathVariable Long serviceGroupId) { LOG.info("Get service group [{}]", serviceGroupId); - return uiServiceGroupService.getServiceGroupById(serviceGroupId); + // SMP administrators are authorized by default + if (authorizationService.isSMPAdministrator()){ + return uiServiceGroupService.getServiceGroupById(serviceGroupId); + } else { + // if not authorized by default check if is it an owner + authorizationService.getAndValidateUserDetails(); + SMPUserDetails user = SessionSecurityUtils.getSessionUserDetails(); + return uiServiceGroupService.getOwnedServiceGroupById(user.getUser().getId(), serviceGroupId); + } } @GetMapping(path = "{service-group-id}/extension", produces = MimeTypeUtils.APPLICATION_JSON_VALUE) @@ -109,7 +117,7 @@ public class ServiceGroupResource { @Secured({SMPAuthority.S_AUTHORITY_TOKEN_SMP_ADMIN, SMPAuthority.S_AUTHORITY_TOKEN_SERVICE_GROUP_ADMIN}) public void updateServiceGroupList(@RequestBody ServiceGroupRO[] updateEntities) { LOG.info("Update ServiceGroupRO count: " + updateEntities.length); - uiServiceGroupService.updateServiceGroupList(Arrays.asList(updateEntities)); + uiServiceGroupService.updateServiceGroupList(Arrays.asList(updateEntities), authorizationService.isSMPAdministrator()); } private String decodeUrlToUTF8(String value) {