diff --git a/pom.xml b/pom.xml index 6cf3bf102daca7e75c0c1709b659c0a19bcb1b0b..26278de5a329e5800ecdb91c2debd004d2df4fbf 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ <modules> <module>smp-parent-pom</module> <module>smp-api</module> - <module>smp-angular</module> + <!-- module>smp-angular</module --> <module>smp-server-library</module> <module>smp-webapp</module> </modules> diff --git a/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java b/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java index df3636cc1efb9763836521d8b4319c09a261f5e8..0bd3d275f2e71b780d5359b21b6f5ffc4faacacd 100644 --- a/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java +++ b/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java @@ -22,6 +22,8 @@ import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.StringReader; import java.net.URL; @@ -59,9 +61,9 @@ public class BdxSmpOasisValidator { return validator.get(); } - public static void validateXSD(String xmlBody) throws XmlInvalidAgainstSchemaException { + public static void validateXSD(byte[] xmlBody) throws XmlInvalidAgainstSchemaException { try { - getValidator().validate(new StreamSource(new StringReader(xmlBody))); + getValidator().validate(new StreamSource(new ByteArrayInputStream(xmlBody))); } catch (SAXException | IOException e) { throw new XmlInvalidAgainstSchemaException(e.getMessage(), e); } diff --git a/smp-api/src/test/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidatorTest.java b/smp-api/src/test/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidatorTest.java index a45d7215902da46bcb0649d2391fbb42777d0e35..fd2ec90745b91f5c2db6034af823352b99e46beb 100644 --- a/smp-api/src/test/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidatorTest.java +++ b/smp-api/src/test/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidatorTest.java @@ -38,7 +38,7 @@ public class BdxSmpOasisValidatorTest { @Parameters({"ServiceMetadata_OK.xml","ServiceGroup_OK.xml"}) public void testValidatePositive(String xmlFilename) throws IOException, XmlInvalidAgainstSchemaException { // given - String xmlBody = loadXMLFile(xmlFilename); + byte[] xmlBody = loadXMLFileAsByteArray(xmlFilename); // when BdxSmpOasisValidator.validateXSD(xmlBody); @@ -61,7 +61,7 @@ public class BdxSmpOasisValidatorTest { @Parameters(method = "negativeCases") public void testValidateNegative(String xmlFilename, String output) throws IOException { // given - String xmlBody = loadXMLFile(xmlFilename); + byte[] xmlBody = loadXMLFileAsByteArray(xmlFilename); // when try { @@ -78,4 +78,9 @@ public class BdxSmpOasisValidatorTest { URL fileUrl = BdxSmpOasisValidatorTest.class.getResource("/XMLValidation/"+path); return IOUtils.toString(fileUrl.openStream(), UTF_8); } + + public byte[] loadXMLFileAsByteArray(String path) throws IOException { + URL fileUrl = BdxSmpOasisValidatorTest.class.getResource("/XMLValidation/"+path); + return IOUtils.toByteArray(fileUrl.openStream()); + } } diff --git a/smp-parent-pom/pom.xml b/smp-parent-pom/pom.xml index 6da417ebc3ecfcc0411d9925512fd687a6ff7694..63b7d0db3d5ef1723fafc070f2517e3d1b5844d8 100644 --- a/smp-parent-pom/pom.xml +++ b/smp-parent-pom/pom.xml @@ -86,19 +86,18 @@ <hibernate.version>5.2.13.Final</hibernate.version> <hibernate-jpa.version>1.0.2.Final</hibernate-jpa.version> <hibernate.validator.version>6.0.13.Final</hibernate.validator.version> - <hibernate.annotations.version>3.5.6-Final</hibernate.annotations.version> <h2.version>1.4.187</h2.version> <oracle.version>12.1.0.1</oracle.version> <mysql.version>5.1.45</mysql.version> <soapui.plugin.version>5.1.2</soapui.plugin.version> <commons-net.version>1.4.1</commons-net.version> <ant-commons-net.version>1.6.5</ant-commons-net.version> - <jetty.version>8.1.15.v20140411</jetty.version> + <!-- jetty.version>8.1.15.v20140411</jetty.version --> <servlet-api.version>3.0.1</servlet-api.version> <metro.version>2.2.1-1</metro.version> <commons-io.version>2.4</commons-io.version> <junitparams.version>1.0.5</junitparams.version> - <lombok.version>1.16.16</lombok.version> + <!-- lombok.version>1.16.16</lombok.version --> <xmlunit.version>2.5.1</xmlunit.version> <hamcrest.version>2.0.0.0</hamcrest.version> <jackson.version>2.9.2</jackson.version> @@ -265,11 +264,6 @@ <artifactId>hibernate-envers</artifactId> <version>${hibernate.version}</version> </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>${hibernate.annotations.version}</version> - </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> @@ -367,12 +361,12 @@ <artifactId>spring-context-support</artifactId> <version>${spring.security.version}</version> </dependency> - <dependency> + <!-- dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <scope>provided</scope> - </dependency> + </dependency --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> diff --git a/smp-server-library/pom.xml b/smp-server-library/pom.xml index cb85416b100f995aa08b13d4ae4c575e8a40c251..73eb58bb2ad09ffd228486659801f0f6e6fcb7a1 100644 --- a/smp-server-library/pom.xml +++ b/smp-server-library/pom.xml @@ -116,14 +116,10 @@ <groupId>org.hibernate</groupId> <artifactId>hibernate-envers</artifactId> </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - </dependency> - <dependency> + <!--dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> - </dependency> + </dependency --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/SMPRole.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/SMPRole.java deleted file mode 100644 index b059422ef0244722cd51ecddad32914a6bc10b45..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/SMPRole.java +++ /dev/null @@ -1,8 +0,0 @@ -package eu.europa.ec.edelivery.smp; - -public enum SMPRole { - - SMP_ADMIN, - SERVICE_GROUP_ADMIN, - SYSTEM_ADMIN -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java index 9fa25c8e5de8b7dea4077f51fbc23c7e179c470b..b66ba56f8d74fbf7bca1929176f2b6b62e103abb 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java @@ -66,7 +66,11 @@ public class CaseSensitivityNormalizer { } public String normalizeParticipantId(String participantId) { - return asString(normalize(asParticipantId(participantId))); + return asString(normalizeParticipant(participantId)); + } + + public ParticipantIdentifierType normalizeParticipant(String participantId) { + return normalize(asParticipantId(participantId)); } private static void toLowerCaseStringList(List<String> strings) { diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverter.java index a9152c0516577472327462b1f8b4e0c348b41db1..0a40e3176581df5fba0def1c2071966c284d2a4c 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverter.java @@ -27,10 +27,7 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import javax.xml.transform.stream.StreamSource; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.util.Collections; import java.util.List; @@ -41,7 +38,9 @@ import static java.nio.charset.StandardCharsets.UTF_8; */ public class ExtensionConverter { private static final SMPLogger LOG = SMPLoggerFactory.getLogger(ServiceGroupConverter.class); - private static final String WRAPPED_FORMAT = "<ExtensionsWrapper xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\">%s</ExtensionsWrapper>"; + // private static final String WRAPPED_FORMAT = "<ExtensionsWrapper xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\">%s</ExtensionsWrapper>"; + private static final byte[] WRAPPED_FORMAT_START = "<ExtensionsWrapper xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\">".getBytes(); + private static final byte[] WRAPPED_FORMAT_END = "</ExtensionsWrapper>".getBytes(); private static final QName EXT_TYPE_QNAME = new QName("http://docs.oasis-open.org/bdxr/ns/SMP/2016/05", "Extension"); /** @@ -70,25 +69,27 @@ public class ExtensionConverter { return extensionUnmarshaller.get(); } - public static String marshalExtensions(List<ExtensionType> extensions) throws JAXBException, XMLStreamException, UnsupportedEncodingException { + public static byte[] marshalExtensions(List<ExtensionType> extensions) throws JAXBException, XMLStreamException, IOException { return marshalExtensions(extensions, false); } - public static String marshalExtensions(List<ExtensionType> extensions, boolean prettyPrint ) throws JAXBException, XMLStreamException, UnsupportedEncodingException { + public static byte[] marshalExtensions(List<ExtensionType> extensions, boolean prettyPrint ) throws JAXBException, XMLStreamException, IOException { if (extensions == null) { return null; } - StringBuilder stringBuilder = new StringBuilder(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // StringBuilder stringBuilder = new StringBuilder(); for (ExtensionType aExtension : extensions) { - stringBuilder.append(ExtensionConverter.marshalExtension(aExtension, prettyPrint)); + baos.write(ExtensionConverter.marshalExtension(aExtension, prettyPrint)); + // stringBuilder.append(ExtensionConverter.marshalExtension(aExtension, prettyPrint)); } - return stringBuilder.toString(); + return baos.toByteArray(); } - private static String marshalExtension(ExtensionType extension, boolean prettyPrint ) throws JAXBException, XMLStreamException, UnsupportedEncodingException { + private static byte[] marshalExtension(ExtensionType extension, boolean prettyPrint ) throws JAXBException, XMLStreamException { if (extension == null) { return null; } @@ -114,12 +115,15 @@ public class ExtensionConverter { xsw.close(); } } - return baos.toString(UTF_8.name()); + //return baos.toString(UTF_8.name()); + return baos.toByteArray(); } - protected static List<ExtensionType> unmarshalExtensions(String xml) throws JAXBException { - String wrappedExtensionsStr = String.format(WRAPPED_FORMAT, xml); - InputStream inStream = new ByteArrayInputStream(wrappedExtensionsStr.getBytes(UTF_8)); + protected static List<ExtensionType> unmarshalExtensions(byte[] xml) throws JAXBException { + + + InputStream inStream = new ByteArrayInputStream(concatByteArrays(WRAPPED_FORMAT_START,xml,WRAPPED_FORMAT_END )); + Unmarshaller jaxbUnmarshaller = getUnmarshaller(); JAXBElement<ExtensionsWrapper> wrappedExtensions = jaxbUnmarshaller.unmarshal(new StreamSource(inStream), ExtensionsWrapper.class); if (wrappedExtensions.getValue() != null && wrappedExtensions.getValue().extensions != null) { @@ -128,4 +132,31 @@ public class ExtensionConverter { return Collections.emptyList(); } } + + /** + * Method concat the bytearrays to one array + * + * + * https://stackoverflow.com/questions/5513152/easy-way-to-concatenate-two-byte-arrays + * - Use varargs (...) to be called with any number of byte[]. + * - Use System.arraycopy() that is implemented with machine specific native code, to ensure high speed operation. + * - Create a new byte[] with the exact size that is need it. + * - Allocate little less int variables by reusing the i and len variables. + + * @param inputs - byte arrays + * @return + */ + public static byte[] concatByteArrays(byte[]... inputs) { + int i, len = 0; + for (i = 0; i < inputs.length; i++) { + len += inputs[i].length; + } + byte[] r = new byte[len]; + len = 0; + for (i = 0; i < inputs.length; i++) { + System.arraycopy(inputs[i], 0, r, len, inputs[i].length); + len += inputs[i].length; + } + return r; + } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java index c97a6cb75aeec9b0a635183f9d106bb304ded51a..bc590f32c4a75b53b3907097b47afb89df22084a 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java @@ -85,6 +85,20 @@ public class ServiceGroupConverter { } } + /** + * Method umarshal ServiceGroup from xml bytearraz + * @param serviceGroupXml + * @return + */ + public static ServiceGroup unmarshal(byte[] serviceGroupXml) { + try { + Document serviceGroupDoc = parse(serviceGroupXml); + return getUnmarshaller().unmarshal(serviceGroupDoc, ServiceGroup.class).getValue(); + } catch (ParserConfigurationException | IOException | SAXException | JAXBException ex) { + throw new SMPRuntimeException(ErrorCode.XML_PARSE_EXCEPTION,ex,ServiceGroup.class.getName(), ExceptionUtils.getRootCauseMessage(ex)); + } + } + /** * Method returns Oasis ServiceGroup entity with extension and * empty ServiceMetadataReferenceCollectionType. If extension can not be converted to jaxb object than @@ -102,7 +116,7 @@ public class ServiceGroupConverter { ServiceGroup serviceGroup = new ServiceGroup(); ParticipantIdentifierType identifier = new ParticipantIdentifierType(dsg.getParticipantIdentifier(), dsg.getParticipantScheme()); serviceGroup.setParticipantIdentifier(identifier); - if (!StringUtils.isBlank(dsg.getExtension())){ + if (dsg.getExtension()!=null){ try { List<ExtensionType> extensions = ExtensionConverter.unmarshalExtensions(dsg.getExtension()); serviceGroup.getExtensions().addAll(extensions); @@ -120,6 +134,11 @@ public class ServiceGroupConverter { return getDocumentBuilder().parse(inputStream); } + + private static Document parse(byte[] serviceGroupXml) throws ParserConfigurationException, IOException, SAXException { + InputStream inputStream = new ByteArrayInputStream(serviceGroupXml); + return getDocumentBuilder().parse(inputStream); + } private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); @@ -127,10 +146,10 @@ public class ServiceGroupConverter { return documentBuilderFactory.newDocumentBuilder(); } - public static String extractExtensionsPayload(ServiceGroup sg) { + public static byte[] extractExtensionsPayload(ServiceGroup sg) { try { return ExtensionConverter.marshalExtensions(sg.getExtensions()); - } catch (JAXBException | XMLStreamException | UnsupportedEncodingException e) { + } catch (JAXBException | XMLStreamException | IOException e) { throw new SMPRuntimeException(INVALID_EXTENSION_FOR_SG, e, sg.getParticipantIdentifier().getValue(), sg.getParticipantIdentifier().getScheme(), ExceptionUtils.getRootCauseMessage(e)); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverter.java index bbd7bef3b3e2406e5afcf51ae5422af4ad73a685..14fd3977988c8956310ceac7ad7db5125cf53401 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverter.java @@ -83,10 +83,10 @@ public class ServiceMetadataConverter { * @param serviceMetadataXml * @return w3d dom element */ - public static Document toSignedServiceMetadatadaDocument(String serviceMetadataXml) { + public static Document toSignedServiceMetadatadaDocument(byte[] serviceMetadataXml) { try { Document docServiceMetadata = parse(serviceMetadataXml); - Document root = parse(DOC_SIGNED_SERVICE_METADATA_EMPTY); + Document root = parse(DOC_SIGNED_SERVICE_METADATA_EMPTY.getBytes()); Node imported = root.importNode(docServiceMetadata.getDocumentElement(), true); root.getDocumentElement().appendChild(imported); return root; @@ -96,7 +96,7 @@ public class ServiceMetadataConverter { } - public static ServiceMetadata unmarshal(String serviceMetadataXml){ + public static ServiceMetadata unmarshal(byte[] serviceMetadataXml){ try { Document serviceMetadataDoc = parse(serviceMetadataXml); ServiceMetadata serviceMetadata = getUnmarshaller().unmarshal(serviceMetadataDoc, ServiceMetadata.class).getValue(); @@ -106,8 +106,8 @@ public class ServiceMetadataConverter { } } - private static Document parse(String serviceMetadataXml) throws SAXException, IOException, ParserConfigurationException { - InputStream inputStream = new ByteArrayInputStream(serviceMetadataXml.getBytes(UTF_8)); + private static Document parse(byte[] serviceMetadataXml) throws SAXException, IOException, ParserConfigurationException { + InputStream inputStream = new ByteArrayInputStream(serviceMetadataXml); return getDocumentBuilder().parse(inputStream); } @@ -118,6 +118,13 @@ public class ServiceMetadataConverter { return writer.toString(); } + public static byte[] toByteArray(Document doc) throws TransformerException, UnsupportedEncodingException { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + transformer.transform(new DOMSource(doc), new StreamResult(stream)); + return stream.toByteArray(); + } + private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/UserDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/UserDao.java index 4c185733182d1172235aa7fba9e3fca0bdbf8837..ac81494b6d2081b03372327e77a1552fb2b21e17 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/UserDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/UserDao.java @@ -14,18 +14,14 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.DBUser; -import eu.europa.ec.edelivery.smp.data.model.DBUserAuthority; import eu.europa.ec.edelivery.smp.exceptions.ErrorCode; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import org.apache.commons.lang3.StringUtils; -import org.springframework.security.core.GrantedAuthority; import org.springframework.stereotype.Repository; import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; import javax.persistence.TypedQuery; import javax.transaction.Transactional; -import java.util.ArrayList; -import java.util.List; import java.util.Optional; import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.ILLEGAL_STATE_CERT_ID_MULTIPLE_ENTRY; @@ -38,23 +34,6 @@ import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.ILLEGAL_STATE_USER public class UserDao extends BaseDao<DBUser> { - public List<GrantedAuthority> getUserRoles(String username) { - - List<GrantedAuthority> lstRes = new ArrayList<>(); - // all users are SERVICEGROUP_ADMIN - lstRes.add(DBUserAuthority.S_ROLE_SERVICEGROUP_ADMIN); - - List<DBUserAuthority> lst = memEManager - .createNamedQuery("DBUserAuthority.getRolesForUsernameNativeQuery") - .setParameter( "username",username) - .getResultList(); - - if (!lst.isEmpty()){ - lstRes.addAll(lst); - } - System.out.println("Got roles: " + lstRes.size() + " " + lstRes); - return lstRes; - } /** * Perstis user to database. Before that test if user has identifiers diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGenerator.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGenerator.java index fed2435cab38205bf8b4f6ebd109d0c121709ee1..45cb6a33575908ddcd16a095b0c144757f5ee86c 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGenerator.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGenerator.java @@ -127,7 +127,6 @@ public class SMPSchemaGenerator { try { directory = new File(Thread.currentThread().getContextClassLoader().getResource(pckgname.replace('.', '/')).getFile()); } catch (NullPointerException x) { - System.out.println("Nullpointer"); throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } if (directory.exists()) { @@ -139,8 +138,7 @@ public class SMPSchemaGenerator { classes.add(Class.forName(pckgname + '.' + files[i].substring(0, files[i].length() - 6))); } } - } else { - System.out.println("Directory does not exist"); + } else { ; throw new ClassNotFoundException("Package: "+pckgname + " does not eixsts!"); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java index a56fa73d6c54049f2694f9df9d0fa268f3de0d6e..c01c952dec727a29e51334ee935bc8952283230d 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java @@ -181,13 +181,13 @@ public class DBServiceGroup extends BaseEntity { } @Transient - public String getExtension() { + public byte[] getExtension() { return getServiceGroupExtension() != null ? getServiceGroupExtension().getExtension() : null; } - public void setExtension(String extension) { + public void setExtension(byte[] extension) { - if (StringUtils.isBlank(extension)) { + if (extension == null) { if (this.serviceGroupExtension != null) { this.serviceGroupExtension.setExtension(null); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupExtension.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupExtension.java index 044f6d44e31fa8485a03c3989cc3e6a07fbcb8a4..c27f84592be87568675fdb13c94653c3aca93749 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupExtension.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupExtension.java @@ -27,7 +27,7 @@ public class DBServiceGroupExtension extends BaseEntity { @Lob @Column(name = "EXTENSION") - String extension; + byte[] extension; @OneToOne @JoinColumn(name = "ID") @@ -51,11 +51,11 @@ public class DBServiceGroupExtension extends BaseEntity { this.dbServiceGroup = dbServiceGroup; } - public String getExtension() { + public byte[] getExtension() { return extension; } - public void setExtension(String extension) { + public void setExtension(byte[] extension) { this.extension = extension; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java index 2dc9862c9e2a8372274e5e5b502a0e5648147e43..e016200c3b40f6ea253d203b496cc7fc9fe57af8 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java @@ -127,14 +127,14 @@ public class DBServiceMetadata extends BaseEntity { } @Transient - public String getXmlContent() { + public byte[] getXmlContent() { return getServiceMetadataXml() != null ? getServiceMetadataXml().getXmlContent() : null; } @Transient - public void setXmlContent(String extension) { + public void setXmlContent(byte[] extension) { - if (StringUtils.isBlank(extension)) { + if (extension == null) { if (this.serviceMetadataXml != null) { this.serviceMetadataXml.setXmlContent(null); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadataXml.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadataXml.java index 44aba47cada8868944aa935db156d976de14450b..070f723e1732a3fd44c6423021b70c1f9670737b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadataXml.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadataXml.java @@ -26,7 +26,7 @@ public class DBServiceMetadataXml extends BaseEntity { @Lob @Column(name = "XML_CONTENT") - String xmlContent; + byte[] xmlContent; @OneToOne @JoinColumn(name = "ID") @@ -50,11 +50,11 @@ public class DBServiceMetadataXml extends BaseEntity { this.serviceMetadata = smd; } - public String getXmlContent() { + public byte[] getXmlContent() { return xmlContent; } - public void setXmlContent(String xmlContent) { + public void setXmlContent(byte[] xmlContent) { this.xmlContent = xmlContent; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUserAuthority.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUserAuthority.java deleted file mode 100644 index c3a5e6b0b3bfbd95b4a7b4ab2e0ce71dd5cc8aee..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUserAuthority.java +++ /dev/null @@ -1,41 +0,0 @@ -package eu.europa.ec.edelivery.smp.data.model; - -import org.springframework.security.core.GrantedAuthority; - -import javax.persistence.*; - -@NamedNativeQueries({ - @NamedNativeQuery( - name = "DBUserAuthority.getRolesForUsernameNativeQuery", - query = "SELECT 'ROLE_SMP_ADMIN' AS AUTHORITY FROM smp_user WHERE isadmin = 1 and username=:username " + - "UNION ALL " + - "SELECT CONCAT(businessIdentifierScheme, CONCAT('::', businessIdentifier)) AS AUTHORITY FROM smp_ownership WHERE username=:username", - resultSetMapping = "RoleDTO" - )}) - -@SqlResultSetMapping( - name = "RoleDTO", - classes = @ConstructorResult - ( - targetClass = DBUserAuthority.class, - columns = { - @ColumnResult(name = "authority", type = String.class) - } - ) -) -public class DBUserAuthority implements GrantedAuthority { - - public static DBUserAuthority S_ROLE_SERVICEGROUP_ADMIN = new DBUserAuthority("ROLE_SERVICEGROUP_ADMIN"); - - - public DBUserAuthority(String authority) { - this.authority = authority; - } - - String authority; - - @Override - public String getAuthority() { - return authority; - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceGroupRO.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceGroupRO.java index 0eb3a2199318dc6f49ad2238516616d5f74af07f..8fbbdfb095fd1b109c868cc634966b0291e39e3a 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceGroupRO.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceGroupRO.java @@ -1,8 +1,6 @@ package eu.europa.ec.edelivery.smp.data.ui; -import lombok.EqualsAndHashCode; -import lombok.ToString; import javax.persistence.*; import java.io.Serializable; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceMetadataRO.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceMetadataRO.java index cbf88c2835805baa1f412d36b0d023b144b039e5..2a2386982e20620352aabc4dfc13a96adb532c66 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceMetadataRO.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/ServiceMetadataRO.java @@ -1,8 +1,6 @@ package eu.europa.ec.edelivery.smp.data.ui; -import lombok.EqualsAndHashCode; -import lombok.ToString; import javax.persistence.*; import java.io.Serializable; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/UserRO.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/UserRO.java index b33e5da416083250085c401b91b5486a68bb26f9..d1704548e426df4593124d6eab5bfaea43b9d59b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/UserRO.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/UserRO.java @@ -1,14 +1,12 @@ package eu.europa.ec.edelivery.smp.data.ui; -import eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import javax.persistence.*; + + import java.io.Serializable; import java.time.LocalDateTime; -import java.util.Objects; + /** * @author Joze Rihtarsic diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorBusinessCode.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorBusinessCode.java index ff71b85399b655db89e4e11244067ae1ddde202f..0aa830f2253ccaca32271eff44a893d6cc5b25c5 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorBusinessCode.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorBusinessCode.java @@ -17,7 +17,7 @@ package eu.europa.ec.edelivery.smp.exceptions; * Created by migueti on 16/01/2017. */ public enum ErrorBusinessCode { - XML_INVALID, + XSD_INVALID, MISSING_FIELD, WRONG_FIELD, OUT_OF_RANGE, diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java index d42ab7adf48cf4c148924e6146667a3ba112e859..9872cf97ec7f03c2c8d3f662a82e9ae6f77b5fa1 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java @@ -21,20 +21,20 @@ public enum ErrorCode { INVALID_USER_NO_IDENTIFIERS (400,"SMP:120",ErrorBusinessCode.MISSING_FIELD,"Invalid user - no identifiers!"), ILLEGAL_STATE_USERNAME_MULTIPLE_ENTRY(500,"SMP:121",ErrorBusinessCode.TECHNICAL,"More than one user entry (username: '%s') is defined in database!"), ILLEGAL_STATE_CERT_ID_MULTIPLE_ENTRY(504,"SMP:122",ErrorBusinessCode.TECHNICAL,"More than one certificate entry (cert. id: '%s') is defined in database!"), - USER_NOT_EXISTS(404,"SMP:123",ErrorBusinessCode.NOT_FOUND,"User not exists or wrong password!"), // OWASP recommendation\ + USER_NOT_EXISTS(400,"SMP:123",ErrorBusinessCode.USER_NOT_FOUND,"User not exists or wrong password!"), // OWASP recommendation\ USER_IS_NOT_OWNER(400,"SMP:124",ErrorBusinessCode.UNAUTHORIZED,"User %s is not owner of service group (part. id: %s, part. sch.: '%s')!"), // OWASP recommendation // service group error ILLEGAL_STATE_SG_MULTIPLE_ENTRY (500,"SMP:130",ErrorBusinessCode.TECHNICAL,"More than one service group ( part. id: %s, part. sch.: '%s') is defined in database!"), - SG_NOT_EXISTS(404,"SMP:131",ErrorBusinessCode.NOT_FOUND,"Service group not exists (dpart. id: '%s', part. sch.: '%s')!"), + SG_NOT_EXISTS(404,"SMP:131",ErrorBusinessCode.NOT_FOUND,"ServiceGroup not found (dpart. id: '%s', part. sch.: '%s')!"), SG_NOT_REGISTRED_FOR_DOMAIN(400,"SMP:131",ErrorBusinessCode.NOT_FOUND,"Service group not registred for domain (domain: %s, part. id:~ '%s', part. sch.: '%s')!"), - INVALID_EXTENSION_FOR_SG (400,"SMP:132",ErrorBusinessCode.XML_INVALID,"Invalid extension for service group (part. id: '%s', part. sch.: '%s'). Error: %s!"), + INVALID_EXTENSION_FOR_SG (400,"SMP:132",ErrorBusinessCode.XSD_INVALID,"Invalid extension for service group (part. id: '%s', part. sch.: '%s'). Error: %s!"), // service metadata error ILLEGAL_STATE_SMD_MULTIPLE_ENTRY (500,"SMP:140",ErrorBusinessCode.TECHNICAL,"More than one service metadata ( doc. id: %s, doc. sch.: '%s') for participant ( part. id %s, part. sch. : '%s') is defined in database!"), - METADATA_NOT_EXISTS(404,"SMP:141",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not exist(part. id: '%s', part. sch.: '%s',doc. id: '%s', doc. sch.: '%s')!"), - SMD_NOT_EXISTS_FOR_DOMAIN(404,"SMP:142",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not exists for domain (domain: %s, part. id: '%s', part. sch.: '%s')!"), - INVALID_SMD_XML (400,"SMP:143",ErrorBusinessCode.XML_INVALID,"Invalid service metada. Error: %s"), + METADATA_NOT_EXISTS(404,"SMP:141",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not found (part. id: '%s', part. sch.: '%s',doc. id: '%s', doc. sch.: '%s')!"), + SMD_NOT_EXISTS_FOR_DOMAIN(404,"SMP:142",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not found for domain (domain: %s, part. id: '%s', part. sch.: '%s')!"), + INVALID_SMD_XML (400,"SMP:143",ErrorBusinessCode.XSD_INVALID,"Invalid service metada. Error: %s"), // SML integration SML_INTEGRATION_EXCEPTION (500,"SMP:150",ErrorBusinessCode.TECHNICAL,"Could not create new DNS entry through SML! Error: %s "), diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java index d6388a39c9591f1c559579ca15d6ea8e18bd70f3..ca7ab211cc1589107fc82e0e5d231e20e724c801 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java @@ -102,7 +102,6 @@ public class ServiceGroupService { LOG.businessDebug(SMPMessageCode.BUS_SAVE_SERVICE_GROUP,domain,normalizedParticipantId.getValue(), normalizedParticipantId.getScheme() ); String newOwnerName = defineGroupOwner(serviceGroupOwner, authenticatedUser); - Optional<DBUser> newOwner = userDao.findUserByIdentifier(newOwnerName); if (!newOwner.isPresent()) { SMPRuntimeException ex = new SMPRuntimeException(USER_NOT_EXISTS); @@ -116,7 +115,7 @@ public class ServiceGroupService { normalizedParticipantId.getScheme()); - String extensions = ServiceGroupConverter.extractExtensionsPayload(serviceGroup); + byte[] extensions = ServiceGroupConverter.extractExtensionsPayload(serviceGroup); if (dbServiceGroup.isPresent()) { // service already exists. @@ -193,6 +192,19 @@ public class ServiceGroupService { } } + /** + * Method validates if user owner with identifier is owner of servicegroup + * @param ownerIdentifier + * @param dbsg + */ + @Transactional + public boolean isServiceGroupOwner(String ownerIdentifier, String serviceGroupIdentifier ){ + ParticipantIdentifierType pt = caseSensitivityNormalizer.normalizeParticipant(serviceGroupIdentifier); + Optional<DBServiceGroup> osg = serviceGroupDao.findServiceGroup(pt.getValue(), pt.getScheme()); + Optional<DBUser> own = userDao.findUserByIdentifier(ownerIdentifier); + return osg.isPresent() && own.isPresent() && osg.get().getUsers().contains(own.get()); + } + @Transactional public void deleteServiceGroup(ParticipantIdentifierType serviceGroupId) { diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataService.java index db9a0bf1f963957bda58d50b69d52a14635d87ff..28fd6146d532a915f1fbd2dbff63fbe40ec0a6f5 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataService.java @@ -87,7 +87,7 @@ public class ServiceMetadataService { * @return True if new ServiceMetadata was created. False if existing one was updated. */ @Transactional - public boolean saveServiceMetadata(String domain, ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId, String xmlContent) { + public boolean saveServiceMetadata(String domain, ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId, byte[] xmlContent) { ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId); DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(documentId); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverterTest.java index d2a3439eb90b8e76abb7d27c89b78474357f9793..fbdd752ea30debced7e0be6cc75f4d8b7178f9e8 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ExtensionConverterTest.java @@ -50,7 +50,7 @@ public class ExtensionConverterTest { String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "extensionMarshal.xml"); // when - String xmlResult = ExtensionConverter.marshalExtensions(list); + byte[] xmlResult = ExtensionConverter.marshalExtensions(list); // then assertThat(xmlResult, CompareMatcher.isIdenticalTo(inputDoc)); @@ -63,23 +63,23 @@ public class ExtensionConverterTest { String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "extensionMarshalMore.xml"); // when - String xmlResult = ExtensionConverter.marshalExtensions(list, true); + byte[] xmlResult = ExtensionConverter.marshalExtensions(list, true); // then - String wrappedXmlResult = String.format(WRAPPED_FORMAT, xmlResult); + String wrappedXmlResult = String.format(WRAPPED_FORMAT, new String(xmlResult, "UTF-8")); String wrappedInputDoc = String.format(WRAPPED_FORMAT, inputDoc); assertThat(wrappedXmlResult, CompareMatcher.isIdenticalTo(wrappedInputDoc)); } @Test - public void testUtf8Handling() throws JAXBException, XMLStreamException, UnsupportedEncodingException { + public void testUtf8Handling() throws JAXBException, XMLStreamException, IOException { // given ExtensionType extension = new ExtensionType(); extension.setExtensionName(UTF8_SEQUENCE); List<ExtensionType> extensions = Arrays.asList(extension); //when - String extensionsXml = ExtensionConverter.marshalExtensions(extensions); + byte[] extensionsXml = ExtensionConverter.marshalExtensions(extensions); List<ExtensionType> resultExtensions = ExtensionConverter.unmarshalExtensions(extensionsXml); //then @@ -89,7 +89,7 @@ public class ExtensionConverterTest { @Test public void testUnmarshal() throws IOException, JAXBException { // given - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "extensionMarshal.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "extensionMarshal.xml"); // when List<ExtensionType> extensions = ExtensionConverter.unmarshalExtensions(inputDoc); @@ -101,7 +101,7 @@ public class ExtensionConverterTest { @Test public void testUnmarshalTwoExtensions() throws IOException, JAXBException { // given - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "extensionMarshalMore.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "extensionMarshalMore.xml"); // when List<ExtensionType> extensions = ExtensionConverter.unmarshalExtensions(inputDoc); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverterTest.java index c3eb4b8d0b945c2b569d6d0c6eacf018abb1ec95..07ff814d351a5e1b45e3ad8da5466cb34a0e2500 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverterTest.java @@ -66,7 +66,7 @@ public class ServiceGroupConverterTest { public void toServiceGroupTestMultiExtensions() throws UnsupportedEncodingException, JAXBException, XMLStreamException { // set DBServiceGroup sg = TestDBUtils.createDBServiceGroup(); - sg.setExtension(TestDBUtils.generateExtension() + TestDBUtils.generateExtension()); + sg.setExtension(ExtensionConverter.concatByteArrays(TestDBUtils.generateExtension(), TestDBUtils.generateExtension())); //when-then ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg); @@ -88,7 +88,7 @@ public class ServiceGroupConverterTest { public void testInvalidExtension() { //given DBServiceGroup sg = TestDBUtils.createDBServiceGroup(); - sg.setExtension("<This > is invalid extensions"); + sg.setExtension("<This > is invalid extensions".getBytes()); expectedExeption.expect(SMPRuntimeException.class); expectedExeption.expectCause(Matchers.isA(UnmarshalException.class)); expectedExeption.expectMessage(Matchers.startsWith("Invalid extension for service group")); @@ -121,11 +121,11 @@ public class ServiceGroupConverterTest { ServiceGroup serviceGroup = ServiceGroupConverter.unmarshal(inputDoc); //when - String val = ServiceGroupConverter.extractExtensionsPayload(serviceGroup); + byte[] val = ServiceGroupConverter.extractExtensionsPayload(serviceGroup); //then assertNotNull(val); - assertEquals(expectedExt, val); + assertEquals(expectedExt, new String(val,"UTF-8")); } @Test diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverterTest.java index 184f7859848874d0033b545eaaeb1cd6b6472b4a..2edd221d99286ae328b84d90511920b0b4a3043e 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/ServiceMetadataConverterTest.java @@ -35,6 +35,7 @@ import javax.xml.bind.JAXBException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.IOException; +import java.util.Arrays; import static org.junit.Assert.*; @@ -53,7 +54,7 @@ public class ServiceMetadataConverterTest { @Test public void testUnmarshalServiceInformation() throws IOException, SAXException, ParserConfigurationException, JAXBException { //given - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "ServiceMetadataWithServiceInformation.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "ServiceMetadataWithServiceInformation.xml"); //when ServiceMetadata serviceMetadata = ServiceMetadataConverter.unmarshal(inputDoc); @@ -73,7 +74,7 @@ public class ServiceMetadataConverterTest { @Test public void testUnmarshalServiceInformationUtf8() throws IOException, SAXException, ParserConfigurationException, JAXBException { //given - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "ServiceMetadataWithServiceInformationUtf8.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "ServiceMetadataWithServiceInformationUtf8.xml"); //when ServiceMetadata serviceMetadata = ServiceMetadataConverter.unmarshal(inputDoc); @@ -87,7 +88,7 @@ public class ServiceMetadataConverterTest { @Test public void testUnmarshalRedirect() throws IOException, SAXException, ParserConfigurationException, JAXBException { //given - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "ServiceMetadataWithRedirect.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "ServiceMetadataWithRedirect.xml"); //when ServiceMetadata serviceMetadata = ServiceMetadataConverter.unmarshal(inputDoc); @@ -107,13 +108,13 @@ public class ServiceMetadataConverterTest { expectedExeption.expect(SMPRuntimeException.class); expectedExeption.expectMessage(Matchers.startsWith("Invalid service metada. Error")); //when - ServiceMetadataConverter.unmarshal("this is malformed XML body"); + ServiceMetadataConverter.unmarshal("this is malformed XML body".getBytes()); } @Test public void testUnmarshalMissingMandatoryFields() throws IOException, SAXException, ParserConfigurationException, JAXBException { //given - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "ServiceMetadataMissingMandatoryFields.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "ServiceMetadataMissingMandatoryFields.xml"); //when ServiceMetadata serviceMetadata = ServiceMetadataConverter.unmarshal(inputDoc); @@ -128,7 +129,7 @@ public class ServiceMetadataConverterTest { @Test public void testToSignedServiceMetadataDocument() throws IOException, SAXException, ParserConfigurationException, TransformerException { //given - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "ServiceMetadataWithServiceInformation.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "ServiceMetadataWithServiceInformation.xml"); //when Document signedServiceMetadataDoc = ServiceMetadataConverter.toSignedServiceMetadatadaDocument(inputDoc); @@ -140,8 +141,8 @@ public class ServiceMetadataConverterTest { NodeList children = root.getChildNodes(); assertEquals(1, children.getLength()); - String resultServiceMetadata = XmlTestUtils.marshal(children.item(0)); - assertEquals(inputDoc, resultServiceMetadata); + byte[] resultServiceMetadata = XmlTestUtils.marshallToByteArray(children.item(0)); + assertTrue(Arrays.equals(inputDoc, resultServiceMetadata)); } @Test @@ -150,7 +151,7 @@ public class ServiceMetadataConverterTest { expectedExeption.expect(SMPRuntimeException.class); expectedExeption.expectMessage(Matchers.startsWith("Invalid service metada. Error:")); //when - ServiceMetadataConverter.toSignedServiceMetadatadaDocument("this is malformed XML body"); + ServiceMetadataConverter.toSignedServiceMetadatadaDocument("this is malformed XML body".getBytes()); } @Test @@ -162,7 +163,7 @@ public class ServiceMetadataConverterTest { expectedExeption.expectCause(Matchers.isA(SAXParseException.class)); - String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "ServiceMetadataWithDOCTYPE.xml"); + byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "ServiceMetadataWithDOCTYPE.xml"); ServiceMetadataConverter.unmarshal(inputDoc); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoIntegrationTest.java index 28b87bdb604cebcc85090792c39625e01e8a229d..d10dc9696a9da7ecd8d2272a7055e0b1a48a3065 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoIntegrationTest.java @@ -9,6 +9,7 @@ import org.junit.runner.RunWith; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.transaction.Transactional; +import java.util.Arrays; import java.util.Optional; import java.util.UUID; @@ -57,7 +58,7 @@ public class ServiceGroupDaoIntegrationTest extends ServiceGroupDaoIntegrationBa DBDomain d = domainDao.getDomainByCode(TEST_DOMAIN_CODE_1).get(); DBServiceGroup sg = TestDBUtils.createDBServiceGroup(); - String extension = String.format(TestConstants.SIMPLE_EXTENSION_XML, UUID.randomUUID().toString()); + byte[] extension = String.format(TestConstants.SIMPLE_EXTENSION_XML, UUID.randomUUID().toString()).getBytes(); sg.setExtension(extension); sg.addDomain(d); @@ -70,14 +71,14 @@ public class ServiceGroupDaoIntegrationTest extends ServiceGroupDaoIntegrationBa assertEquals(sg, res); // test equal method - same entity assertEquals(sg.getParticipantIdentifier(), res.getParticipantIdentifier()); // test equal method - same entity assertEquals(sg.getParticipantScheme(), res.getParticipantScheme()); // test equal method - same entity - assertEquals(extension, res.getExtension()); // test loaded Domain + assertTrue(Arrays.equals(extension, res.getExtension())); // test loaded Domain } @Test public void updateServiceGroupExtension() { // given DBServiceGroup sg = createAndSaveNewServiceGroup(); - String extension1 = String.format(TestConstants.SIMPLE_EXTENSION_XML, UUID.randomUUID().toString()); + byte[] extension1 = String.format(TestConstants.SIMPLE_EXTENSION_XML, UUID.randomUUID().toString()).getBytes(); // when DBServiceGroup res = testInstance.findServiceGroup(sg.getParticipantIdentifier(), sg.getParticipantScheme()).get(); res.setExtension(extension1); @@ -89,7 +90,7 @@ public class ServiceGroupDaoIntegrationTest extends ServiceGroupDaoIntegrationBa assertEquals(res, res2); // test equal method - same entity assertEquals(res.getParticipantIdentifier(), res2.getParticipantIdentifier()); // test equal method - same entity assertEquals(res.getParticipantScheme(), res2.getParticipantScheme()); // test equal method - same entity - assertEquals(extension1, res2.getExtension()); // test loaded Domain + assertTrue(Arrays.equals(extension1, res2.getExtension())); // test loaded Domain } @Test diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoMetadataIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoMetadataIntegrationTest.java index 537668eb32302e8354d6bfb18cbe7e8f87344e47..efcac9f16095a87c6c698f5ec120f3c6492fe004 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoMetadataIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDaoMetadataIntegrationTest.java @@ -9,6 +9,7 @@ import org.junit.runner.RunWith; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.transaction.Transactional; +import java.util.Arrays; import java.util.Optional; import java.util.UUID; @@ -71,7 +72,7 @@ public class ServiceGroupDaoMetadataIntegrationTest extends ServiceGroupDaoInteg DBServiceGroup res2 = testInstance.findServiceGroup(sg.getParticipantIdentifier(), sg.getParticipantScheme()).get(); assertNotNull(res2); assertEquals(1, res2.getServiceGroupDomains().get(0).getServiceMetadata().size()); - assertEquals(md.getXmlContent(), res2.getServiceGroupDomains().get(0).getServiceMetadata().get(0).getXmlContent()); + assertTrue(Arrays.equals(md.getXmlContent(), res2.getServiceGroupDomains().get(0).getServiceMetadata().get(0).getXmlContent())); } @Test @@ -82,7 +83,7 @@ public class ServiceGroupDaoMetadataIntegrationTest extends ServiceGroupDaoInteg DBServiceGroup res = testInstance.findServiceGroup(sg.getParticipantIdentifier(), sg.getParticipantScheme()).get(); DBServiceMetadata md = res.getServiceGroupDomains().get(0).getServiceMetadata(0); - String str = TestDBUtils.generateDocumentSample(sg.getParticipantIdentifier(),sg.getParticipantScheme(), + byte[] str = TestDBUtils.generateDocumentSample(sg.getParticipantIdentifier(),sg.getParticipantScheme(), md.getDocumentIdentifier(),md.getDocumentIdentifierScheme(),UUID.randomUUID().toString()); assertNotEquals (str, md.getXmlContent()); //when @@ -94,7 +95,7 @@ public class ServiceGroupDaoMetadataIntegrationTest extends ServiceGroupDaoInteg DBServiceGroup res2 = testInstance.findServiceGroup(sg.getParticipantIdentifier(), sg.getParticipantScheme()).get(); assertNotNull(res2); assertEquals(1, res2.getServiceGroupDomains().get(0).getServiceMetadata().size()); - assertEquals(str, res2.getServiceGroupDomains().get(0).getServiceMetadata().get(0).getXmlContent()); + assertTrue(Arrays.equals(str, res2.getServiceGroupDomains().get(0).getServiceMetadata().get(0).getXmlContent())); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceMultipleDomainsIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceMultipleDomainsIntegrationTest.java index 3ba17f68d8df4d934ff16c06c412fe1f0548b418..58936bd2aad0f997c45db7b31271a956eb7e4b6d 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceMultipleDomainsIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceMultipleDomainsIntegrationTest.java @@ -35,6 +35,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.xml.bind.JAXBException; import javax.xml.stream.XMLStreamException; import java.io.IOException; +import java.util.Arrays; import java.util.Optional; import static eu.europa.ec.edelivery.smp.conversion.ServiceGroupConverter.unmarshal; @@ -107,8 +108,8 @@ public class ServiceGroupServiceMultipleDomainsIntegrationTest extends AbstractS ServiceGroup inServiceGroup = unmarshal(loadDocumentAsString(TestConstants.SERVICE_GROUP_TEST2_XML_PATH)); Optional<DBServiceGroup> dbsg = serviceGroupDao.findServiceGroup(TEST_SG_ID_2, TEST_SG_SCHEMA_2); assertTrue(dbsg.isPresent()); // test if exists - String extension = dbsg.get().getExtension(); // test if exists - String newExtension = ExtensionConverter.marshalExtensions(inServiceGroup.getExtensions()); + byte[] extension = dbsg.get().getExtension(); // test if exists + byte[] newExtension = ExtensionConverter.marshalExtensions(inServiceGroup.getExtensions()); assertNotEquals(extension, newExtension); // extension updated // when @@ -126,7 +127,7 @@ public class ServiceGroupServiceMultipleDomainsIntegrationTest extends AbstractS assertEquals(TEST_DOMAIN_CODE_1, dbServiceGroup.getServiceGroupDomains().get(0).getDomain().getDomainCode()); assertEquals(inServiceGroup.getParticipantIdentifier().getValue(), dbServiceGroup.getParticipantIdentifier()); assertEquals(inServiceGroup.getParticipantIdentifier().getScheme(), dbServiceGroup.getParticipantScheme()); - assertEquals(newExtension, dbServiceGroup.getExtension()); // extension updated + assertTrue(Arrays.equals(newExtension, dbServiceGroup.getExtension())); // extension updated } @Test diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceSingleDomainIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceSingleDomainIntegrationTest.java index 7c09124e6dc1589b77c6b56e44576080e5519c30..a0ed9b02e41367a3c494f5eb616aebd7d48646b4 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceSingleDomainIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceSingleDomainIntegrationTest.java @@ -32,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.xml.bind.JAXBException; import javax.xml.stream.XMLStreamException; import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -111,9 +112,9 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ DBDomain domain = domainDao.getTheOnlyDomain().get(); assertNotNull(domain); - String extension = dbsg.get().getExtension(); // test if exists - String newExtension = ExtensionConverter.marshalExtensions(inServiceGroup.getExtensions()); - assertNotEquals(extension, newExtension); // extension updated + byte[] extension = dbsg.get().getExtension(); // test if exists + byte[] newExtension = ExtensionConverter.marshalExtensions(inServiceGroup.getExtensions()); + assertFalse(Arrays.equals(extension, newExtension)); // extension updated // when boolean bCreated = testInstance.saveServiceGroup(inServiceGroup, domain.getDomainCode(), TestConstants.USERNAME_1, diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataIntegrationTest.java index 5ad0f7b551e9d2c1f93d1d5265f4e0ce277f8a25..b05922b30583bec6764a2cb85490e93a6bf71ea3 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataIntegrationTest.java @@ -55,13 +55,13 @@ import javax.persistence.PersistenceContext; import javax.xml.bind.JAXBException; import javax.xml.transform.TransformerException; import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.Optional; import static eu.europa.ec.edelivery.smp.conversion.ServiceMetadataConverter.unmarshal; import static eu.europa.ec.edelivery.smp.testutil.TestConstants.*; -import static eu.europa.ec.edelivery.smp.testutil.XmlTestUtils.loadDocumentAsString; -import static eu.europa.ec.edelivery.smp.testutil.XmlTestUtils.marshall; +import static eu.europa.ec.edelivery.smp.testutil.XmlTestUtils.*; import static eu.europa.ec.smp.api.Identifiers.asDocumentId; import static eu.europa.ec.smp.api.Identifiers.asParticipantId; import static org.junit.Assert.*; @@ -107,8 +107,8 @@ public class ServiceMetadataIntegrationTest extends AbstractServiceIntegrationTe //given - String inServiceMetadataXml = loadDocumentAsString(SERVICE_METADATA_XML_PATH); - String expectedSignedServiceMetadataXml = loadDocumentAsString(SIGNED_SERVICE_METADATA_XML_PATH); + byte[] inServiceMetadataXml = loadDocumentAsByteArray(SERVICE_METADATA_XML_PATH); + byte[] expectedSignedServiceMetadataXml = loadDocumentAsByteArray(SIGNED_SERVICE_METADATA_XML_PATH); List<DocumentIdentifier> docIdsBefore = testInstance.findServiceMetadataIdentifiers(PT_ID); assertEquals(0, docIdsBefore.size()); @@ -121,7 +121,7 @@ public class ServiceMetadataIntegrationTest extends AbstractServiceIntegrationTe assertEquals(1, docIdsAfter.size()); assertEquals(DOC_ID.getValue().toLowerCase(), docIdsAfter.get(0).getValue()); // normalized assertEquals(DOC_ID.getScheme().toLowerCase(), docIdsAfter.get(0).getScheme()); // normalized - assertEquals(expectedSignedServiceMetadataXml, ServiceMetadataConverter.toString(outServiceMetadataDoc)); + assertTrue(Arrays.equals(expectedSignedServiceMetadataXml, ServiceMetadataConverter.toByteArray(outServiceMetadataDoc) )); } @Test @@ -148,7 +148,7 @@ public class ServiceMetadataIntegrationTest extends AbstractServiceIntegrationTe @Test public void saveAndDeletePositiveScenario() throws IOException { //given - String inServiceMetadataXml = loadDocumentAsString(SERVICE_METADATA_XML_PATH); + byte[] inServiceMetadataXml = loadDocumentAsByteArray(SERVICE_METADATA_XML_PATH); testInstance.saveServiceMetadata(null, PT_ID, DOC_ID, inServiceMetadataXml); List<DocumentIdentifier> docIdsBefore = testInstance.findServiceMetadataIdentifiers(PT_ID); assertEquals(1, docIdsBefore.size()); @@ -174,13 +174,13 @@ public class ServiceMetadataIntegrationTest extends AbstractServiceIntegrationTe @Test public void updatePositiveScenario() throws IOException, JAXBException, TransformerException { //given - String oldServiceMetadataXml = loadDocumentAsString(SERVICE_METADATA_XML_PATH); + byte[] oldServiceMetadataXml = loadDocumentAsByteArray(SERVICE_METADATA_XML_PATH); testInstance.saveServiceMetadata(null, PT_ID, DOC_ID, oldServiceMetadataXml); - ServiceMetadata newServiceMetadata = unmarshal(loadDocumentAsString(SERVICE_METADATA_XML_PATH)); + ServiceMetadata newServiceMetadata = unmarshal(loadDocumentAsByteArray(SERVICE_METADATA_XML_PATH)); EndpointType endpoint = newServiceMetadata.getServiceInformation().getProcessList().getProcesses().get(0).getServiceEndpointList().getEndpoints().get(0); endpoint.setServiceDescription("New Description"); - String newServiceMetadataXml = marshall(newServiceMetadata); + byte[] newServiceMetadataXml = marshallToByteArray(newServiceMetadata); testInstance.saveServiceMetadata(null, PT_ID, DOC_ID, newServiceMetadataXml); //when @@ -193,14 +193,14 @@ public class ServiceMetadataIntegrationTest extends AbstractServiceIntegrationTe @Test public void findServiceMetadataIdsPositiveScenario() throws IOException, JAXBException, TransformerException { //given - String serviceMetadataXml1 = loadDocumentAsString(SERVICE_METADATA_XML_PATH); + byte[] serviceMetadataXml1 = loadDocumentAsByteArray(SERVICE_METADATA_XML_PATH); testInstance.saveServiceMetadata(null, PT_ID, DOC_ID, serviceMetadataXml1); String secondDocIdValue = "second-doc-id"; DocumentIdentifier secondDocId = new DocumentIdentifier(secondDocIdValue, DOC_ID.getScheme()); - ServiceMetadata serviceMetadata2 = unmarshal(loadDocumentAsString(SERVICE_METADATA_XML_PATH)); + ServiceMetadata serviceMetadata2 = unmarshal(loadDocumentAsByteArray(SERVICE_METADATA_XML_PATH)); serviceMetadata2.getServiceInformation().getDocumentIdentifier().setValue(secondDocIdValue); - String serviceMetadataXml2 = marshall(serviceMetadata2); + byte[] serviceMetadataXml2 = marshallToByteArray(serviceMetadata2); testInstance.saveServiceMetadata(null, PT_ID, secondDocId, serviceMetadataXml2); //when diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java index 7401b6cdca564509a70a0fd9b64f18b4514605e5..52788ec9024781790f286ea417c68e996b3807af 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java @@ -6,6 +6,7 @@ import eu.europa.ec.edelivery.smp.data.model.DBServiceGroupDomain; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; +import java.util.Arrays; import java.util.Optional; import static org.junit.Assert.assertEquals; @@ -39,13 +40,13 @@ public class DBAssertion { } @Transactional - public void assertServiceGroupExtensionEqual(String partId, String partSchema, String expectedExt){ - String ext = getExtensionForServiceGroup(partId, partSchema); - assertEquals(expectedExt,ext); + public void assertServiceGroupExtensionEqual(String partId, String partSchema, byte[] expectedExt){ + byte[] ext = getExtensionForServiceGroup(partId, partSchema); + assertTrue(Arrays.equals(expectedExt,ext)); } @Transactional - public String getExtensionForServiceGroup(String partId, String partSchema){ + public byte[] getExtensionForServiceGroup(String partId, String partSchema){ DBServiceGroup sg= serviceGroupDao.findServiceGroup(partId, partSchema).get(); return sg.getExtension(); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SignatureUtil.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SignatureUtil.java index ec64ae795ba7b11534602cf6a0faafd090cceb1c..45021d040565590ff56a46069cc08730947c53e9 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SignatureUtil.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SignatureUtil.java @@ -177,7 +177,6 @@ public class SignatureUtil { // Marshalling and parsing the document - signature validation fails without this stinky "magic". // _Probably_ SUN's implementation doesn't import correctly signatures between two different documents. String strUnwrapped = marshall(docUnwrapped); - System.out.println(strUnwrapped); return parseDocument(strUnwrapped); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/TestDBUtils.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/TestDBUtils.java index cac56e2c0d73cc1436f3fb95722fbf8629b6c175..357dbf742eeabc06788473ce22c00cc532604b67 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/TestDBUtils.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/TestDBUtils.java @@ -45,11 +45,11 @@ public class TestDBUtils { return grp; } - public static String generateDocumentSample(String partcId, String partcSch, String docId, String docSch, String desc){ - return String.format(SIMPLE_DOCUMENT_XML,partcSch, partcId,docSch, docId, desc); + public static byte[] generateDocumentSample(String partcId, String partcSch, String docId, String docSch, String desc){ + return String.format(SIMPLE_DOCUMENT_XML,partcSch, partcId,docSch, docId, desc).getBytes(); } - public static String generateExtension(){ - return String.format(SIMPLE_EXTENSION_XML, UUID.randomUUID().toString()); + public static byte[] generateExtension(){ + return String.format(SIMPLE_EXTENSION_XML, UUID.randomUUID().toString()).getBytes(); } public static DBServiceGroup createDBServiceGroup(String id, String sch) { diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/XmlTestUtils.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/XmlTestUtils.java index 7201c7729b24e831803854cee72eb5113e860086..2d7b120796118002be5ca94b5d5e493d264cdeee 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/XmlTestUtils.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/XmlTestUtils.java @@ -40,6 +40,11 @@ public class XmlTestUtils { private static final String UTF_8 = "UTF-8"; + public static byte[] loadDocumentAsByteArray(String docResourcePath) throws IOException { + InputStream inputStream = XmlTestUtils.class.getResourceAsStream(docResourcePath); + return IOUtils.toByteArray(inputStream); + } + public static String loadDocumentAsString(String docResourcePath) throws IOException { InputStream inputStream = XmlTestUtils.class.getResourceAsStream(docResourcePath); return IOUtils.toString(inputStream, UTF_8); @@ -63,6 +68,21 @@ public class XmlTestUtils { trans.transform(new DOMSource(doc), new StreamResult(stream)); return stream.toString(UTF_8); } + public static byte[] marshallToByteArray(Node doc) throws TransformerException, UnsupportedEncodingException { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer trans = tf.newTransformer(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + trans.transform(new DOMSource(doc), new StreamResult(stream)); + return stream.toByteArray(); + } + + public static byte[] marshallToByteArray(ServiceMetadata serviceMetadata) throws JAXBException { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + JAXBContext jaxbContext = JAXBContext.newInstance(ServiceMetadata.class); + Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); + jaxbMarshaller.marshal(serviceMetadata, stream); + return stream.toByteArray(); + } public static String marshall(ServiceMetadata serviceMetadata) throws JAXBException { StringWriter sw = new StringWriter(); diff --git a/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql b/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql new file mode 100644 index 0000000000000000000000000000000000000000..5b6e51ab8381af18f4c9b7d3e14c4563365f3137 --- /dev/null +++ b/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql @@ -0,0 +1,51 @@ +-- Copyright 2018 European Commission | CEF eDelivery +-- +-- Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"); +-- You may not use this work except in compliance with the Licence. +-- +-- You may obtain a copy of the Licence attached in file: LICENCE-EUPL-v1.2.pdf +-- +-- Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (1, 'peppol_user', '$2a$10$.pqNZZ4fRDdNbLhNlnEYg.1/d4yAGpLDgeXpJFI0sw7.WtyKphFzu', 'SMP_ADMIN', 1); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (2, 'the_admin', '', 'SMP_ADMIN', 1); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (3, 'AdminSMP1TEST', '$2a$06$u6Hym7Zrbsf4gEIeAsJRceK.Kg7tei3kDypwucQQdky0lXOLCkrCO', 'SMP_ADMIN', 1); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (4, 'AdminSMP2TEST', '$2a$10$h8Q3Kjbs6ZrGkU6ditjNueINlJOMDJ/g/OKiqFZy32WmdhLjV5TAi', 'SMP_ADMIN', 1); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (5, 'test', '', 'SMP_ADMIN', 1); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (6, 'test1', '$2a$06$toKXJgjqQINZdjQqSao3NeWz2n1S64PFPhVU1e8gIHh4xdbwzy1Uy', 'SMP_ADMIN', 1); + + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (10, 'EHEALTH_SMP_EC', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (10, 'CN=EHEALTH_SMP_EC,O=European Commission,C=BE:f71ee8b11cb3b787', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (11, 'EHEALTH_ż_ẞ_Ẅ_,O', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (11, 'CN=EHEALTH_ż_ẞ_Ẅ_,O=European_ż_ẞ_Ẅ_Commission,C=BE:f71ee8b11cb3b787', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (12, 'EHEALTH_SMP_1000000007', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (12, 'CN=EHEALTH_SMP_1000000007,O=DG-DIGIT,C=BE:000000000123ABCD', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (13, 'EHEALTH_SMP_EC1', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (13, 'CN=EHEALTH_SMP_EC/emailAddress\=CEF-EDELIVERY-SUPPORT@ec.europa.eu,O=European Commission,C=BE:f71ee8b11cb3b787', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (14, 'EHEALTH_SMP_1000000007', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (14, 'CN=EHEALTH_SMP_1000000007,O=DG-DIGIT,C=BE', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (15, 'EHEALTH&SMP_EC', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (15, 'CN=EHEALTH&SMP_EC,O=European&Commission,C=B&E:f71ee8b11cb3b787', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (16, 'EHEALTH_SMP_EC2', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (16, 'CN=EHEALTH_SMP_EC,O=European Commission,C=BE:000000000000100f', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (17, 'SMP_1000000007', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (17, 'CN=SMP_1000000007,O=DG-DIGIT,C=BE', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (18, 'SMP_1000000007', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (18, 'CN=SMP_1000000007,O=DG-DIGIT,C=BE:000000000123ABCD', null,null); + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (19, 'SMP_1000000181,O=DIGIT,C=DK:123456789', '$2a$10$v2d/2E99dWHBM2ipTIip1enyaRKBTi.Xj/Iz0K8g0gjHBWdKRsHaC', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (19, 'CN=SMP_1000000181,O=DIGIT,C=DK:123456789', null,null); + +-- insert domain +insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SIGNATURE_KEY_ALIAS) values (1, 'domain','subdomain','sig-key'); + diff --git a/smp-soapui-tests/pom.xml b/smp-soapui-tests/pom.xml index d0a5623e65d37b746a2c080a0643c54313184ee6..62e6f72947123305af906052b135673cbf0a402a 100644 --- a/smp-soapui-tests/pom.xml +++ b/smp-soapui-tests/pom.xml @@ -13,7 +13,7 @@ <description>Interation tests suit for SMP</description> <properties> - <url>http://localhost:8080/cipa-smp-full-webapp</url> + <url>http://localhost:8080/smp</url> </properties> <build> @@ -51,7 +51,9 @@ <testFailIgnore>true</testFailIgnore> <projectFile>${project.basedir}/soapui/SMP4.0-Generic-soapui-project.xml</projectFile> <testSuite>PASSING_AUTO_BAMBOO</testSuite> - <!--If you want to execute single test case <testCase>SMP001-Create ServiceGroup-Basic Flow-Admin Service Group specified</testCase>--> + <!--If you want to execute single test case <testCase>SMP001-Create ServiceGroup-Basic Flow-Admin Service Group specified</testCase>--> + <testCase>SMP078-Basic Flow-UTF-8 in Body</testCase> + <projectProperties> <value>url=${url}</value> </projectProperties> diff --git a/smp-soapui-tests/soapui/SMP4.0-Generic-soapui-project.xml b/smp-soapui-tests/soapui/SMP4.0-Generic-soapui-project.xml index 8a2754cdb73f2a791c69d4da49a6a7743f1c794c..2651b5533e4765395b83f0a79ef702bff89358bb 100644 --- a/smp-soapui-tests/soapui/SMP4.0-Generic-soapui-project.xml +++ b/smp-soapui-tests/soapui/SMP4.0-Generic-soapui-project.xml @@ -4140,7 +4140,7 @@ testRunner.testCase.testSteps['Delete ServiceGroup'].run(testRunner, context); <con:entry key="ParticipantIdentifierScheme" value="${Put ServiceGroup#ParticipantIdentifierScheme}"/> <con:entry key="ParticipantIdentifier" value="${Put ServiceGroup#ParticipantIdentifier}"/> </con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="TEST1 Get ServiceMetadata" id="53dc28c2-61ac-4f9c-82e9-0d0f5167348f"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="GET ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="TEST1 Get ServiceMetadata" mediaType="application/xml" id="798e6729-3cf8-44b5-8fc7-f19165c82521"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-notqns::0088:7770010100777/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="11e586ff-c74a-4e68-8db6-4bb76f2ce6b5" name="Valid HTTP Status Codes"><con:configuration><codes>404</codes></con:configuration></con:assertion><con:assertion type="Simple Contains" id="1fb97c35-e5e2-43a8-b2ef-872d7c82f070" name="Contains"><con:configuration><token><BusinessCode>NOT_FOUND</BusinessCode> -</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="ab7ce4b3-7b75-4ffa-84a4-1e0d5dc6ac16" name="Contains 2"><con:configuration><token>ServiceMetadata not found, ServiceGroupID</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="ParticipantIdentifierScheme" value="ehealth-actorid-notqns" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="TEST2 Get ServiceMetadata" id="6345da91-ae27-4596-810d-3b21ed003cc7"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="GET ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="TEST2 Get ServiceMetadata" mediaType="application/xml" id="798e6729-3cf8-44b5-8fc7-f19165c82521"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100778/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="9d8ac797-ee8e-4a0d-8de0-8525cc959d38" name="Valid HTTP Status Codes"><con:configuration><codes>404</codes></con:configuration></con:assertion><con:assertion type="Simple Contains" id="ab058fbd-e7b7-42bc-8c1b-77acbbbb8e78" name="Contains"><con:configuration><token><BusinessCode>NOT_FOUND</BusinessCode></token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="c5826191-f3ed-4f75-851d-27425aed964e"><con:configuration/></con:assertion><con:assertion type="Simple Contains" id="5439e706-ba6c-43f5-8275-d6fc9a5c3a2e" name="Contains 2"><con:configuration><token>ServiceMetadata not found, ServiceGroupID</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="ParticipantIdentifier" value="2:${Put ServiceGroup#ParticipantIdentifier}" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="TEST3 Get ServiceMetadata" id="7ee41886-f9b8-46d9-b05a-f320524d75ec"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="GET ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="TEST3 Get ServiceMetadata" mediaType="application/xml" id="798e6729-3cf8-44b5-8fc7-f19165c82521"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100777/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3ACredit-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="7c7a9439-7238-4e3a-926a-1640ebbc816a" name="Valid HTTP Status Codes"><con:configuration><codes>404</codes></con:configuration></con:assertion><con:assertion type="Simple Contains" id="6a2279a7-1eab-4d51-ae3d-2f4dc517ad1a" name="Contains"><con:configuration><token><BusinessCode>NOT_FOUND</BusinessCode></token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="c3fc33a2-006e-4e22-801f-2a88de66e338"><con:configuration/></con:assertion><con:assertion type="Simple Contains" id="6cf991ee-ba21-4809-a947-91c8d3f70d5a" name="Contains 2"><con:configuration><token>ServiceMetadata not found, ServiceGroupID</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="DocTypeIdentifierScheme" value="busdox-docid-qns2" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="TEST4 Get ServiceMetadata" id="9a110fcf-c5fa-4898-8ac7-f0a50b8fb976"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="GET ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="TEST4 Get ServiceMetadata" mediaType="application/xml" id="798e6729-3cf8-44b5-8fc7-f19165c82521"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100777/services/busnotdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="086ed54d-13c3-4894-9ee3-ba6f1efa9850" name="Valid HTTP Status Codes"><con:configuration><codes>404</codes></con:configuration></con:assertion><con:assertion type="Simple Contains" id="742b6828-e27c-4fcd-9d2e-2411ef59fd29" name="Contains"><con:configuration><token><BusinessCode>NOT_FOUND</BusinessCode></token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="f9496979-fbcc-46b7-bd75-e849aff153bb" name="Contains 2"><con:configuration><token>ServiceMetadata not found, ServiceGroupID</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="DocTypeIdentifier" value="urn:oasis:names:specification:ubl:schema:xsd:Invoice-001::Invoice##UBL-2.0" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="Delete ServiceMetadata" id="9c4809fa-622b-4d54-8741-9cf63c9dee6b" disabled="true"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="DELETE ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="Delete ServiceMetadata" mediaType="application/xml" id="cfe391c2-9084-45a5-a637-fbbc25a25f27" postQueryString="false"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns%3A%3A0088%3A7770010100777/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="455c1564-1956-4339-895f-e11e6d2fd416" name="Valid HTTP Status Codes"><con:configuration><codes>200</codes></con:configuration></con:assertion><con:credentials><con:username>AdminSMP1TEST</con:username><con:password>adminsmp1test</con:password><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters/></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="Delete ServiceGroup" id="1b09e015-a095-438c-ae63-eedcfc4785a0" disabled="true"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}" methodName="DELETE ServiceGroup" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="Delete ServiceGroup" mediaType="application/xml" id="a97cde56-8e9c-4d6f-b950-faf82b0268e9" postQueryString="false"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100777</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="995ce00d-f14d-4f50-9e8f-1639849557bd" name="Valid HTTP Status Codes"><con:configuration><codes>200</codes></con:configuration></con:assertion><con:credentials><con:username>AdminSMP1TEST</con:username><con:password>adminsmp1test</con:password><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters> +</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="ab7ce4b3-7b75-4ffa-84a4-1e0d5dc6ac16" name="Contains 2"><con:configuration><token>ServiceMetadata not found</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="ParticipantIdentifierScheme" value="ehealth-actorid-notqns" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="TEST2 Get ServiceMetadata" id="6345da91-ae27-4596-810d-3b21ed003cc7"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="GET ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="TEST2 Get ServiceMetadata" mediaType="application/xml" id="798e6729-3cf8-44b5-8fc7-f19165c82521"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100778/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="9d8ac797-ee8e-4a0d-8de0-8525cc959d38" name="Valid HTTP Status Codes"><con:configuration><codes>404</codes></con:configuration></con:assertion><con:assertion type="Simple Contains" id="ab058fbd-e7b7-42bc-8c1b-77acbbbb8e78" name="Contains"><con:configuration><token><BusinessCode>NOT_FOUND</BusinessCode></token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="5439e706-ba6c-43f5-8275-d6fc9a5c3a2e" name="Contains 2"><con:configuration><token>ServiceMetadata not found</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="ParticipantIdentifier" value="2:${Put ServiceGroup#ParticipantIdentifier}" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="TEST3 Get ServiceMetadata" id="7ee41886-f9b8-46d9-b05a-f320524d75ec"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="GET ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="TEST3 Get ServiceMetadata" mediaType="application/xml" id="798e6729-3cf8-44b5-8fc7-f19165c82521"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100777/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3ACredit-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="7c7a9439-7238-4e3a-926a-1640ebbc816a" name="Valid HTTP Status Codes"><con:configuration><codes>404</codes></con:configuration></con:assertion><con:assertion type="Simple Contains" id="6a2279a7-1eab-4d51-ae3d-2f4dc517ad1a" name="Contains"><con:configuration><token><BusinessCode>NOT_FOUND</BusinessCode></token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="6cf991ee-ba21-4809-a947-91c8d3f70d5a" name="Contains 2"><con:configuration><token>ServiceMetadata not found</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="DocTypeIdentifierScheme" value="busdox-docid-qns2" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="TEST4 Get ServiceMetadata" id="9a110fcf-c5fa-4898-8ac7-f0a50b8fb976"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="GET ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="TEST4 Get ServiceMetadata" mediaType="application/xml" id="798e6729-3cf8-44b5-8fc7-f19165c82521"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100777/services/busnotdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="086ed54d-13c3-4894-9ee3-ba6f1efa9850" name="Valid HTTP Status Codes"><con:configuration><codes>404</codes></con:configuration></con:assertion><con:assertion type="Simple Contains" id="742b6828-e27c-4fcd-9d2e-2411ef59fd29" name="Contains"><con:configuration><token><BusinessCode>NOT_FOUND</BusinessCode></token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:assertion type="Simple Contains" id="f9496979-fbcc-46b7-bd75-e849aff153bb" name="Contains 2"><con:configuration><token>ServiceMetadata not found</token><ignoreCase>false</ignoreCase><useRegEx>false</useRegEx></con:configuration></con:assertion><con:credentials><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><entry key="DocTypeIdentifier" value="urn:oasis:names:specification:ubl:schema:xsd:Invoice-001::Invoice##UBL-2.0" xmlns="http://eviware.com/soapui/config"/></con:parameters></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="Delete ServiceMetadata" id="9c4809fa-622b-4d54-8741-9cf63c9dee6b" disabled="true"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}/services/{DocTypeIdentifierScheme}::{DocTypeIdentifier}" methodName="DELETE ServiceMetadata" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="Delete ServiceMetadata" mediaType="application/xml" id="cfe391c2-9084-45a5-a637-fbbc25a25f27" postQueryString="false"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns%3A%3A0088%3A7770010100777/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-001%3A%3AInvoice%23%23UBL-2.0</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="455c1564-1956-4339-895f-e11e6d2fd416" name="Valid HTTP Status Codes"><con:configuration><codes>200</codes></con:configuration></con:assertion><con:credentials><con:username>AdminSMP1TEST</con:username><con:password>adminsmp1test</con:password><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters/></con:restRequest></con:config></con:testStep><con:testStep type="restrequest" name="Delete ServiceGroup" id="1b09e015-a095-438c-ae63-eedcfc4785a0" disabled="true"><con:settings/><con:config service="SMP" resourcePath="/{ParticipantIdentifierScheme}::{ParticipantIdentifier}" methodName="DELETE ServiceGroup" xsi:type="con:RestRequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:restRequest name="Delete ServiceGroup" mediaType="application/xml" id="a97cde56-8e9c-4d6f-b950-faf82b0268e9" postQueryString="false"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:endpoint>${#Project#url}</con:endpoint><con:request/><con:originalUri>http://wltdgt02.cc.cec.eu.int/cipa-smp-full-webapp/ehealth-actorid-qns::0088:7770010100777</con:originalUri><con:assertion type="Valid HTTP Status Codes" id="995ce00d-f14d-4f50-9e8f-1639849557bd" name="Valid HTTP Status Codes"><con:configuration><codes>200</codes></con:configuration></con:assertion><con:credentials><con:username>AdminSMP1TEST</con:username><con:password>adminsmp1test</con:password><con:selectedAuthProfile>Basic</con:selectedAuthProfile><con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes><con:preemptive>true</con:preemptive><con:authType>Preemptive</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters> <con:entry key="ParticipantIdentifierScheme" value="${Put ServiceGroup#ParticipantIdentifierScheme}"/> <con:entry key="ParticipantIdentifier" value="${Put ServiceGroup#ParticipantIdentifier}"/> </con:parameters></con:restRequest></con:config></con:testStep><con:tearDownScript>// Run clean test steps. diff --git a/smp-webapp/pom.xml b/smp-webapp/pom.xml index 5d345e119310b04516400f348b01f2f8300d4750..1071d7bee0c78f88b0a2c34b4c5dbf273dc3f6e7 100644 --- a/smp-webapp/pom.xml +++ b/smp-webapp/pom.xml @@ -98,7 +98,7 @@ <artifactId>hamcrest-junit</artifactId> <scope>test</scope> </dependency> - <dependency> + <!--dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> <version>RELEASE</version> @@ -109,7 +109,7 @@ <artifactId>spring-boot-autoconfigure</artifactId> <version>RELEASE</version> <scope>compile</scope> - </dependency> + </dependency--> </dependencies> <build> diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SMPAuthenticationProvider.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationProvider.java similarity index 67% rename from smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SMPAuthenticationProvider.java rename to smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationProvider.java index f752e546f37bf4b38e44853d0091dc2b1433327e..dda846c4a087882ef35a7ea525e4b55a85c805ac 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SMPAuthenticationProvider.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationProvider.java @@ -1,4 +1,4 @@ -package eu.europa.ec.edelivery.smp.config; +package eu.europa.ec.edelivery.smp.auth; import eu.europa.ec.edelivery.smp.data.dao.UserDao; import eu.europa.ec.edelivery.smp.data.model.DBUser; @@ -8,12 +8,10 @@ import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCrypt; import java.util.Collections; -import java.util.List; +import java.util.Optional; public class SMPAuthenticationProvider implements AuthenticationProvider { @@ -30,29 +28,22 @@ public class SMPAuthenticationProvider implements AuthenticationProvider { String username = auth.getName(); String password = auth.getCredentials().toString(); - DBUser usr = mUserDao.find(username); - System.out.println("GOT user " +username + " username " + usr ); - if (usr == null){ + Optional<DBUser> oUsr = mUserDao.findUserByIdentifier(username); + if (!oUsr.isPresent()){ //https://www.owasp.org/index.php/Authentication_Cheat_Sheet // Do not reveal the status of an existing account. Not to use UsernameNotFoundException throw new BadCredentialsException("Login failed; Invalid userID or password"); } - System.out.println("Check print"); - if (!BCrypt.checkpw(password, usr.getPassword())) { - throw new BadCredentialsException("Login failed; Invalid userID or password"); - } - System.out.println("get roles"); - List<GrantedAuthority> roles ; + DBUser usr = oUsr.get(); try { - roles = mUserDao.getUserRoles(username); - - }catch (Exception ex) { - ex.printStackTrace(System.out); - return null; + if (!BCrypt.checkpw(password, usr.getPassword())) { + throw new BadCredentialsException("Login failed; Invalid userID or password"); + } + }catch (java.lang.IllegalArgumentException ex){ + // password is not hashed + throw new BadCredentialsException("Login failed; Invalid userID or password"); } - - System.out.println("Got roles: " + roles.size() + " " + roles); - return new UsernamePasswordAuthenticationToken(username, password,roles); + return new UsernamePasswordAuthenticationToken(username, password,Collections.singletonList(new SMPAuthority(usr.getRole()))); } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthority.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthority.java new file mode 100644 index 0000000000000000000000000000000000000000..8a64b60ec1494819837b9714ffc1e57db810b340 --- /dev/null +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthority.java @@ -0,0 +1,24 @@ +package eu.europa.ec.edelivery.smp.auth; + +import org.springframework.security.core.GrantedAuthority; + + +public class SMPAuthority implements GrantedAuthority { + + // static constants for annotations! + public static final String S_AUTHORITY_SYSTEM_ADMIN = "ROLE_SYSTEM_ADMIN"; + public static final String S_AUTHORITY_SMP_ADMIN = "ROLE_SMP_ADMIN"; + public static final String S_AUTHORITY_SERVICE_GROUP_ADMIN = "ROLE_SERVICE_GROUP_ADMIN"; + + + String role; + + public SMPAuthority(String role) { + this.role = role; + } + + @Override + public String getAuthority() { + return "ROLE_"+role; + } +} diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPRole.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPRole.java new file mode 100644 index 0000000000000000000000000000000000000000..12d1d4e2725e91ee83a6b179c211074da3dadce6 --- /dev/null +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPRole.java @@ -0,0 +1,23 @@ +package eu.europa.ec.edelivery.smp.auth; + +public enum SMPRole { + + SMP_ADMIN("SMP_ADMIN"), + SERVICE_GROUP_ADMIN("SERVICE_GROUP_ADMIN"), + SYSTEM_ADMIN("SYSTEM_ADMIN"); + + + + + String code; + SMPRole(String code){ + this.code = code; + } + + public String getCode() { + return code; + } + + + +} diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java index 0a0e9b52afb702f81e791f0d75cae26b4df80ac5..0d114eabd3531bee70ea065e7bb982babfac0d3b 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java @@ -13,6 +13,7 @@ package eu.europa.ec.edelivery.smp.controllers; +import eu.europa.ec.edelivery.smp.auth.SMPAuthority; import eu.europa.ec.edelivery.smp.conversion.ServiceGroupConverter; import eu.europa.ec.edelivery.smp.services.ServiceGroupService; import eu.europa.ec.edelivery.smp.services.ServiceMetadataService; @@ -33,7 +34,6 @@ import org.springframework.security.access.annotation.Secured; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; -import java.io.UnsupportedEncodingException; import java.util.List; import static eu.europa.ec.smp.api.Identifiers.asParticipantId; @@ -77,14 +77,14 @@ public class ServiceGroupController { @PutMapping - @Secured("ROLE_SMP_ADMIN") + @Secured({SMPAuthority.S_AUTHORITY_SYSTEM_ADMIN, SMPAuthority.S_AUTHORITY_SMP_ADMIN}) public ResponseEntity saveServiceGroup( @PathVariable String serviceGroupId, @RequestHeader(name = "ServiceGroup-Owner", required = false) String serviceGroupOwner, @RequestHeader(name = "Domain", required = false) String domain, - @RequestBody String body) throws XmlInvalidAgainstSchemaException { + @RequestBody byte[] body) throws XmlInvalidAgainstSchemaException { - log.info("PUT ServiceGroup: {} domain {} owner {} \n{}", serviceGroupId,domain, serviceGroupOwner, body); + log.info("PUT ServiceGroup: {} domain {} owner {} \n{}", serviceGroupId,domain, serviceGroupOwner, new String(body)); // Validations BdxSmpOasisValidator.validateXSD(body); @@ -100,7 +100,7 @@ public class ServiceGroupController { } @DeleteMapping - @Secured("ROLE_SMP_ADMIN") + @Secured({SMPAuthority.S_AUTHORITY_SYSTEM_ADMIN, SMPAuthority.S_AUTHORITY_SMP_ADMIN}) public void deleteServiceGroup(@PathVariable String serviceGroupId) { log.info("DELETE ServiceGroup: {}", serviceGroupId); diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java index a126dc46604d31431088b4972ebb0b0646af7f79..be71c119140ef9736f890268380aa40321fd856e 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java @@ -14,6 +14,7 @@ package eu.europa.ec.edelivery.smp.controllers; import eu.europa.ec.edelivery.smp.conversion.ServiceMetadataConverter; +import eu.europa.ec.edelivery.smp.services.ServiceGroupService; import eu.europa.ec.edelivery.smp.services.ServiceMetadataService; import eu.europa.ec.edelivery.smp.validation.ServiceMetadataValidator; import eu.europa.ec.smp.api.exceptions.XmlInvalidAgainstSchemaException; @@ -48,6 +49,9 @@ public class ServiceMetadataController { @Autowired private ServiceMetadataService serviceMetadataService; + @Autowired + private ServiceGroupService serviceGroupService; + @Autowired private ServiceMetadataPathBuilder pathBuilder; @@ -64,14 +68,15 @@ public class ServiceMetadataController { } @PutMapping - @PreAuthorize("hasAnyAuthority('ROLE_SMP_ADMIN', @caseSensitivityNormalizer.normalizeParticipantId(#serviceGroupId))") + @PreAuthorize("hasAnyAuthority(T(eu.europa.ec.edelivery.smp.auth.SMPAuthority).S_AUTHORITY_SMP_ADMIN) OR" + + " @serviceGroupService.isServiceGroupOwner(authentication.name, #serviceGroupId)") public ResponseEntity saveServiceMetadata( @PathVariable String serviceGroupId, @PathVariable String serviceMetadataId, @RequestHeader(name = "Domain", required = false) String domain, - @RequestBody String body) throws XmlInvalidAgainstSchemaException { + @RequestBody byte[] body) throws XmlInvalidAgainstSchemaException { - log.info("PUT ServiceMetadata: {} - {}\n{}", serviceGroupId, serviceMetadataId, body); + log.info("PUT ServiceMetadata: {} - {}\n{}", serviceGroupId, serviceMetadataId, new String(body)); serviceMetadataValidator.validate(serviceGroupId, serviceMetadataId, body); @@ -83,7 +88,8 @@ public class ServiceMetadataController { } @DeleteMapping - @PreAuthorize("hasAnyAuthority('ROLE_SMP_ADMIN', @caseSensitivityNormalizer.normalizeParticipantId(#serviceGroupId))") + @PreAuthorize("hasAnyAuthority(T(eu.europa.ec.edelivery.smp.auth.SMPAuthority).S_AUTHORITY_SMP_ADMIN) OR" + + " @serviceGroupService.isServiceGroupOwner(authentication.name, #serviceGroupId)") public ResponseEntity deleteServiceMetadata(@PathVariable String serviceGroupId, @PathVariable String serviceMetadataId, @RequestHeader(name = "Domain", required = false) String domain ) { diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java index 910906ac673e5c00ab853832d6fc61f55a38b230..fceb733ba05f87f8ca6ef52d61247c07f5c18b2e 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java @@ -91,7 +91,7 @@ public class ErrorMappingControllerAdvice { @ExceptionHandler(XmlInvalidAgainstSchemaException.class) public ResponseEntity handleXmlInvalidAgainstSchemaException(XmlInvalidAgainstSchemaException ex) { - return buildAndWarn(BAD_REQUEST, XML_INVALID, ex.getMessage(), ex); + return buildAndWarn(BAD_REQUEST, XSD_INVALID, ex.getMessage(), ex); } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SpringSecurityExceptionHandler.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SpringSecurityExceptionHandler.java index 0629acafca543b7d0efa760566bbb4d8c66d50bb..7d8418e8c0acfb5220e87b22028bb3e2cadd2fb3 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SpringSecurityExceptionHandler.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SpringSecurityExceptionHandler.java @@ -54,7 +54,7 @@ public class SpringSecurityExceptionHandler extends BasicAuthenticationEntryPoin AuthenticationException authException) throws IOException, ServletException { String errorMsg = authException.getMessage(); if(authException instanceof BadCredentialsException){ - errorMsg += " - Provided username/password or client certificate is invalid"; + errorMsg += " - Provided username/password or client certificate are invalid"; } handle(response, authException, errorMsg); } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/validation/ServiceMetadataValidator.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/validation/ServiceMetadataValidator.java index 20216417ad8a1b830511bd346e0b483feedee0a2..219fe59222c6bf49daa338f1edfe543fd919d862 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/validation/ServiceMetadataValidator.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/validation/ServiceMetadataValidator.java @@ -40,7 +40,7 @@ public class ServiceMetadataValidator { public void validate(String serviceGroupIdStr, String serviceMetadataIdStr, - String serviceMetadataBody + byte[] serviceMetadataBody ) throws XmlInvalidAgainstSchemaException { BdxSmpOasisValidator.validateXSD(serviceMetadataBody); diff --git a/smp-webapp/src/main/resources/spring-security.xml b/smp-webapp/src/main/resources/spring-security.xml index 96a632bd28c3c35b485836d228a014a758acc11c..9060d3bf630a58bae71181c42060de6d8d95d967 100644 --- a/smp-webapp/src/main/resources/spring-security.xml +++ b/smp-webapp/src/main/resources/spring-security.xml @@ -36,18 +36,24 @@ <authentication-manager alias="smpAuthenticationManager"> - <authentication-provider> + <!-- authentication-provider> <password-encoder hash="bcrypt"/> <jdbc-user-service id="smpJdbcUserDetailsService" data-source-ref="dataSource" - users-by-username-query="SELECT USERNAME, COALESCE(PASSWORD, 'dummy'), ACTIVE FROM SMP_USER WHERE USERNAME = ?" - authorities-by-username-query="SELECT all_roles.USERNAME, all_roles.authority from ( SELECT USERNAME, 'ROLE_SERVICEGROUP_ADMIN' AS AUTHORITY FROM SMP_USER UNION ALL SELECT USERNAME, 'ROLE_SMP_ADMIN' AS AUTHORITY FROM SMP_USER WHERE ROLE = 'ROLE_SMP_ADMIN') all_roles WHERE USERNAME = ?"/> - </authentication-provider> - + users-by-username-query="SELECT username, COALESCE(PASSWORD, 'dummy'), ACTIVE FROM SMP_USER WHERE USERNAME = ?" + authorities-by-username-query="select username, ROLE FROM SMP_USER where USERNAME = ?"/> + </authentication-provider --> + <authentication-provider ref="smpAuthProvider"/> <authentication-provider ref="preauthAuthProvider"/> </authentication-manager> + <!-- user detail service is used only in preAhtProviders for cert authentication that is why search is only on cert table--> + <jdbc-user-service id="smpJdbcUserDetailsService" + data-source-ref="dataSource" + users-by-username-query="SELECT c.CERTIFICATE_ID AS USERNAME, 'dummy' AS PASWORD, u.ACTIVE FROM SMP_CERTIFICATE c INNER JOIN SMP_USER u ON (u.id = c.id) WHERE c.CERTIFICATE_ID = ?" + authorities-by-username-query="SELECT c.CERTIFICATE_ID AS USERNAME, u.ROLE FROM SMP_CERTIFICATE c INNER JOIN SMP_USER u ON (u.id = c.id) WHERE c.CERTIFICATE_ID = ?"/> + <b:bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider"> <b:property name="preAuthenticatedUserDetailsService"> @@ -75,4 +81,9 @@ <b:property name="allowUrlEncodedSlash" value="${encodedSlashesAllowedInUrl}"/> </b:bean> + <b:bean id="smpAuthProvider" class="eu.europa.ec.edelivery.smp.auth.SMPAuthenticationProvider"> + </b:bean> + + + </b:beans> diff --git a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-4.1.0-SNAPSHOT.ddl b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-4.1.0-SNAPSHOT.ddl index c7d9c708c2407ffda4f8298f5abd954e015f1705..28362d52dfdeb05ef726a4dd23850cba850d49d9 100644 --- a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-4.1.0-SNAPSHOT.ddl +++ b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-4.1.0-SNAPSHOT.ddl @@ -149,7 +149,7 @@ create table SMP_SERVICE_METADATA_XML ( ID bigint not null, - XML_CONTENT longtext, + XML_CONTENT longblob, primary key (ID) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -157,13 +157,13 @@ ID bigint not null, REV bigint not null, REVTYPE tinyint, - XML_CONTENT longtext, + XML_CONTENT longblob, primary key (ID, REV) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; create table SMP_SG_EXTENSION ( ID bigint not null, - EXTENSION longtext, + EXTENSION longblob, primary key (ID) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -171,7 +171,7 @@ ID bigint not null, REV bigint not null, REVTYPE tinyint, - EXTENSION longtext, + EXTENSION longblob, primary key (ID, REV) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/smp-webapp/src/main/smp-setup/database-scripts/oracle10g-4.1.0-SNAPSHOT.ddl b/smp-webapp/src/main/smp-setup/database-scripts/oracle10g-4.1.0-SNAPSHOT.ddl index a75783766d3cb63ab220e3c030f856b5ce6fdadd..d4839da83dbd6cf4b73eca67c68521a9f21e7bb7 100644 --- a/smp-webapp/src/main/smp-setup/database-scripts/oracle10g-4.1.0-SNAPSHOT.ddl +++ b/smp-webapp/src/main/smp-setup/database-scripts/oracle10g-4.1.0-SNAPSHOT.ddl @@ -125,7 +125,7 @@ create sequence SMP_USER_SEQ start with 1 increment by 50; create table SMP_SERVICE_METADATA_XML ( ID number(19,0) not null, - XML_CONTENT clob, + XML_CONTENT blob, primary key (ID) ); @@ -133,13 +133,13 @@ create sequence SMP_USER_SEQ start with 1 increment by 50; ID number(19,0) not null, REV number(19,0) not null, REVTYPE number(3,0), - XML_CONTENT clob, + XML_CONTENT blob, primary key (ID, REV) ); create table SMP_SG_EXTENSION ( ID number(19,0) not null, - EXTENSION clob, + EXTENSION blob, primary key (ID) ); @@ -147,7 +147,7 @@ create sequence SMP_USER_SEQ start with 1 increment by 50; ID number(19,0) not null, REV number(19,0) not null, REVTYPE number(3,0), - EXTENSION clob, + EXTENSION blob, primary key (ID, REV) ); diff --git a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationTest.java b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationTest.java index 4c095ba54b5c28c24f44ae5cc7df52c6640af1f6..866b17ef55b4c05e76f5185ea33f02db8d7ef3b7 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationTest.java @@ -55,18 +55,11 @@ public class SecurityConfigurationTest { public static final String TEST_USERNAME_CLEAR_PASS = "test_user_clear_pass"; public static final String TEST_USERNAME_HASHED_PASS = "test_user_hashed_pass"; - public static final String PASSWORD = "gutek123"; + public static final String PASSWORD = "test123"; public static final String BLUE_COAT_VALID_HEADER = "sno=66&subject=C=BE,O=org,CN=comon name&validfrom=Dec 6 17:41:42 2016 GMT&validto=Jul 9 23:59:00 2050 GMT&issuer=C=x,O=y,CN=z"; public static final String TEST_USERNAME_BLUE_COAT = "CN=comon name,O=org,C=BE:0000000000000066"; - //both passwords represent the same value - clear and hashed - /* - private DBUser userHashedPass = createUser(TEST_USERNAME_HASHED_PASS, "$2a$06$k.Q/6anG4Eq/nNTZ0C1UIuAKxpr6ra5oaMkMSrlESIyA5jKEsUdyS"); - private DBUser userClearPass = createUser(TEST_USERNAME_CLEAR_PASS, PASSWORD); - private DBUser userBlueCoat = createUser(TEST_USERNAME_BLUE_COAT, null); - */ - @Autowired private WebApplicationContext context; diff --git a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureUtil.java b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureUtil.java index 5abf7ac88e0b6537ea15366df7800aa729833cb2..f5a91eba19eb28a223db6da31e4f17eff678f20e 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureUtil.java +++ b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureUtil.java @@ -122,7 +122,6 @@ public class SignatureUtil { InputStream is = ((Reference) i.next()).getDigestInputStream(); // Display the data. byte[] a = IOUtils.readFully(is, 0, true); - System.out.println(new String(a)); } // Check core validation status. diff --git a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureValidatorTest.java b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureValidatorTest.java index 01038950f7900b2aa11cac27b2f98ae8a6fe303a..1d5c4a2e34e5b06a86f985840214a00d3b4c3c3e 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureValidatorTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SignatureValidatorTest.java @@ -74,11 +74,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @Transactional @Rollback(true) @Sql("classpath:/webapp_integration_test_data.sql") -public class SignatureValidatorTest/* extends AbstractTest*/ { +public class SignatureValidatorTest { private static final String C14N_METHOD = CanonicalizationMethod.INCLUSIVE; private static final String PARSER_DISALLOW_DTD_PARSING_FEATURE = "http://apache.org/xml/features/disallow-doctype-decl"; - private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("test_admin", "gutek123"); + private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("test_admin", "test123"); @Autowired private WebApplicationContext webAppContext; diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java index b2739cc4c22f6dbb499975f49249d46c2c9cc10a..b94a7f311790d0b8739e757d08775db6e54939de 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java @@ -73,7 +73,7 @@ public class ServiceGroupControllerTest { private static final String OTHER_OWNER_NAME_URL_ENCODED = "CN=utf-8_%C5%BC_SMP,O=EC,C=BE:0000000000000666"; - private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("test_admin", "gutek123"); + private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("test_admin", "test123"); @Autowired private WebApplicationContext webAppContext; @@ -227,7 +227,7 @@ public class ServiceGroupControllerTest { .contentType(APPLICATION_XML_VALUE) .header(HTTP_HEADER_KEY_SERVICE_GROUP_OWNER, "not-existing-user") .content(SERVICE_GROUP_INPUT_BODY)) - .andExpect(status().isNotFound()); + .andExpect(status().isBadRequest()); } } diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdviceTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdviceTest.java index f95bace1aa4e6faacae10b6ef7334c1620e26a28..2e5278c0f37b178b0669f5944bbe5d8f34cd540b 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdviceTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdviceTest.java @@ -74,6 +74,6 @@ public class ErrorMappingControllerAdviceTest { new XmlInvalidAgainstSchemaException("XmlInvalidAgainstSchemaExceptionMessage", null)); assertEquals(BAD_REQUEST, re.getStatusCode()); - assertEquals(ErrorBusinessCode.XML_INVALID.toString(), ((ErrorResponse)re.getBody()).getBusinessCode()); + assertEquals(ErrorBusinessCode.XSD_INVALID.toString(), ((ErrorResponse)re.getBody()).getBusinessCode()); } } \ No newline at end of file diff --git a/smp-webapp/src/test/resources/webapp_integration_test_data.sql b/smp-webapp/src/test/resources/webapp_integration_test_data.sql index 82f0744dcb3506167986b2b7267f684d6a937db8..49116f27db7d28c992ea7d5075dfaf4d47adab29 100644 --- a/smp-webapp/src/test/resources/webapp_integration_test_data.sql +++ b/smp-webapp/src/test/resources/webapp_integration_test_data.sql @@ -8,12 +8,18 @@ -- Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (1, 'test_admin', '$2a$06$k.Q/6anG4Eq/nNTZ0C1UIuAKxpr6ra5oaMkMSrlESIyA5jKEsUdyS', 'ROLE_SMP_ADMIN', 1); -insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (2, 'test_user_hashed_pass', '$2a$06$k.Q/6anG4Eq/nNTZ0C1UIuAKxpr6ra5oaMkMSrlESIyA5jKEsUdyS', 'ROLE_SMP_ADMIN',1); -insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (3, 'test_user_clear_pass', 'gutek123', 'ROLE_SMP_ADMIN',1); -insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (4, 'CN=comon name,O=org,C=BE:0000000000000066', '', 'ROLE_SMP_ADMIN', 1); -insert into SMP_USER(ID, USERNAME, ROLE, ACTIVE) values (5, 'CN=EHEALTH_SMP_TEST_BRAZIL,O=European Commission,C=BE:48b681ee8e0dcc08', 'ROLE_SMP_ADMIN', 1); -insert into SMP_USER(ID, USERNAME, ROLE, ACTIVE) values (6, 'CN=utf-8_ż_SMP,O=EC,C=BE:0000000000000666', 'ROLE_SMP_ADMIN', 1); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (1, 'test_admin', '$2a$06$AXSSUDJlpzzq/gPZb7eIBeb8Mi0.PTKqDjzujZH.bWPwj5.ePEInW', 'SMP_ADMIN', 1); +insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (2, 'test_user_hashed_pass', '$2a$06$AXSSUDJlpzzq/gPZb7eIBeb8Mi0.PTKqDjzujZH.bWPwj5.ePEInW', 'SMP_ADMIN',1); +insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (3, 'test_user_clear_pass', 'test123', 'SMP_ADMIN',1); +insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE) values (4, 'cert1', '', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (4, 'CN=comon name,O=org,C=BE:0000000000000066', null,null); + +insert into SMP_USER(ID, USERNAME, ROLE, ACTIVE) values (5, 'cert2', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (5, 'CN=EHEALTH_SMP_TEST_BRAZIL,O=European Commission,C=BE:48b681ee8e0dcc08', null,null); + +insert into SMP_USER(ID, USERNAME, ROLE, ACTIVE) values (6, 'Cert2', 'SMP_ADMIN', 1); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO) values (6, 'CN=utf-8_ż_SMP,O=EC,C=BE:0000000000000666', null,null); + insert into SMP_SERVICE_GROUP(ID, PARTICIPANT_IDENTIFIER, PARTICIPANT_SCHEME,SML_REGISTRED) values (1, 'urn:australia:ncpb', 'ehealth-actorid-qns', 1); insert into SMP_SERVICE_GROUP(ID, PARTICIPANT_IDENTIFIER, PARTICIPANT_SCHEME,SML_REGISTRED) values (2, 'urn:brazil:ncpb', 'ehealth-actorid-qns', 1);