From 0954599d6751ddf22bf59f20dfb447caaf2b5f11 Mon Sep 17 00:00:00 2001
From: RIHTARSIC Joze <joze.rihtarsic@ext.ec.europa.eu>
Date: Tue, 25 Apr 2023 13:10:24 +0200
Subject: [PATCH] Fix edit group domain change not refreshing groups

---
 .../edit/edit-group/edit-group.component.html |  2 +-
 smp-examples/pom.xml                          |  2 +-
 .../pom.xml                                   |  2 +-
 .../spi/ExamplePayloadValidatorSpiImpl.java   |  0
 .../src/main/resources/logback.xml            |  0
 .../smp/data/model/doc/DBResource.java        | 30 ++++++++---------
 .../smp/services/SMLIntegrationService.java   |  3 +-
 .../services/ui/UITruststoreServiceTest.java  | 33 +++++++++++++++++++
 8 files changed, 52 insertions(+), 20 deletions(-)
 rename smp-examples/{smp-spi-example => smp-spi-payload-validation-example}/pom.xml (96%)
 rename smp-examples/{smp-spi-example => smp-spi-payload-validation-example}/src/main/java/eu/europa/ec/smp/spi/ExamplePayloadValidatorSpiImpl.java (100%)
 rename smp-examples/{smp-spi-example => smp-spi-payload-validation-example}/src/main/resources/logback.xml (100%)

diff --git a/smp-angular/src/app/edit/edit-group/edit-group.component.html b/smp-angular/src/app/edit/edit-group/edit-group.component.html
index 7437b134c..86363c03a 100644
--- a/smp-angular/src/app/edit/edit-group/edit-group.component.html
+++ b/smp-angular/src/app/edit/edit-group/edit-group.component.html
@@ -32,7 +32,7 @@
     <mat-select placeholder="Select domain"
                 matTooltip="Select domain."
                 id="domain_id"
-                [value]="selectedDomain"
+                [(value)]="selectedDomain"
                 required>
       <mat-option *ngFor="let domain of domainList"
                   [value]="domain"
diff --git a/smp-examples/pom.xml b/smp-examples/pom.xml
index 79e3dc2c8..d2736ea0b 100644
--- a/smp-examples/pom.xml
+++ b/smp-examples/pom.xml
@@ -25,6 +25,6 @@
     <packaging>pom</packaging>
     <description>The sub-project contains SMP examples of API and SPI implementations. Currently, SPI payload validation example.</description>
     <modules>
-        <module>smp-spi-example</module>
+        <module>smp-spi-payload-validation-example</module>
     </modules>
 </project>
diff --git a/smp-examples/smp-spi-example/pom.xml b/smp-examples/smp-spi-payload-validation-example/pom.xml
similarity index 96%
rename from smp-examples/smp-spi-example/pom.xml
rename to smp-examples/smp-spi-payload-validation-example/pom.xml
index e079f8748..c574fe76e 100644
--- a/smp-examples/smp-spi-example/pom.xml
+++ b/smp-examples/smp-spi-payload-validation-example/pom.xml
@@ -24,7 +24,7 @@
         <maven.deploy.skip>false</maven.deploy.skip>
     </properties>
 
-    <artifactId>smp-spi-example</artifactId>
+    <artifactId>smp-spi-payload-validation-example</artifactId>
     <name>smp-spi-example</name>
     <description>Example of SMP's SPI Payload validation.</description>
     <dependencies>
diff --git a/smp-examples/smp-spi-example/src/main/java/eu/europa/ec/smp/spi/ExamplePayloadValidatorSpiImpl.java b/smp-examples/smp-spi-payload-validation-example/src/main/java/eu/europa/ec/smp/spi/ExamplePayloadValidatorSpiImpl.java
similarity index 100%
rename from smp-examples/smp-spi-example/src/main/java/eu/europa/ec/smp/spi/ExamplePayloadValidatorSpiImpl.java
rename to smp-examples/smp-spi-payload-validation-example/src/main/java/eu/europa/ec/smp/spi/ExamplePayloadValidatorSpiImpl.java
diff --git a/smp-examples/smp-spi-example/src/main/resources/logback.xml b/smp-examples/smp-spi-payload-validation-example/src/main/resources/logback.xml
similarity index 100%
rename from smp-examples/smp-spi-example/src/main/resources/logback.xml
rename to smp-examples/smp-spi-payload-validation-example/src/main/resources/logback.xml
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResource.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResource.java
index 8e7dc163c..2b97648c7 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResource.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResource.java
@@ -76,40 +76,40 @@ import static eu.europa.ec.edelivery.smp.data.dao.QueryNames.*;
 @NamedQuery(name = "DBResource.getPublicSearch", query = "SELECT r FROM  DBResource r WHERE r.group.visibility='PUBLIC' " +
         " AND (r.group.domain.visibility='PUBLIC' " +
         "    OR :user_id IS NOT NULL " +
-        "     AND ( (select count(id) from DBDomainMember dm where dm.user.id = :user_id and dm.domain.id = r.group.domain.id) > 0 " +
-        "      OR (select count(id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.domain.id = r.group.domain.id) > 0 " +
-        "      OR (select count(id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.domain.id = r.group.domain.id) > 0 " +
+        "     AND ( (select count(dm.id) from DBDomainMember dm where dm.user.id = :user_id and dm.domain.id = r.group.domain.id) > 0 " +
+        "      OR (select count(gm.id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.domain.id = r.group.domain.id) > 0 " +
+        "      OR (select count(rm.id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.domain.id = r.group.domain.id) > 0 " +
         "     ) " +
         "  ) " +
         " AND (r.group.visibility='PUBLIC' " +
-        "    OR  :user_id IS NOT NULL " +
-        "     AND ( (select count(id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.id = r.group.id) > 0 " +
-        "      OR (select count(id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.id = r.group.id) > 0 " +
-        "     ) " +
+        "    OR  (:user_id IS NOT NULL " +
+        "     AND ( (select count(gm.id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.id = r.group.id) > 0 " +
+        "      OR (select count(rm.id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.id = r.group.id) > 0 " +
+        "     ) )" +
         "  ) " +
         " AND ( r.visibility = 'PUBLIC' " +
-        "   OR :user_id IS NOT NULL " +
-        "     AND (select count(id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.id = r.id) > 0 ) " +
+        "   OR (:user_id IS NOT NULL " +
+        "     AND (select count(id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.id = r.id) > 0 )) " +
         " AND (:resource_identifier IS NULL OR r.identifierValue like :resource_identifier )" +
         " AND (:resource_scheme IS NULL OR r.identifierScheme like :resource_scheme) order by r.identifierScheme, r.identifierValue"
 )
 @NamedQuery(name = "DBResource.getPublicSearchCount", query = "SELECT count(r.id) FROM  DBResource r WHERE r.group.visibility='PUBLIC' " +
         " AND (r.group.domain.visibility='PUBLIC' " +
         "    OR :user_id IS NOT NULL " +
-        "     AND ( (select count(id) from DBDomainMember dm where dm.user.id = :user_id and dm.domain.id = r.group.domain.id) > 0 " +
-        "      OR (select count(id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.domain.id = r.group.domain.id) > 0 " +
-        "      OR (select count(id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.domain.id = r.group.domain.id) > 0 " +
+        "     AND ( (select count(dm.id) from DBDomainMember dm where dm.user.id = :user_id and dm.domain.id = r.group.domain.id) > 0 " +
+        "      OR (select count(gm.id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.domain.id = r.group.domain.id) > 0 " +
+        "      OR (select count(rm.id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.domain.id = r.group.domain.id) > 0 " +
         "     ) " +
         "  ) " +
         " AND (r.group.visibility='PUBLIC' " +
         "    OR  :user_id IS NOT NULL " +
-        "     AND ( (select count(id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.id = r.group.id) > 0 " +
-        "      OR (select count(id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.id = r.group.id) > 0 " +
+        "     AND ( (select count(gm.id) from DBGroupMember gm where gm.user.id = :user_id and gm.group.id = r.group.id) > 0 " +
+        "      OR (select count(rm.id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.group.id = r.group.id) > 0 " +
         "     ) " +
         "  ) " +
         " AND ( r.visibility = 'PUBLIC' " +
         "   OR :user_id IS NOT NULL " +
-        "     AND (select count(id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.id = r.id) > 0 ) " +
+        "     AND (select count(rm.id) from DBResourceMember rm where rm.user.id = :user_id and rm.resource.id = r.id) > 0 ) " +
         " AND (:resource_identifier IS NULL OR r.identifierValue like :resource_identifier )" +
         " AND (:resource_scheme IS NULL OR r.identifierScheme like :resource_scheme)"
 )
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java
index 758b51974..ac2e40e77 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java
@@ -94,8 +94,7 @@ public class SMLIntegrationService {
         LOG.businessDebug(BUS_SML_REGISTER_SERVICE_GROUP, resource.getIdentifierValue(), resource.getIdentifierScheme(), domain.getDomainCode());
         if (!isSMLIntegrationEnabled()) {
             String msg = "SML integration is not enabled!";
-            LOG.businessError(BUS_SML_REGISTER_SERVICE_GROUP_FAILED, resource.getIdentifierValue(), resource.getIdentifierScheme(), domain.getDomainCode(), msg);
-            throw new SMPRuntimeException(CONFIGURATION_ERROR, msg);
+            LOG.businessWarn(BUS_SML_REGISTER_SERVICE_GROUP_FAILED, resource.getIdentifierValue(), resource.getIdentifierScheme(), domain.getDomainCode(), msg);
         }
         Identifier normalizedParticipantId = identifierService
                 .normalizeParticipant(resource.getIdentifierScheme(), resource.getIdentifierValue());
diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java
index d60081d56..11c7672d8 100644
--- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java
+++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java
@@ -1,5 +1,7 @@
 package eu.europa.ec.edelivery.smp.services.ui;
 
+import eu.europa.ec.edelivery.security.utils.KeystoreUtils;
+import eu.europa.ec.edelivery.security.utils.X509CertificateUtils;
 import eu.europa.ec.edelivery.smp.data.dao.UserDao;
 import eu.europa.ec.edelivery.smp.data.model.user.DBUser;
 import eu.europa.ec.edelivery.smp.data.ui.CertificateRO;
@@ -8,6 +10,7 @@ import eu.europa.ec.edelivery.smp.services.CRLVerifierService;
 import eu.europa.ec.edelivery.smp.services.ConfigurationService;
 import eu.europa.ec.edelivery.smp.testutil.X509CertificateTestUtils;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.ArgumentMatchers;
@@ -16,11 +19,15 @@ import org.springframework.core.convert.ConversionService;
 
 import javax.security.auth.x500.X500Principal;
 import java.io.File;
+import java.io.FileOutputStream;
+import java.math.BigInteger;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.security.KeyStore;
 import java.security.Security;
 import java.security.cert.*;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Optional;
 import java.util.UUID;
 import java.util.regex.Pattern;
@@ -175,6 +182,7 @@ public class UITruststoreServiceTest {
                 resultException.getMessage());
     }
 
+
     @Test
     public void validateCertificateSubjectExpressionLegacyValidatedMatch() throws Exception {
         String regularExpression = ".*CN=Something.*";
@@ -201,4 +209,29 @@ public class UITruststoreServiceTest {
         result = testInstance.loadTruststore(resourceDirectory.toFile());
         assertNull(result);
     }
+
+
+    /**
+     * This method is not a tests is it done for generating the  tests Soapui certificates
+     * @throws Exception
+     */
+    @Test
+    @Ignore
+    public void generateSoapUITestCertificates() throws Exception {
+
+        List <String[]> listCerts = Arrays.asList( new String[]{"f71ee8b11cb3b787","CN=EHEALTH_SMP_EC,O=European Commission,C=BE","ehealth_smp_ec",},
+                new String[]{"E07B6b956330a19a","CN=blue_gw,O=eDelivery,C=BE","blue_gw"},
+                new String[]{"9792ce69BC89F14C","CN=red_gw,O=eDelivery,C=BE","red_gw"}
+        );
+        String token = "test123";
+        File keystoreFile = new File( "./target/smp-test-examples.p12");
+        KeyStore keyStore = KeystoreUtils.createNewKeystore(keystoreFile, token);
+        for (String[] data: listCerts) {
+            BigInteger serial = new BigInteger(data[0],16);
+            X509CertificateUtils.createAndStoreSelfSignedCertificate(serial, data[1],data[2], keyStore, token);
+        }
+        try (FileOutputStream fos = new FileOutputStream(keystoreFile)) {
+            keyStore.store(fos, token.toCharArray());
+        }
+    }
 }
-- 
GitLab