diff --git a/smp-angular/src/styles.css b/smp-angular/src/styles.css index f0722b5cbf73ee256bd31081ff57899b48072da8..5166bb551bcd99530c4749238e603b96bc3e379a 100644 --- a/smp-angular/src/styles.css +++ b/smp-angular/src/styles.css @@ -50,6 +50,24 @@ ngx-datatable span:before { content: " " !important; } +/* selection for datatable */ +.ngx-datatable .datatable-body-cell, .ngx-datatable .datatable-header-cell { + -webkit-user-select: auto !important; + -moz-user-select: auto !important; + -ms-user-select: auto !important; + -o-user-select: auto !important; + user-select: auto !important; +} + +.ngx-datatable .datatable-body-cell, .ngx-datatable .datatable-header-cell { + -webkit-user-select: auto !important; + -moz-user-select: auto !important; + -ms-user-select: auto !important; + -o-user-select: auto !important; + user-select: auto !important; + padding: 0.5em !important; +} + .ngx-datatable span { word-wrap: break-word; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java index 8fb1ef6701fed93d5f05cb4d7b853610b29c11a4..de28db36b0e79b5d5dd8c3731587b6e487727295 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java @@ -155,10 +155,12 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> implements Initia return result; } + @Transactional public String getCachedProperty(SMPPropertyEnum key) { return getCachedProperty(key.getProperty(), key.getDefValue()); } + @Transactional public String getCachedProperty(String property, String defValue) { if (lastUpdate == null) { // init properties diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/enums/ApplicationRoleType.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/enums/ApplicationRoleType.java index 98965efb4cdc5e1a442aa313a5faabd919b2778a..b42bab4c0dd7e48d03e68db5e3671b2eb8eb50ed 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/enums/ApplicationRoleType.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/enums/ApplicationRoleType.java @@ -1,30 +1,34 @@ package eu.europa.ec.edelivery.smp.data.enums; +import eu.europa.ec.edelivery.smp.data.ui.auth.SMPRole; + public enum ApplicationRoleType { - USER("USER","WS_USER"), - SYSTEM_ADMIN("SYSTEM_ADMIN","WS_USER"); - String apiName; - String uiName; - - ApplicationRoleType(String uiName, String apiName) { - this.apiName = apiName; - this.uiName = uiName; + USER(SMPRole.USER, SMPRole.WS_USER), + SYSTEM_ADMIN(SMPRole.SYSTEM_ADMIN, SMPRole.WS_SYSTEM_ADMIN); + + + SMPRole apiRole; + SMPRole uiRole; + + ApplicationRoleType(SMPRole uiRole, SMPRole apiRole) { + this.uiRole = uiRole; + this.apiRole = apiRole; } - public String getAPIRole(){ + public String getAPIRole() { return "ROLE_" + apiName(); } - public String getUIRole(){ - return apiName; + public String getUIRole() { + return "ROLE_" + uiName(); } - public String apiName(){ - return apiName; + public String apiName() { + return apiRole.getCode(); } - public String uiName(){ - return uiName; + public String uiName() { + return uiRole.getCode(); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPAuthority.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPAuthority.java index 7c63109df5002d8187c721845420349df4a22e48..9f1ba51aadef510da58f9305a13401405b8078c8 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPAuthority.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPAuthority.java @@ -16,7 +16,9 @@ import org.springframework.security.core.GrantedAuthority; public class SMPAuthority implements GrantedAuthority { // static constants for annotations! - public static final String S_AUTHORITY_TOKEN_WS_SMP_ADMIN = "ROLE_WS_SMP_ADMIN"; + public static final String S_AUTHORITY_TOKEN_WS_SYSTEM_ADMIN = "ROLE_WS_SYSTEM_ADMIN"; + + public static final String S_AUTHORITY_TOKEN_WS_USER= "ROLE_WS_USER"; // ui public static final String S_AUTHORITY_TOKEN_SYSTEM_ADMIN = "ROLE_SYSTEM_ADMIN"; public static final String S_AUTHORITY_TOKEN_USER = "ROLE_USER"; @@ -25,9 +27,8 @@ public class SMPAuthority implements GrantedAuthority { public static final SMPAuthority S_AUTHORITY_SYSTEM_ADMIN = new SMPAuthority(SMPRole.SYSTEM_ADMIN.getCode()); public static final SMPAuthority S_AUTHORITY_USER = new SMPAuthority(SMPRole.USER.getCode()); public static final SMPAuthority S_AUTHORITY_ANONYMOUS = new SMPAuthority(SMPRole.ANONYMOUS.getCode()); - public static final SMPAuthority S_AUTHORITY_WS_USER = new SMPAuthority(SMPRole.WS_USER.getCode()); - public static final SMPAuthority S_AUTHORITY_WS_SYSTEM_ADMIN = new SMPAuthority(SMPRole.SYSTEM_ADMIN.getCode()); + public static final SMPAuthority S_AUTHORITY_WS_SYSTEM_ADMIN = new SMPAuthority(SMPRole.WS_SYSTEM_ADMIN.getCode()); String role; @@ -62,6 +63,8 @@ public class SMPAuthority implements GrantedAuthority { return S_AUTHORITY_WS_USER; case SYSTEM_ADMIN: return S_AUTHORITY_SYSTEM_ADMIN; + case WS_SYSTEM_ADMIN: + return S_AUTHORITY_WS_SYSTEM_ADMIN; default: return S_AUTHORITY_ANONYMOUS; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPRole.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPRole.java index 729dacc3fe6eafa7c44f0d2a675386a1192454ff..d499421bd884694d91302c8daef7acae491f71b2 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPRole.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/auth/SMPRole.java @@ -6,6 +6,7 @@ public enum SMPRole { USER("USER"), WS_USER("WS_USER"), SYSTEM_ADMIN("SYSTEM_ADMIN"), + WS_SYSTEM_ADMIN("WS_SYSTEM_ADMIN") ; String code; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverService.java index ab1b027345371c7e7bb88d6f91a185f7840af93d..529eec63f8ca54d62092389e719c751ef5692ced 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverService.java @@ -264,7 +264,8 @@ public class ResourceResolverService { resource.setDocument(new DBDocument()); resource.getDocument().setName(resourceDef.getName()); resource.getDocument().setMimeType(resourceDef.getMimeType()); - resource.setDomainResourceDef(domainResourceDefDao.getResourceDefConfigurationForDomainAndResourceDef(domain, resourceDef).get()); + resource.setDomainResourceDef(domainResourceDefDao.getResourceDefConfigurationForDomainAndResourceDef(domain, resourceDef) + .orElse(null)); return resource; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpIdentifierService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpIdentifierService.java index 6db8bbb7198e799ae6b51cb54f2e572414b27c8b..553cc62785ed143010ab01e7a73a0a45c533e52d 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpIdentifierService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpIdentifierService.java @@ -2,6 +2,8 @@ package eu.europa.ec.edelivery.smp.services.spi; import eu.europa.ec.edelivery.smp.conversion.IdentifierService; import eu.europa.ec.edelivery.smp.identifiers.Identifier; +import eu.europa.ec.edelivery.smp.logging.SMPLogger; +import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory; import eu.europa.ec.edelivery.smp.services.ConfigurationService; import eu.europa.ec.smp.spi.api.SmpIdentifierServiceApi; import eu.europa.ec.smp.spi.api.model.ResourceIdentifier; @@ -19,6 +21,7 @@ import java.util.regex.Pattern; */ @Service public class SmpIdentifierService implements SmpIdentifierServiceApi { + private static final SMPLogger LOG = SMPLoggerFactory.getLogger(SmpIdentifierService.class); final IdentifierService identifierService; final ConfigurationService configurationService; @@ -77,9 +80,14 @@ public class SmpIdentifierService implements SmpIdentifierServiceApi { @Override public boolean concatenateResourceIdentifier(ResourceIdentifier identifier) { Pattern concatenatePartyId = configurationService.getParticipantIdentifierUrnValidationRexExp(); + if (identifier == null || StringUtils.isBlank(identifier.getScheme())) { + LOG.debug("Return false for null or empty scheme identifier!"); + return false; + } - return identifier == null - && StringUtils.isNotBlank(identifier.getScheme()) && concatenatePartyId != null && concatenatePartyId.matcher(identifier.getScheme()).matches(); + return concatenatePartyId != null + && concatenatePartyId.matcher(identifier.getScheme()) + .matches(); } private Identifier toIdentifier(ResourceIdentifier identifier) { diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpXmlSignatureService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpXmlSignatureService.java index fd779662a1e93ac83b7eacaf79b3ff698e5607d8..0a84ef9010576c880415044a096b6eb5551d6313 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpXmlSignatureService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/spi/SmpXmlSignatureService.java @@ -86,8 +86,7 @@ public final class SmpXmlSignatureService implements SmpXmlSignatureApi { public void createEnvelopedSignature(RequestData resourceMetadata, Element parentSignatureNode, List<String> signedElementURIList) throws SignatureException { // Find the domain for the identifier - - if (resourceMetadata == null && resourceMetadata.getResourceIdentifier() == null) { + if (resourceMetadata == null || resourceMetadata.getResourceIdentifier() == null) { throw new SignatureException(SignatureException.ErrorCode.INVALID_PARAMETERS, "Missing resource identifier"); } @@ -97,14 +96,7 @@ public final class SmpXmlSignatureService implements SmpXmlSignatureApi { Optional<DBDomain> optDomain = domainDao.getDomainByCode(resourceMetadata.getDomainCode()); DBDomain domain = optDomain.orElseThrow( () -> new SignatureException(SignatureException.ErrorCode.INVALID_PARAMETERS, "Domain for the domain code [" + resourceMetadata.getDomainCode() + "] does not exists!")); - ; - - // get domain for the document - // get alias for the - // type is known - // - // get createEnvelopedSignature(parentSignatureNode, Collections.emptyList(), domain.getSignatureKeyAlias(), diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/monitor/MonitorResource.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/monitor/MonitorResource.java index 03b30792dd447bdd0d036c260b4b58b8cc88ab19..8f8a3e45d50e5d612516dde11f5d50baf6a34af1 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/monitor/MonitorResource.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/monitor/MonitorResource.java @@ -1,23 +1,24 @@ package eu.europa.ec.edelivery.smp.monitor; +import eu.europa.ec.edelivery.smp.data.dao.DocumentDao; import eu.europa.ec.edelivery.smp.data.dao.DomainDao; -import eu.europa.ec.edelivery.smp.data.dao.ResourceDao; import eu.europa.ec.edelivery.smp.data.model.DBDomain; -import eu.europa.ec.edelivery.smp.data.model.doc.DBResource; import eu.europa.ec.edelivery.smp.data.ui.auth.SMPAuthority; +import eu.europa.ec.edelivery.smp.exceptions.SMPTestIsALiveException; import eu.europa.ec.edelivery.smp.logging.SMPLogger; import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory; -import eu.europa.ec.edelivery.smp.services.ServiceGroupService; -import org.springframework.beans.factory.annotation.Autowired; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.annotation.Secured; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.Objects; /** * @author Joze Rihtarsic @@ -31,57 +32,34 @@ public class MonitorResource { private static final SMPLogger LOG = SMPLoggerFactory.getLogger(MonitorResource.class); - @Autowired - private ServiceGroupService serviceGroupService; + private static final String TEST_NAME = "urn:test:document:is-alive"; + private static final String TEST_EXTENSION_XML = "<Extension xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\"><ex:dummynode xmlns:ex=\"http://test.eu\">Sample not mandatory extension</ex:dummynode></Extension>"; + private static final String TEST_DB_SUCCESSFUL_ROLLBACK = "TEST_DB_SUCCESSFUL_ROLLBACK MESSAGE"; - @Autowired - private DomainDao domainDao; - @Autowired - private ResourceDao serviceGroupDao; + private final DocumentDao documentDao; + private final DomainDao domainDao; - private static final String TEST_PART_SCHEMA = "test-actorid-qns"; - private static final String TEST_PART_ID = "urn:test:is:alive"; - private static final String TEST_EXTENSION_XML = "<Extension xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\"><ex:dummynode xmlns:ex=\"http://test.eu\">Sample not mandatory extension</ex:dummynode></Extension>"; - private static final String TEST_DB_SUCCESSFUL_ROLLBACK = "TEST_DB_SUCCESSFUL_ROLLBACK MESSAGE"; + public MonitorResource(DocumentDao documentDao, DomainDao domainDao) { + this.documentDao = documentDao; + this.domainDao = domainDao; + } @GetMapping(path = "/is-alive") - @Secured({SMPAuthority.S_AUTHORITY_TOKEN_SYSTEM_ADMIN, SMPAuthority.S_AUTHORITY_TOKEN_USER, SMPAuthority.S_AUTHORITY_TOKEN_WS_SMP_ADMIN}) + @Secured({SMPAuthority.S_AUTHORITY_TOKEN_WS_SYSTEM_ADMIN}) public ResponseEntity isAlive() { boolean suc = false; -/* - String user = SecurityContextHolder.getContext().getAuthentication().getName(); - LOG.debug("Start isAlive function for user: " + SecurityContextHolder.getContext().getAuthentication().getName()); - byte[] bServiceGroup = null; - try { - bServiceGroup = IOUtils.readBytesFromStream( - MonitorResource.class.getResourceAsStream("/isAliveTestFiles/ServiceGroupTest.xml")); - - } catch (IOException e) { - LOG.error("Error reading test resource file", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - ServiceGroup serviceGroup; - try { - // Validations - BdxSmpOasisValidator.validateXSD(bServiceGroup); - serviceGroup = ServiceGroupConverter.unmarshal(bServiceGroup); - serviceGroupValidator - .validate(TEST_PART_SCHEMA + "::" + TEST_PART_ID, serviceGroup); - } catch (XmlInvalidAgainstSchemaException ex) { - LOG.error("Error reading testing resource file", ex); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } + String user = SecurityContextHolder.getContext().getAuthentication().getName(); + LOG.debug("Start isAlive function for user: [{}]", user); try { suc = testDatabase(); } catch (SMPTestIsALiveException ex) { suc = Objects.equals(TEST_DB_SUCCESSFUL_ROLLBACK, ex.getMessage()); } catch (RuntimeException th) { - LOG.error("Error occurred while testing database connection: Msg:" + ExceptionUtils.getRootCauseMessage(th), th); + LOG.error("Error occurred while testing database connection: Msg: [{}]", ExceptionUtils.getRootCauseMessage(th)); } - */ return suc ? ResponseEntity.ok().build() : ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } @@ -92,14 +70,6 @@ public class MonitorResource { LOG.error("Bad configuration! At least one domain must be configured!"); return false; } - - DBResource newSg = new DBResource(); - newSg.setIdentifierValue(TEST_PART_ID); - newSg.setIdentifierScheme(TEST_PART_SCHEMA); - // newSg.setExtension(TEST_EXTENSION_XML.getBytes()); - //newSg.addDomain(lstDomain.get(0)); // add initial domain - // persist (make sure this is not in transaction) - serviceGroupDao.testPersist(newSg, true, TEST_DB_SUCCESSFUL_ROLLBACK); return true; } diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorResourceTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorResourceTest.java index c7ec8cb55844738c065c63a6ee2ac2531a43cd77..593cec67fde1159d9169a907d7271e97b6c1646a 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorResourceTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorResourceTest.java @@ -26,7 +26,7 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import java.io.IOException; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -43,12 +43,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. "classpath:/cleanup-database.sql", "classpath:/webapp_integration_test_data.sql"}, executionPhase = BEFORE_TEST_METHOD) -@Ignore public class MonitorResourceTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - private static final String URL = "/monitor/is-alive"; private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("pat_smp_admin", "123456"); @Autowired @@ -76,7 +72,6 @@ public class MonitorResourceTest { listener.contextInitialized(event); } - @Test public void isAliveNotAuthorized() throws Exception { mvc.perform(get(URL)) @@ -92,12 +87,10 @@ public class MonitorResourceTest { @Test public void testDatabase() { - // given - expectedEx.expectMessage("TEST_DB_SUCCESSFUL_ROLLBACK MESSAGE"); - expectedEx.expect(SMPTestIsALiveException.class); // when - boolean bval = testInstance.testDatabase(); - //then - assertTrue(bval); + boolean result = testInstance.testDatabase(); + + assertTrue(result); + } }