From a9080fd1ff50715d1c13e2029746d3f8eb8f1f5f Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Mon, 18 Oct 2021 14:04:58 +0200 Subject: [PATCH 01/22] update ci --- .gitlab-ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9d121502..8c5097c0c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,8 +7,10 @@ build: build2: script: mvn clean initialize && mvn -Dspring.config.location=/opt/tomcat-esup-signature/conf/app_config/application.yml clean package && cp -rf target/esup-signature.war /opt/tomcat-esup-signature/webapps/ROOT.war - only: - - tags - tags: - - prod + rules: + - if: $CI_COMMIT_REF_NAME != "prod" && $CI_COMMIT_TAG != "" + when: on_success + - when: never + tags: + - prod \ No newline at end of file From aa289d7a6c1935c436020acf653c17056fea7563 Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Mon, 18 Oct 2021 14:08:01 +0200 Subject: [PATCH 02/22] update ci --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c5097c0c..fc8f269d8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ build: build2: script: mvn clean initialize && mvn -Dspring.config.location=/opt/tomcat-esup-signature/conf/app_config/application.yml clean package && cp -rf target/esup-signature.war /opt/tomcat-esup-signature/webapps/ROOT.war rules: - - if: $CI_COMMIT_REF_NAME != "prod" && $CI_COMMIT_TAG != "" + - if: $CI_COMMIT_REF_NAME == "prod" && $CI_COMMIT_TAG != "" when: on_success - when: never From 7824d7cbca1a9ff523eeb841dcebb2924acba3df Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Mon, 18 Oct 2021 14:29:00 +0200 Subject: [PATCH 03/22] 1.15.1-SNAPSHOT --- .gitlab-ci.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc8f269d8..0b8bfdb6b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ build: build2: script: mvn clean initialize && mvn -Dspring.config.location=/opt/tomcat-esup-signature/conf/app_config/application.yml clean package && cp -rf target/esup-signature.war /opt/tomcat-esup-signature/webapps/ROOT.war rules: - - if: $CI_COMMIT_REF_NAME == "prod" && $CI_COMMIT_TAG != "" + - if: $CI_COMMIT_REF_NAME == "prod" && $CI_COMMIT_TAG != null when: on_success - when: never diff --git a/pom.xml b/pom.xml index 0e92aedc4..65bf054f1 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.esupportail esup-signature - 1.15 + 1.15.1-SNAPSHOT esup-signature org.esupportail.esupsignature.EsupSignatureApplication From 87072bf04c7554ee2dcfe66b055061b7de1318fa Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 8 Oct 2021 17:58:14 +0200 Subject: [PATCH 04/22] web service : handle non-rest target urls protocol --- .../esupsignature/service/DataService.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/esupportail/esupsignature/service/DataService.java b/src/main/java/org/esupportail/esupsignature/service/DataService.java index 51650ca9c..15a14254c 100644 --- a/src/main/java/org/esupportail/esupsignature/service/DataService.java +++ b/src/main/java/org/esupportail/esupsignature/service/DataService.java @@ -91,6 +91,23 @@ public void deleteOnlyData(Long id) { dataRepository.delete(data); } + private DocumentIOType getPathIOType(String path) throws EsupSignatureException { + try { + var uri = new java.net.URI(path); + switch (uri.getScheme()) { + case "smb": return DocumentIOType.smb; + case "cmis": return DocumentIOType.cmis; + case "sftp": return DocumentIOType.vfs; + + case "http": + case "https": return DocumentIOType.rest; + } + throw new EsupSignatureException("unknown protocol for url " + path); + } catch (java.net.URISyntaxException e) { + throw new EsupSignatureException("target Url error", e); + } + } + @Transactional public SignBook sendForSign(Long dataId, List recipientsEmails, List allSignToCompletes, List externalUsersInfos, List targetEmails, String targetUrl, String userEppn, String authUserEppn, boolean forceSendEmail) throws EsupSignatureException, EsupSignatureIOException { User user = userService.getUserByEppn(userEppn); @@ -120,7 +137,7 @@ public SignBook sendForSign(Long dataId, List recipientsEmails, List Date: Fri, 8 Oct 2021 17:55:43 +0200 Subject: [PATCH 05/22] merger prigaux 69a6272 --- .../esupportail/esupsignature/service/DataService.java | 8 +++++--- .../esupsignature/web/ws/FormWsController.java | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/esupportail/esupsignature/service/DataService.java b/src/main/java/org/esupportail/esupsignature/service/DataService.java index 15a14254c..6fb799f44 100644 --- a/src/main/java/org/esupportail/esupsignature/service/DataService.java +++ b/src/main/java/org/esupportail/esupsignature/service/DataService.java @@ -109,7 +109,7 @@ private DocumentIOType getPathIOType(String path) throws EsupSignatureException } @Transactional - public SignBook sendForSign(Long dataId, List recipientsEmails, List allSignToCompletes, List externalUsersInfos, List targetEmails, String targetUrl, String userEppn, String authUserEppn, boolean forceSendEmail) throws EsupSignatureException, EsupSignatureIOException { + public SignBook sendForSign(Long dataId, List recipientsEmails, List allSignToCompletes, List externalUsersInfos, List targetEmails, List targetUrls, String userEppn, String authUserEppn, boolean forceSendEmail) throws EsupSignatureException, EsupSignatureIOException { User user = userService.getUserByEppn(userEppn); User authUser = userService.getUserByEppn(authUserEppn); Data data = getById(dataId); @@ -136,8 +136,10 @@ public SignBook sendForSign(Long dataId, List recipientsEmails, List recipientEmails, @RequestParam(required = false) @Parameter(description = "Lites des numéros d'étape pour lesquelles tous les participants doivent signer", example = "[stepNumber]") List allSignToCompletes, @RequestParam(required = false) @Parameter(description = "Liste des destinataires finaux", example = "[email]") List targetEmails, - @RequestParam(required = false) @Parameter(description = "Emplacement final", example = "smb://drive.univ-ville.fr/forms-archive/") String targetUrl + @RequestParam(required = false) @Parameter(description = "Emplacements finaux", example = "[smb://drive.univ-ville.fr/forms-archive/]") List targetUrls ) { Data data = dataService.addData(id, eppn, eppn); try { - SignBook signBook = dataService.sendForSign(data.getId(), recipientEmails, allSignToCompletes, null, targetEmails, targetUrl, eppn, eppn, true); + SignBook signBook = dataService.sendForSign(data.getId(), recipientEmails, allSignToCompletes, null, targetEmails, targetUrls, eppn, eppn, true); return signBook.getSignRequests().get(0).getId(); } catch (EsupSignatureException | EsupSignatureIOException e) { return -1L; From 68062c0a9e2d0cc03fab5321ef7aaa50708b3e12 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 8 Oct 2021 18:00:49 +0200 Subject: [PATCH 06/22] WIP handle vfs urls not referenced in application.yml ie do not keep connection opened TODO: correctly handle may_close in case of exceptions --- .../interfaces/fs/vfs/VfsAccessImpl.java | 91 ++++++++++++------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java index 03c758cca..6ddc7260f 100644 --- a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java +++ b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java @@ -64,35 +64,40 @@ public void setFtpPassiveMode(boolean ftpPassiveMode) { this.ftpPassiveMode = ftpPassiveMode; } - @Override - public void open() { - super.open(); - try { - if(!isOpened()) { - FileSystemOptions fsOptions = new FileSystemOptions(); - - if ( ftpControlEncoding != null ) - FtpFileSystemConfigBuilder.getInstance().setControlEncoding(fsOptions, ftpControlEncoding); - - if(sftpSetUserDirIsRoot) { - SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, true); - FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, true); - } else { - SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, false); - FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, false); - } - - if(!strictHostKeyChecking) { - SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fsOptions, "no"); - } - - FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fsOptions, ftpPassiveMode); - - fsManager = VFS.getManager(); - root = fsManager.resolveFile(uri, fsOptions); - } - } catch(FileSystemException e) { - logger.error("unable to open vfs", e); + private FileObject open(String uri) { + try { + FileSystemOptions fsOptions = new FileSystemOptions(); + + if ( ftpControlEncoding != null ) + FtpFileSystemConfigBuilder.getInstance().setControlEncoding(fsOptions, ftpControlEncoding); + + if(sftpSetUserDirIsRoot) { + SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, true); + FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, true); + } else { + SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, false); + FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, false); + } + + if(!strictHostKeyChecking) { + SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fsOptions, "no"); + } + + FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fsOptions, ftpPassiveMode); + + fsManager = VFS.getManager(); + return fsManager.resolveFile(uri, fsOptions); + } catch(FileSystemException e) { + logger.error("unable to open vfs", e); + return null; + } + } + + @Override + public void open() { + super.open(); + if(!isOpened()) { + root = open(uri); } } @@ -106,6 +111,20 @@ public void close() { } } + private boolean use_stateful_filesystem(String uri) { + return !uri.startsWith("sftp://"); + } + + private void may_close(String uri, FileObject o) { + if (!use_stateful_filesystem(uri)) { + try { + VFS.getManager().closeFileSystem(o.getFileSystem()); + } catch (FileSystemException e) { + logger.error("unable to close vfs", e); + } + } + } + public void destroy() throws Exception { this.close(); } @@ -121,12 +140,14 @@ public FileObject cd(String path) { this.open(); if (path == null || path.length() == 0) { returnValue = root; + } else if (use_stateful_filesystem(path)) { + returnValue = root.resolveFile("/" + path); } else { - returnValue = root.resolveFile(getUri() + "/" + path); + returnValue = open(path); } returnValue.refresh(); } catch(FileSystemException e) { - logger.error("unable to open directory"); + logger.error("unable to open directory", e); } return returnValue; } @@ -150,6 +171,8 @@ public List listFiles(String url) throws EsupSignatureFsException { } catch (IOException e) { throw new EsupSignatureFsException(e); + } finally { + may_close(url, resource); } return fsFiles; } @@ -184,6 +207,7 @@ public String createFile(String parentPath, String title, String type) { } else { logger.info("file " + title + " already exists !"); } + may_close(parentPath, parent); } catch (FileSystemException e) { logger.info("can't create file because of FileSystemException : " + e.getMessage(), e); @@ -207,6 +231,7 @@ public boolean renameFile(String path, String title) throws EsupSignatureFsExcep } else { logger.info("file " + title + " already exists !"); } + may_close(path, file); } catch (FileSystemException e) { logger.info("can't rename file because of FileSystemException : " + e.getMessage(), e); @@ -229,6 +254,7 @@ public boolean moveCopyFilesIntoDirectory(String dir, List filesToCopy, } } + may_close(dir, folder); return true; } catch (FileSystemException e) { logger.warn("can't move/copy file because of FileSystemException : " @@ -240,6 +266,7 @@ public boolean moveCopyFilesIntoDirectory(String dir, List filesToCopy, @Override public FsFile getFile(String dir) { try { + if (!use_stateful_filesystem(dir)) throw new RuntimeException("TODO"); FileObject fileObject = cd(dir); return toFsFile(fileObject); } catch (IOException e) { @@ -287,6 +314,8 @@ public boolean putFile(String dir, String filename, InputStream inputStream, Upl FileCopyUtils.copy(inputStream, outstr); + may_close(dir, folder); + success = true; } catch (FileSystemException e) { logger.info("can't upload file : " + e.getMessage(), e); From ad06e2f5fa6f4d9a3917d6e8477ecf9cf755c39c Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 8 Oct 2021 18:01:45 +0200 Subject: [PATCH 07/22] TODO getFileFromURI/getFile hard to implement with non-stateful VfsAccessImpl... --- .../esupportail/esupsignature/service/DocumentService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/esupportail/esupsignature/service/DocumentService.java b/src/main/java/org/esupportail/esupsignature/service/DocumentService.java index c157d40f5..cc5523e21 100644 --- a/src/main/java/org/esupportail/esupsignature/service/DocumentService.java +++ b/src/main/java/org/esupportail/esupsignature/service/DocumentService.java @@ -85,11 +85,9 @@ public String exportDocument(DocumentIOType documentIOType, String targetUrl, Do InputStream inputStream = signedFile.getInputStream(); if (fsAccessService.putFile(targetUrl, signedFile.getFileName(), inputStream, UploadActionType.OVERRIDE)) { documentUri = targetUrl + "/" + signedFile.getFileName(); - if (fsAccessService.getFileFromURI(documentUri) != null) { + return documentUri; - } else { - throw new EsupSignatureFsException("file is not exported"); - } + } else { throw new EsupSignatureFsException("file is not exported"); } From 04163b422b817799f65d00e5ad9955abc247f162 Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Tue, 19 Oct 2021 13:51:06 +0200 Subject: [PATCH 08/22] work with ftp sftp --- .../esupsignature/entity/Workflow.java | 33 +++++++++---------- .../esupsignature/service/DataService.java | 25 +++----------- .../service/DocumentService.java | 5 +-- .../service/SignBookService.java | 8 ++--- .../service/SignRequestService.java | 10 +++--- .../esupsignature/service/TargetService.java | 18 ++++++---- .../service/WorkflowService.java | 24 ++++++++------ .../interfaces/fs/FsAccessFactory.java | 27 ++++++++------- .../interfaces/fs/FsAccessService.java | 16 ++++++++- .../interfaces/fs/vfs/VfsAccessImpl.java | 26 +++++++-------- .../scheduler/ScheduledTaskService.java | 2 +- .../admin/WorkflowAdminController.java | 10 +++--- .../manager/ManagerWorkflowController.java | 8 ++--- .../web/controller/user/DataController.java | 3 +- .../user/SignRequestController.java | 4 +-- .../web/controller/user/WizardController.java | 3 +- .../web/ws/FormWsController.java | 3 +- .../web/ws/SignRequestWsController.java | 4 +-- src/main/resources/i18n/messages.properties | 2 +- .../templates/admin/workflows/update.html | 4 +-- .../esupsignature/FsAccessServiceTest.java | 15 ++++----- 21 files changed, 132 insertions(+), 118 deletions(-) diff --git a/src/main/java/org/esupportail/esupsignature/entity/Workflow.java b/src/main/java/org/esupportail/esupsignature/entity/Workflow.java index bcfb70242..f903d6d04 100644 --- a/src/main/java/org/esupportail/esupsignature/entity/Workflow.java +++ b/src/main/java/org/esupportail/esupsignature/entity/Workflow.java @@ -6,7 +6,11 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Entity @JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"}, ignoreUnknown = true) @@ -163,6 +167,17 @@ public String getDocumentsSourceUri() { return documentsSourceUri; } + public String getProtectedDocumentsSourceUri() { + Pattern p = Pattern.compile("[^@]*:\\/\\/[^:]*:([^@]*)@.*?$"); + Matcher m = p.matcher(documentsSourceUri); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + m.appendReplacement(sb, m.group(0).replaceFirst(Pattern.quote(m.group(1)), "********")); + } + m.appendTail(sb); + return sb.toString(); + } + public void setDocumentsSourceUri(String documentsSourceUri) { this.documentsSourceUri = documentsSourceUri; } @@ -191,22 +206,6 @@ public void setWorkflowSteps(List workflowSteps) { this.workflowSteps = workflowSteps; } -// public DocumentIOType getTargetType() { -// return targetType; -// } -// -// public void setTargetType(DocumentIOType targetType) { -// this.targetType = targetType; -// } -// -// public String getDocumentsTargetUri() { -// return documentsTargetUri; -// } -// -// public void setDocumentsTargetUri(String documentsTargetUri) { -// this.documentsTargetUri = documentsTargetUri; -// } - public List getRoles() { return roles; } diff --git a/src/main/java/org/esupportail/esupsignature/service/DataService.java b/src/main/java/org/esupportail/esupsignature/service/DataService.java index 6fb799f44..eb8cab624 100644 --- a/src/main/java/org/esupportail/esupsignature/service/DataService.java +++ b/src/main/java/org/esupportail/esupsignature/service/DataService.java @@ -1,9 +1,9 @@ package org.esupportail.esupsignature.service; import org.esupportail.esupsignature.entity.*; -import org.esupportail.esupsignature.entity.enums.DocumentIOType; import org.esupportail.esupsignature.entity.enums.SignRequestStatus; import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.exception.EsupSignatureIOException; import org.esupportail.esupsignature.repository.DataRepository; import org.esupportail.esupsignature.service.interfaces.prefill.PreFillService; @@ -91,25 +91,8 @@ public void deleteOnlyData(Long id) { dataRepository.delete(data); } - private DocumentIOType getPathIOType(String path) throws EsupSignatureException { - try { - var uri = new java.net.URI(path); - switch (uri.getScheme()) { - case "smb": return DocumentIOType.smb; - case "cmis": return DocumentIOType.cmis; - case "sftp": return DocumentIOType.vfs; - - case "http": - case "https": return DocumentIOType.rest; - } - throw new EsupSignatureException("unknown protocol for url " + path); - } catch (java.net.URISyntaxException e) { - throw new EsupSignatureException("target Url error", e); - } - } - @Transactional - public SignBook sendForSign(Long dataId, List recipientsEmails, List allSignToCompletes, List externalUsersInfos, List targetEmails, List targetUrls, String userEppn, String authUserEppn, boolean forceSendEmail) throws EsupSignatureException, EsupSignatureIOException { + public SignBook sendForSign(Long dataId, List recipientsEmails, List allSignToCompletes, List externalUsersInfos, List targetEmails, List targetUrls, String userEppn, String authUserEppn, boolean forceSendEmail) throws EsupSignatureException, EsupSignatureIOException, EsupSignatureFsException { User user = userService.getUserByEppn(userEppn); User authUser = userService.getUserByEppn(authUserEppn); Data data = getById(dataId); @@ -138,7 +121,7 @@ public SignBook sendForSign(Long dataId, List recipientsEmails, List targetEmails, List recipientsEmails, List allSignToCompletes, List externalUsersInfos, List targetEmails, String userEppn, String authUserEppn) throws EsupSignatureException { + public void initWorkflowAndPendingSignBook(Long signRequestId, List recipientsEmails, List allSignToCompletes, List externalUsersInfos, List targetEmails, String userEppn, String authUserEppn) throws EsupSignatureFsException, EsupSignatureException { SignRequest signRequest = signRequestService.getById(signRequestId); SignBook signBook = signRequest.getParentSignBook(); if(signBook.getStatus().equals(SignRequestStatus.draft)) { diff --git a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java index 46f5f8829..a7bd7e072 100644 --- a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java +++ b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java @@ -846,7 +846,7 @@ public void addPostit(Long signRequestId, String comment, String userEppn, Strin } } - public void archiveSignRequests(List signRequests, String authUserEppn) throws EsupSignatureFsException { + public void archiveSignRequests(List signRequests, String authUserEppn) throws EsupSignatureFsException, EsupSignatureException { if(globalProperties.getArchiveUri() != null) { for(SignRequest signRequest : signRequests) { Document signedFile = signRequest.getLastSignedDocument(); @@ -893,7 +893,7 @@ public void clearAllDocuments(SignRequest signRequest) { } } - public FsFile getLastSignedFsFile(SignRequest signRequest) throws EsupSignatureFsException { + public FsFile getLastSignedFsFile(SignRequest signRequest) throws EsupSignatureFsException, EsupSignatureException { if(signRequest.getStatus().equals(SignRequestStatus.exported)) { if (signRequest.getExportedDocumentURI() != null && !signRequest.getExportedDocumentURI().startsWith("mail")) { FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(signRequest.getExportedDocumentURI()); @@ -1254,7 +1254,7 @@ public void addStep(Long id, List recipientsEmails, SignType signType, B } @Transactional - public Map sendSignRequest(MultipartFile[] multipartFiles, SignType signType, Boolean allSignToComplete, Boolean userSignFirst, Boolean pending, String comment, List recipientsCCEmails, List recipientsEmails, List externalUsersInfos, User user, User authUser, boolean forceSendEmail, Boolean forceAllSign, String targetUrl) throws EsupSignatureException, EsupSignatureIOException { + public Map sendSignRequest(MultipartFile[] multipartFiles, SignType signType, Boolean allSignToComplete, Boolean userSignFirst, Boolean pending, String comment, List recipientsCCEmails, List recipientsEmails, List externalUsersInfos, User user, User authUser, boolean forceSendEmail, Boolean forceAllSign, String targetUrl) throws EsupSignatureException, EsupSignatureIOException, EsupSignatureFsException { if(forceAllSign == null) forceAllSign = false; if (!signService.checkSignTypeDocType(signType, multipartFiles[0])) { throw new EsupSignatureException("Impossible de demander une signature visuelle sur un document du type " + multipartFiles[0].getContentType()); @@ -1267,7 +1267,7 @@ public Map sendSignRequest(MultipartFile[] multipartFiles, Sig throw new EsupSignatureException(e.getMessage()); } if(targetUrl != null && !targetUrl.isEmpty()) { - signBook.getLiveWorkflow().getTargets().add(targetService.createTarget(DocumentIOType.rest, targetUrl)); + signBook.getLiveWorkflow().getTargets().add(targetService.createTarget(targetUrl)); } return signBookService.sendSignBook(signBook, signType, allSignToComplete, userSignFirst, pending, comment, recipientsEmails, externalUsersInfos, user, authUser, forceSendEmail); } @@ -1392,7 +1392,7 @@ public Map getAttachmentResponse(Long signRequestId, Long attach } @Transactional - public Map getToSignFileResponse(Long signRequestId) throws SQLException, EsupSignatureFsException, IOException { + public Map getToSignFileResponse(Long signRequestId) throws SQLException, EsupSignatureFsException, IOException, EsupSignatureException { SignRequest signRequest = getById(signRequestId); if (!signRequest.getStatus().equals(SignRequestStatus.exported)) { List documents = getToSignDocuments(signRequest.getId()); diff --git a/src/main/java/org/esupportail/esupsignature/service/TargetService.java b/src/main/java/org/esupportail/esupsignature/service/TargetService.java index 246f4cec6..3a2bd64ff 100644 --- a/src/main/java/org/esupportail/esupsignature/service/TargetService.java +++ b/src/main/java/org/esupportail/esupsignature/service/TargetService.java @@ -3,7 +3,10 @@ import org.esupportail.esupsignature.entity.SignBook; import org.esupportail.esupsignature.entity.Target; import org.esupportail.esupsignature.entity.enums.DocumentIOType; +import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.repository.TargetRepository; +import org.esupportail.esupsignature.service.interfaces.fs.FsAccessFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,31 +19,34 @@ public class TargetService { @Resource private TargetRepository targetRepository; + @Resource + private FsAccessFactory fsAccessFactory; + public Target getById(Long id) { return targetRepository.findById(id).get(); } @Transactional - public Target createTarget(DocumentIOType targetType, String targetUri) { + public Target createTarget(String targetUri) throws EsupSignatureFsException { Target target = new Target(); - target.setTargetType(targetType); + target.setTargetType(fsAccessFactory.getPathIOType(targetUri)); target.setTargetUri(targetUri); targetRepository.save(target); return target; } - public void copyTargets(List targets, SignBook signBook, List targetEmails) { + public void copyTargets(List targets, SignBook signBook, List targetEmails) throws EsupSignatureFsException, EsupSignatureException { signBook.getLiveWorkflow().getTargets().clear(); for(Target target : targets) { if(target.getTargetType() != DocumentIOType.none && target.getTargetType() != DocumentIOType.mail && target.getTargetUri() != null && !target.getTargetUri().isEmpty()) { - signBook.getLiveWorkflow().getTargets().add(createTarget(target.getTargetType(), target.getTargetUri())); + signBook.getLiveWorkflow().getTargets().add(createTarget(target.getTargetUri())); } } signBook.getLiveWorkflow().getTargets().add(addTargetEmails(targetEmails, targets)); } - public Target addTargetEmails(List targetEmails, List targets) { + public Target addTargetEmails(List targetEmails, List targets) throws EsupSignatureFsException { StringBuilder targetEmailsToAdd = new StringBuilder(); for(Target target1 : targets) { if(target1.getTargetType().equals(DocumentIOType.mail)) { @@ -59,7 +65,7 @@ public Target addTargetEmails(List targetEmails, List targets) { } } if(!targetEmailsToAdd.toString().isEmpty()) { - return createTarget(DocumentIOType.mail, targetEmailsToAdd.toString()); + return createTarget(targetEmailsToAdd.toString()); } else { return null; } diff --git a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java index 0aba386b8..9629aeb12 100644 --- a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java +++ b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java @@ -4,6 +4,7 @@ import org.esupportail.esupsignature.entity.*; import org.esupportail.esupsignature.entity.enums.*; import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.exception.EsupSignatureUserException; import org.esupportail.esupsignature.repository.WorkflowRepository; import org.esupportail.esupsignature.service.interfaces.fs.FsAccessFactory; @@ -243,13 +244,13 @@ public Set getWorkflowsByUser(String userEppn, String authUserEppn) { } @Transactional - public int importFilesFromSource(Long workflowId, User user, User authUser) { + public int importFilesFromSource(Long workflowId, User user, User authUser) throws EsupSignatureFsException { Workflow workflow = getById(workflowId); List fsFiles = new ArrayList<>(); int nbImportedFiles = 0; - if (workflow.getSourceType() != null && !workflow.getSourceType().equals(DocumentIOType.none)) { - logger.debug("retrieve from " + workflow.getSourceType() + " in " + workflow.getDocumentsSourceUri()); - FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(workflow.getSourceType()); + if (workflow.getDocumentsSourceUri() != null && !workflow.getDocumentsSourceUri().equals("")) { + logger.debug("retrieve from " + workflow.getProtectedDocumentsSourceUri()); + FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(workflow.getDocumentsSourceUri()); if (fsAccessService != null) { fsAccessService.open(); if (fsAccessService.cd(workflow.getDocumentsSourceUri()) == null) { @@ -305,7 +306,7 @@ public int importFilesFromSource(Long workflowId, User user, User authUser) { if (keySplit[0].equals("sign") && keySplit[1].contains("target")) { String metadataTarget = metadatas.get(metadataKey); for(Target target : workflow.getTargets()) { - signBook.getLiveWorkflow().getTargets().add(targetService.createTarget(target.getTargetType(), target.getTargetUri() + "/" + metadataTarget)); + signBook.getLiveWorkflow().getTargets().add(targetService.createTarget(target.getTargetUri() + "/" + metadataTarget)); } logger.info("target set to : " + signBook.getLiveWorkflow().getTargets().get(0).getTargetUri()); } @@ -521,7 +522,9 @@ public Workflow update(Workflow workflow, User user, String[] types, List getWorkflowStepsFromSignRequest(SignRequest signReques } @Transactional - public boolean addTarget(Long id, String targetType, String documentsTargetUri) { + public boolean addTarget(Long id, String documentsTargetUri) throws EsupSignatureFsException, EsupSignatureException { Workflow workflow = getById(id); + DocumentIOType targetType = fsAccessFactory.getPathIOType(documentsTargetUri); if(!targetType.equals("mail") || workflow.getTargets().stream().map(Target::getTargetType).noneMatch(tt -> tt.equals(DocumentIOType.mail))) { - Target target = targetService.createTarget(DocumentIOType.valueOf(targetType), documentsTargetUri); + Target target = targetService.createTarget(documentsTargetUri); workflow.getTargets().add(target); return true; } @@ -589,7 +593,7 @@ public InputStream getJsonWorkflowSetup(Long id) throws IOException { } @Transactional - public void setWorkflowSetupFromJson(Long id, InputStream inputStream) throws IOException { + public void setWorkflowSetupFromJson(Long id, InputStream inputStream) throws IOException, EsupSignatureException, EsupSignatureFsException { Workflow workflow = getById(id); String savedName = workflow.getName(); String savedTitle = workflow.getTitle(); @@ -610,7 +614,7 @@ public void setWorkflowSetupFromJson(Long id, InputStream inputStream) throws IO workflow.getTargets().clear(); update(workflow, workflowSetup.getCreateBy(), null, workflowSetup.getManagers()); for(Target target : workflowSetup.getTargets()) { - Target newTarget = targetService.createTarget(target.getTargetType(), target.getTargetUri()); + Target newTarget = targetService.createTarget(target.getTargetUri()); workflow.getTargets().add(newTarget); } workflow.setName(savedName); diff --git a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java index 9dd8d86e4..9e1fae122 100644 --- a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java +++ b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java @@ -8,8 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.net.URI; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -37,12 +35,8 @@ public void setVfsAccessImpl(VfsAccessImpl vfsAccessImpl) { public void setCmisAccessImpl(CmisAccessImpl cmisAccessImpl) { this.cmisAccessImpl = cmisAccessImpl; } - - public FsAccessService getFsAccessService(String path) throws EsupSignatureFsException { - return getFsAccessService(getPathIOType(path)); - } - - public FsAccessService getFsAccessService(DocumentIOType type) { + public FsAccessService getFsAccessService(String uri) throws EsupSignatureFsException { + DocumentIOType type = getPathIOType(uri); switch (type) { case smb: return smbAccessImpl; @@ -71,9 +65,20 @@ public List getFsAccessServices() { public DocumentIOType getPathIOType(String path) throws EsupSignatureFsException { try { - URI uri = new URI(path); - return DocumentIOType.valueOf(uri.getScheme()); - } catch (URISyntaxException e) { + var uri = new java.net.URI(path); + switch (uri.getScheme()) { + case "smb": return DocumentIOType.smb; + case "cmis": return DocumentIOType.cmis; + case "file": + case "sftp": + case "ftp": + return DocumentIOType.vfs; + case "http": + case "https": + return DocumentIOType.rest; + } + throw new EsupSignatureFsException("unknown protocol for url " + path); + } catch (java.net.URISyntaxException e) { throw new EsupSignatureFsException("target Url error", e); } } diff --git a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessService.java b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessService.java index dab9f900a..90b36dd54 100644 --- a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessService.java +++ b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessService.java @@ -26,6 +26,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public abstract class FsAccessService { @@ -64,7 +66,7 @@ public void setUriManipulateService( protected void manipulateUri() { // make only one uri manipulation - if(this.uriManipulateService != null && this.uriManipulateDone == false) { + if(this.uriManipulateService != null && !this.uriManipulateDone) { this.uriManipulateDone = true; this.uri = this.uriManipulateService.manipulate(uri); } @@ -126,4 +128,16 @@ public boolean isSupportQuota(String path) { return false; } + + protected String getProtectedUri(String uri) { + Pattern p = Pattern.compile("[^@]*:\\/\\/[^:]*:([^@]*)@.*?$"); + Matcher m = p.matcher(uri); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + m.appendReplacement(sb, m.group(0).replaceFirst(Pattern.quote(m.group(1)), "********")); + } + m.appendTail(sb); + return sb.toString(); + } + } diff --git a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java index 6ddc7260f..06c74b668 100644 --- a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java +++ b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/vfs/VfsAccessImpl.java @@ -111,12 +111,12 @@ public void close() { } } - private boolean use_stateful_filesystem(String uri) { - return !uri.startsWith("sftp://"); + private boolean useStatefulFilesystem(String uri) { + return !uri.startsWith("sftp://") && !uri.startsWith("ftp://"); } - private void may_close(String uri, FileObject o) { - if (!use_stateful_filesystem(uri)) { + private void mayClose(String uri, FileObject o) { + if (!useStatefulFilesystem(uri)) { try { VFS.getManager().closeFileSystem(o.getFileSystem()); } catch (FileSystemException e) { @@ -125,7 +125,7 @@ private void may_close(String uri, FileObject o) { } } - public void destroy() throws Exception { + public void destroy() { this.close(); } @@ -140,7 +140,7 @@ public FileObject cd(String path) { this.open(); if (path == null || path.length() == 0) { returnValue = root; - } else if (use_stateful_filesystem(path)) { + } else if (useStatefulFilesystem(path)) { returnValue = root.resolveFile("/" + path); } else { returnValue = open(path); @@ -172,14 +172,14 @@ public List listFiles(String url) throws EsupSignatureFsException { } catch (IOException e) { throw new EsupSignatureFsException(e); } finally { - may_close(url, resource); + mayClose(url, resource); } return fsFiles; } @Override public void remove(FsFile fsFile) throws EsupSignatureFsException { - logger.info("removing file on vfs " + fsFile.getPath() + "/" + fsFile.getName()); + logger.info("removing file on vfs " + super.getProtectedUri(fsFile.getPath()) + "/" + fsFile.getName()); FileObject file; try { file = cd(fsFile.getPath() + "/" + fsFile.getName()); @@ -207,7 +207,7 @@ public String createFile(String parentPath, String title, String type) { } else { logger.info("file " + title + " already exists !"); } - may_close(parentPath, parent); + mayClose(parentPath, parent); } catch (FileSystemException e) { logger.info("can't create file because of FileSystemException : " + e.getMessage(), e); @@ -231,7 +231,7 @@ public boolean renameFile(String path, String title) throws EsupSignatureFsExcep } else { logger.info("file " + title + " already exists !"); } - may_close(path, file); + mayClose(path, file); } catch (FileSystemException e) { logger.info("can't rename file because of FileSystemException : " + e.getMessage(), e); @@ -254,7 +254,7 @@ public boolean moveCopyFilesIntoDirectory(String dir, List filesToCopy, } } - may_close(dir, folder); + mayClose(dir, folder); return true; } catch (FileSystemException e) { logger.warn("can't move/copy file because of FileSystemException : " @@ -266,7 +266,7 @@ public boolean moveCopyFilesIntoDirectory(String dir, List filesToCopy, @Override public FsFile getFile(String dir) { try { - if (!use_stateful_filesystem(dir)) throw new RuntimeException("TODO"); + if (!useStatefulFilesystem(dir)) throw new RuntimeException("TODO"); FileObject fileObject = cd(dir); return toFsFile(fileObject); } catch (IOException e) { @@ -314,7 +314,7 @@ public boolean putFile(String dir, String filename, InputStream inputStream, Upl FileCopyUtils.copy(inputStream, outstr); - may_close(dir, folder); + mayClose(dir, folder); success = true; } catch (FileSystemException e) { diff --git a/src/main/java/org/esupportail/esupsignature/service/scheduler/ScheduledTaskService.java b/src/main/java/org/esupportail/esupsignature/service/scheduler/ScheduledTaskService.java index 1e6751573..99f0fa56c 100644 --- a/src/main/java/org/esupportail/esupsignature/service/scheduler/ScheduledTaskService.java +++ b/src/main/java/org/esupportail/esupsignature/service/scheduler/ScheduledTaskService.java @@ -67,7 +67,7 @@ public void setoJService(OJService oJService) { @Scheduled(initialDelay = 120000, fixedRate = 300000) @Transactional - public void scanAllSignbooksSources() { + public void scanAllSignbooksSources() throws EsupSignatureFsException { Iterable workflows = workflowService.getAllWorkflows(); User userScheduler = userService.getSchedulerUser(); for(Workflow workflow : workflows) { diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java b/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java index 452064e78..a3a7b8aec 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java @@ -10,6 +10,7 @@ import org.esupportail.esupsignature.entity.enums.ShareType; import org.esupportail.esupsignature.entity.enums.SignType; import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.service.*; import org.esupportail.esupsignature.web.ws.json.JsonMessage; import org.slf4j.Logger; @@ -198,7 +199,7 @@ public String addStep(@ModelAttribute("authUserEppn") String authUserEppn, } @GetMapping(value = "/get-files-from-source/{id}") - public String getFileFromSource(@ModelAttribute("authUserEppn") String authUserEppn, @PathVariable("id") Long id, Model model, RedirectAttributes redirectAttributes) { + public String getFileFromSource(@ModelAttribute("authUserEppn") String authUserEppn, @PathVariable("id") Long id, Model model, RedirectAttributes redirectAttributes) throws EsupSignatureFsException { User authUser = (User) model.getAttribute("authUser"); int nbImportedFiles = workflowService.importFilesFromSource(id, authUser, authUser); if(nbImportedFiles == 0) { @@ -211,10 +212,9 @@ public String getFileFromSource(@ModelAttribute("authUserEppn") String authUserE @PostMapping(value = "/add-target/{id}") public String addTarget(@PathVariable("id") Long id, - @RequestParam("targetType") String targetType, @RequestParam("documentsTargetUri") String documentsTargetUri, - RedirectAttributes redirectAttributes) { - if(workflowService.addTarget(id, targetType, documentsTargetUri)) { + RedirectAttributes redirectAttributes) throws EsupSignatureException, EsupSignatureFsException { + if(workflowService.addTarget(id, documentsTargetUri)) { redirectAttributes.addFlashAttribute("message", new JsonMessage("info", "Destination ajoutée")); } else { redirectAttributes.addFlashAttribute("message", new JsonMessage("warn", "Une destination mail existe déjà")); @@ -253,7 +253,7 @@ public String importWorkflowSetup(@PathVariable("id") Long id, if(multipartFormSetup.getSize() > 0) { workflowService.setWorkflowSetupFromJson(id, multipartFormSetup.getInputStream()); } - } catch (IOException e) { + } catch (IOException | EsupSignatureException | EsupSignatureFsException e) { logger.error(e.getMessage()); redirectAttributes.addFlashAttribute("message", new JsonMessage("error", e.getMessage())); } diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/manager/ManagerWorkflowController.java b/src/main/java/org/esupportail/esupsignature/web/controller/manager/ManagerWorkflowController.java index 23cd0a403..c5f1cd062 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/manager/ManagerWorkflowController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/manager/ManagerWorkflowController.java @@ -7,6 +7,7 @@ import org.esupportail.esupsignature.entity.enums.ShareType; import org.esupportail.esupsignature.entity.enums.SignType; import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.service.UserService; import org.esupportail.esupsignature.service.WorkflowService; import org.esupportail.esupsignature.service.WorkflowStepService; @@ -182,7 +183,7 @@ public String addStep(@ModelAttribute("authUserEppn") String authUserEppn, @GetMapping(value = "/get-files-from-source/{id}") @PreAuthorize("@preAuthorizeService.workflowManager(#id, #authUserEppn)") - public String getFileFromSource(@ModelAttribute("authUserEppn") String authUserEppn, @PathVariable("id") Long id, Model model, RedirectAttributes redirectAttributes) { + public String getFileFromSource(@ModelAttribute("authUserEppn") String authUserEppn, @PathVariable("id") Long id, Model model, RedirectAttributes redirectAttributes) throws EsupSignatureFsException { User authUser = (User) model.getAttribute("authUser"); int nbImportedFiles = workflowService.importFilesFromSource(id, authUser, authUser); if(nbImportedFiles == 0) { @@ -196,11 +197,10 @@ public String getFileFromSource(@ModelAttribute("authUserEppn") String authUserE @PostMapping(value = "/add-target/{id}") @PreAuthorize("@preAuthorizeService.workflowManager(#id, #authUserEppn)") public String addTarget(@PathVariable("id") Long id, - @RequestParam("targetType") String targetType, @RequestParam("documentsTargetUri") String documentsTargetUri, @ModelAttribute("authUserEppn") String authUserEppn, - RedirectAttributes redirectAttributes) { - if(workflowService.addTarget(id, targetType, documentsTargetUri)) { + RedirectAttributes redirectAttributes) throws EsupSignatureException, EsupSignatureFsException { + if(workflowService.addTarget(id, documentsTargetUri)) { redirectAttributes.addFlashAttribute("message", new JsonMessage("info", "Destination ajoutée")); } else { redirectAttributes.addFlashAttribute("message", new JsonMessage("warn", "Une destination mail existe déjà")); diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/user/DataController.java b/src/main/java/org/esupportail/esupsignature/web/controller/user/DataController.java index d1ec30c00..3727860e0 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/user/DataController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/user/DataController.java @@ -8,6 +8,7 @@ import org.esupportail.esupsignature.entity.SignBook; import org.esupportail.esupsignature.entity.User; import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.exception.EsupSignatureIOException; import org.esupportail.esupsignature.service.DataService; import org.esupportail.esupsignature.service.FormService; @@ -64,7 +65,7 @@ public String sendForm(@ModelAttribute("userEppn") String userEppn, @ModelAttrib @RequestParam(value = "names", required = false) List names, @RequestParam(value = "firstnames", required = false) List firstnames, @RequestParam(value = "phones", required = false) List phones, - @PathVariable("id") Long id, RedirectAttributes redirectAttributes) throws EsupSignatureIOException, EsupSignatureException { + @PathVariable("id") Long id, RedirectAttributes redirectAttributes) throws EsupSignatureIOException, EsupSignatureException, EsupSignatureFsException { List externalUsersInfos = userService.getJsonExternalUserInfos(emails, names, firstnames, phones); if(formService.isFormAuthorized(userEppn, authUserEppn, id)) { Data data = dataService.addData(id, userEppn, authUserEppn); diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/user/SignRequestController.java b/src/main/java/org/esupportail/esupsignature/web/controller/user/SignRequestController.java index e5dd9b035..458b0bcf2 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/user/SignRequestController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/user/SignRequestController.java @@ -406,7 +406,7 @@ public String sendSignRequest(@ModelAttribute("userEppn") String userEppn, @Mode redirectAttributes.addFlashAttribute("message", new JsonMessage("error", "Merci de compléter tous les utilisateurs externes")); } return "redirect:/user/signrequests/" + signRequestId; - } catch (EsupSignatureException | MessagingException e) { + } catch (EsupSignatureException | MessagingException | EsupSignatureFsException e) { redirectAttributes.addFlashAttribute("message", new JsonMessage("error", e.getMessage())); } } else { @@ -616,7 +616,7 @@ public String pending(@ModelAttribute("userEppn") String userEppn, @ModelAttribu @RequestParam(value = "names", required = false) List names, @RequestParam(value = "firstnames", required = false) List firstnames, @RequestParam(value = "phones", required = false) List phones, - RedirectAttributes redirectAttributes) throws MessagingException, EsupSignatureException { + RedirectAttributes redirectAttributes) throws MessagingException, EsupSignatureException, EsupSignatureFsException { List externalUsersInfos = userService.getJsonExternalUserInfos(emails, names, firstnames, phones); if(!signRequestService.checkTempUsers(id, recipientEmails, externalUsersInfos)) { redirectAttributes.addFlashAttribute("message", new JsonMessage("error", "Merci de compléter tous les utilisateurs externes")); diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/user/WizardController.java b/src/main/java/org/esupportail/esupsignature/web/controller/user/WizardController.java index f5c40ed22..d65481655 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/user/WizardController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/user/WizardController.java @@ -5,6 +5,7 @@ import org.esupportail.esupsignature.entity.Workflow; import org.esupportail.esupsignature.entity.enums.SignType; import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.exception.EsupSignatureMailException; import org.esupportail.esupsignature.service.*; import org.esupportail.esupsignature.web.ws.json.JsonMessage; @@ -59,7 +60,7 @@ public String wiz4(@ModelAttribute("userEppn") String userEppn, @PathVariable("i @RequestParam(value = "forceAllSign", required = false) Boolean forceAllSign, @RequestParam(value = "recipientsCCEmailsWiz", required = false) List recipientsCCEmailsWiz, @RequestParam(value = "comment", required = false) String comment, - Model model) { + Model model) throws EsupSignatureFsException { User user = (User) model.getAttribute("user"); SignBook signBook = signBookService.getById(id); signBook.setForceAllDocsSign(forceAllSign); diff --git a/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java b/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java index 0354836ff..639bfeeca 100644 --- a/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java +++ b/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java @@ -5,6 +5,7 @@ import org.esupportail.esupsignature.entity.Data; import org.esupportail.esupsignature.entity.SignBook; import org.esupportail.esupsignature.exception.EsupSignatureException; +import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.exception.EsupSignatureIOException; import org.esupportail.esupsignature.service.DataService; import org.esupportail.esupsignature.service.export.DataExportService; @@ -38,7 +39,7 @@ public Long start(@PathVariable Long id, try { SignBook signBook = dataService.sendForSign(data.getId(), recipientEmails, allSignToCompletes, null, targetEmails, targetUrls, eppn, eppn, true); return signBook.getSignRequests().get(0).getId(); - } catch (EsupSignatureException | EsupSignatureIOException e) { + } catch (EsupSignatureException | EsupSignatureIOException | EsupSignatureFsException e) { return -1L; } } diff --git a/src/main/java/org/esupportail/esupsignature/web/ws/SignRequestWsController.java b/src/main/java/org/esupportail/esupsignature/web/ws/SignRequestWsController.java index eb6ba28be..11f4b1b65 100644 --- a/src/main/java/org/esupportail/esupsignature/web/ws/SignRequestWsController.java +++ b/src/main/java/org/esupportail/esupsignature/web/ws/SignRequestWsController.java @@ -68,7 +68,7 @@ public Long create(@Parameter(description = "Multipart stream du fichier à sign try { Map signBookStringMap = signRequestService.sendSignRequest(multipartFiles, SignType.valueOf(signType), allSignToComplete, userSignFirst, pending, comment, recipientsCCEmails, recipientsEmails, externalUsersInfos, user, user, true, forceAllSign, targetUrl); return signBookStringMap.keySet().iterator().next().getSignRequests().get(0).getId(); - } catch (EsupSignatureException | EsupSignatureIOException e) { + } catch (EsupSignatureException | EsupSignatureIOException | EsupSignatureFsException e) { logger.error(e.getMessage(), e); return -1L; } @@ -101,7 +101,7 @@ public ResponseEntity getLastFileFromSignRequest(@PathVariable("id") Long IOUtils.copyLarge((InputStream) fileResponse.get("inputStream"), httpServletResponse.getOutputStream()); } return new ResponseEntity<>(HttpStatus.OK); - } catch (NoResultException | IOException | EsupSignatureFsException | SQLException e) { + } catch (NoResultException | IOException | EsupSignatureFsException | SQLException | EsupSignatureException e) { logger.error(e.getMessage(), e); } return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index e10cec886..0b4aa5908 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -43,7 +43,7 @@ signbook.status.cleaned=Archivé (et purgé) signbook.status.completed=Terminé signbook.documentiotype.none=Ajout manuel signbook.documentiotype.smb=Partage réseau (smb) -signbook.documentiotype.vfs=Dossier local du serveur +signbook.documentiotype.vfs=Dossier VFS signbook.documentiotype.cmis=Gestionnaire électronique de documents (cmis) signbook.documentiotype.mail=Envoi par email signbook.documentiotype.rest=Envoi d'un message REST diff --git a/src/main/resources/templates/admin/workflows/update.html b/src/main/resources/templates/admin/workflows/update.html index 718a2c961..3163e8af4 100644 --- a/src/main/resources/templates/admin/workflows/update.html +++ b/src/main/resources/templates/admin/workflows/update.html @@ -144,9 +144,9 @@

Nombre de demandes pour ce circuit :
-
diff --git a/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java b/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java index 53cac3427..05bc5f465 100644 --- a/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java +++ b/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java @@ -1,7 +1,6 @@ package org.esupportail.esupsignature; import org.esupportail.esupsignature.config.GlobalProperties; -import org.esupportail.esupsignature.entity.enums.DocumentIOType; import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.service.interfaces.fs.FsAccessFactory; import org.esupportail.esupsignature.service.interfaces.fs.FsAccessService; @@ -32,8 +31,8 @@ public class FsAccessServiceTest { private GlobalProperties globalProperties; @Test - public void testSmbAccessImpl() { - FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(DocumentIOType.smb); + public void testSmbAccessImpl() throws EsupSignatureFsException { + FsAccessService fsAccessService = fsAccessFactory.getFsAccessService("smb://test"); assumeTrue("SMB not configured", fsAccessService != null && fsAccessService.getUri() != null); try { if (fsAccessService.cd("/") == null) { @@ -50,8 +49,8 @@ public void testSmbAccessImpl() { } @Test - public void testCmisAccessImpl() { - FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(DocumentIOType.cmis); + public void testCmisAccessImpl() throws EsupSignatureFsException { + FsAccessService fsAccessService = fsAccessFactory.getFsAccessService("cmis://test"); assumeTrue("cmis not configured", fsAccessService != null && fsAccessService.getUri() != null); try { if (fsAccessService.cd("/") == null) { @@ -67,8 +66,8 @@ public void testCmisAccessImpl() { } @Test - public void testVfsAccessImpl() { - FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(DocumentIOType.vfs); + public void testVfsAccessImpl() throws EsupSignatureFsException { + FsAccessService fsAccessService = fsAccessFactory.getFsAccessService("ftp://test"); assumeTrue("vfs not configured", fsAccessService != null && fsAccessService.getUri() != null); try { if (fsAccessService.cd("/") == null) { @@ -86,7 +85,7 @@ public void testVfsAccessImpl() { @Test public void testArchiveUri() throws EsupSignatureFsException { assumeTrue("archive url not configured", globalProperties.getArchiveUri() != null); - FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(fsAccessFactory.getPathIOType(globalProperties.getArchiveUri())); + FsAccessService fsAccessService = fsAccessFactory.getFsAccessService(globalProperties.getArchiveUri()); fsAccessService.createURITree(globalProperties.getArchiveUri()); } From cc5b549ad55d8d5fb2baa619b874c2f8446a66ea Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Tue, 19 Oct 2021 16:27:04 +0200 Subject: [PATCH 09/22] multi targets based on uri --- .../esupsignature/config/fs/FsConfig.java | 4 +- .../esupsignature/config/fs/FsProperties.java | 10 ++-- .../esupsignature/entity/Target.java | 34 +++++++------ .../esupsignature/entity/Workflow.java | 29 ++++------- .../service/SignBookService.java | 10 ++-- .../service/SignRequestService.java | 8 ++-- .../esupsignature/service/TargetService.java | 19 ++++---- .../service/WorkflowService.java | 10 +--- .../interfaces/fs/FsAccessFactory.java | 48 ++++++++----------- .../interfaces/workflow/DefaultWorkflow.java | 6 --- .../service/mail/MailService.java | 2 +- .../admin/WorkflowAdminController.java | 2 +- .../js/modules/ui/workflows/WorkflowUi.js | 28 +---------- .../templates/admin/workflows/list.html | 2 +- .../templates/admin/workflows/update.html | 36 ++++---------- .../resources/templates/fragments/new.html | 2 +- .../templates/managers/workflows/update.html | 13 ----- .../user/signrequests/cards/stepscard.html | 4 +- .../templates/user/signrequests/show.html | 4 +- .../user/wizard/wiz-setup-workflow.html | 4 +- src/main/resources/update_1.15.1.sql | 3 ++ .../esupportail/esupsignature/DSSTest.java | 5 +- .../esupsignature/FsAccessServiceTest.java | 4 +- 23 files changed, 104 insertions(+), 183 deletions(-) create mode 100644 src/main/resources/update_1.15.1.sql diff --git a/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java b/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java index 80bd5d063..865a92600 100644 --- a/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java +++ b/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java @@ -25,11 +25,11 @@ public FsProperties getFsProperties() { } @Bean - @ConditionalOnProperty({"fs.smb-uri"}) + @ConditionalOnProperty({"fs.smb-test-uri"}) public SmbAccessImpl smbAccessImpl(){ SmbAccessImpl smbAccessImpl = new SmbAccessImpl(); smbAccessImpl.setDriveName("CIFS"); - smbAccessImpl.setUri(fsProperties.getSmbUri()); + smbAccessImpl.setUri(fsProperties.getSmbTestUri()); smbAccessImpl.setJcifsConfigProperties(smbProperties()); smbAccessImpl.setLogin(fsProperties.getSmbLogin()); smbAccessImpl.setPassword(fsProperties.getSmbPassword()); diff --git a/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java b/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java index 2ecbbd788..3591cc8f7 100644 --- a/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java +++ b/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java @@ -5,7 +5,7 @@ @ConfigurationProperties(prefix="fs") public class FsProperties { - private String smbUri; + private String smbTestUri; private String smbLogin; private String smbPassword; private String smbDomain; @@ -16,12 +16,12 @@ public class FsProperties { private String cmisRespositoryId; private String cmisRootPath; - public String getSmbUri() { - return smbUri; + public String getSmbTestUri() { + return smbTestUri; } - public void setSmbUri(String smbUri) { - this.smbUri = smbUri; + public void setSmbTestUri(String smbTestUri) { + this.smbTestUri = smbTestUri; } public String getSmbLogin() { diff --git a/src/main/java/org/esupportail/esupsignature/entity/Target.java b/src/main/java/org/esupportail/esupsignature/entity/Target.java index 9ec7f9c86..06588fbb6 100644 --- a/src/main/java/org/esupportail/esupsignature/entity/Target.java +++ b/src/main/java/org/esupportail/esupsignature/entity/Target.java @@ -1,8 +1,11 @@ package org.esupportail.esupsignature.entity; -import org.esupportail.esupsignature.entity.enums.DocumentIOType; - -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Entity public class Target { @@ -11,9 +14,6 @@ public class Target { @GeneratedValue(strategy = GenerationType.AUTO) private Long id; - @Enumerated(EnumType.STRING) - private DocumentIOType targetType; - private String targetUri; private Boolean targetOk = false; @@ -26,14 +26,6 @@ public void setTargetOk(Boolean targetOk) { this.targetOk = targetOk; } - public DocumentIOType getTargetType() { - return targetType; - } - - public void setTargetType(DocumentIOType targetType) { - this.targetType = targetType; - } - public String getTargetUri() { return targetUri; } @@ -49,4 +41,18 @@ public void setId(Long id) { public Long getId() { return id; } + + public String getProtectedTargetUri() { + if(targetUri != null) { + Pattern p = Pattern.compile("[^@]*:\\/\\/[^:]*:([^@]*)@.*?$"); + Matcher m = p.matcher(targetUri); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + m.appendReplacement(sb, m.group(0).replaceFirst(Pattern.quote(m.group(1)), "********")); + } + m.appendTail(sb); + return sb.toString(); + } + return ""; + } } diff --git a/src/main/java/org/esupportail/esupsignature/entity/Workflow.java b/src/main/java/org/esupportail/esupsignature/entity/Workflow.java index f903d6d04..df184ff64 100644 --- a/src/main/java/org/esupportail/esupsignature/entity/Workflow.java +++ b/src/main/java/org/esupportail/esupsignature/entity/Workflow.java @@ -1,7 +1,6 @@ package org.esupportail.esupsignature.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import org.esupportail.esupsignature.entity.enums.DocumentIOType; import org.esupportail.esupsignature.entity.enums.ShareType; import org.springframework.format.annotation.DateTimeFormat; @@ -54,9 +53,6 @@ public class Workflow { private Boolean sendAlertToAllRecipients = false; - @Enumerated(EnumType.STRING) - private DocumentIOType sourceType; - private String documentsSourceUri; @ElementCollection(targetClass=String.class) @@ -155,27 +151,22 @@ public void setPublicUsage(Boolean publicUsage) { this.publicUsage = publicUsage; } - public DocumentIOType getSourceType() { - return sourceType; - } - - public void setSourceType(DocumentIOType sourceType) { - this.sourceType = sourceType; - } - public String getDocumentsSourceUri() { return documentsSourceUri; } public String getProtectedDocumentsSourceUri() { - Pattern p = Pattern.compile("[^@]*:\\/\\/[^:]*:([^@]*)@.*?$"); - Matcher m = p.matcher(documentsSourceUri); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - m.appendReplacement(sb, m.group(0).replaceFirst(Pattern.quote(m.group(1)), "********")); + if(documentsSourceUri != null) { + Pattern p = Pattern.compile("[^@]*:\\/\\/[^:]*:([^@]*)@.*?$"); + Matcher m = p.matcher(documentsSourceUri); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + m.appendReplacement(sb, m.group(0).replaceFirst(Pattern.quote(m.group(1)), "********")); + } + m.appendTail(sb); + return sb.toString(); } - m.appendTail(sb); - return sb.toString(); + return ""; } public void setDocumentsSourceUri(String documentsSourceUri) { diff --git a/src/main/java/org/esupportail/esupsignature/service/SignBookService.java b/src/main/java/org/esupportail/esupsignature/service/SignBookService.java index 07c3fb904..e37cad4bd 100644 --- a/src/main/java/org/esupportail/esupsignature/service/SignBookService.java +++ b/src/main/java/org/esupportail/esupsignature/service/SignBookService.java @@ -200,6 +200,10 @@ public List getSharedSignBooks(String userEppn) { @Transactional public void delete(Long signBookId, String userEppn) { SignBook signBook = getById(signBookId); + if(signBook.getStatus().equals(SignRequestStatus.deleted)) { + deleteDefinitive(signBookId); + return; + } List signRequestsIds = signBook.getSignRequests().stream().map(SignRequest::getId).collect(Collectors.toList()); for(Long signRequestId : signRequestsIds) { signRequestService.delete(signRequestId, userEppn); @@ -233,10 +237,6 @@ public void deleteDefinitive(Long signBookId) { logger.info("definitive delete signbook : " + signBookId); } - public void removeSignRequestFromSignBook(SignBook signBook, SignRequest signRequest) { - signBook.getSignRequests().remove(signRequest); - } - public boolean checkUserManageRights(String userEppn, SignBook signBook) { if (signBook.getCreateBy().getEppn().equals(userEppn) || signBook.getCreateBy().getEppn().equals("system")) { return true; @@ -300,7 +300,7 @@ public void archivesFiles(SignBook signBook, String authUserEppn) throws EsupSig } } - public void exportFilesToTarget(SignBook signBook, String authUserEppn) throws EsupSignatureException { + public void exportFilesToTarget(SignBook signBook, String authUserEppn) throws EsupSignatureException, EsupSignatureFsException { if(signBook.getLiveWorkflow() != null && signBook.getLiveWorkflow().getTargets().size() > 0) { signRequestService.sendSignRequestsToTarget(signBook.getSignRequests(), signBook.getName(), signBook.getLiveWorkflow().getTargets(), authUserEppn); signBook.setStatus(SignRequestStatus.exported); diff --git a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java index a7bd7e072..1701b8d3e 100644 --- a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java +++ b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java @@ -763,11 +763,11 @@ public void completeSignRequests(List signRequests, String authUser } } - public void sendSignRequestsToTarget(List signRequests, String title, List targets, String authUserEppn) throws EsupSignatureException { + public void sendSignRequestsToTarget(List signRequests, String title, List targets, String authUserEppn) throws EsupSignatureException, EsupSignatureFsException { boolean allTargetsDone = true; for(Target target : targets) { if(!target.getTargetOk()) { - DocumentIOType documentIOType = target.getTargetType(); + DocumentIOType documentIOType = fsAccessFactory.getPathIOType(target.getTargetUri()); String targetUrl = target.getTargetUri(); if (documentIOType != null && !documentIOType.equals(DocumentIOType.none)) { if (documentIOType.equals(DocumentIOType.mail)) { @@ -789,7 +789,7 @@ public void sendSignRequestsToTarget(List signRequests, String titl } } else { for (SignRequest signRequest : signRequests) { - if (target.getTargetType().equals(DocumentIOType.rest)) { + if (fsAccessFactory.getPathIOType(target.getTargetUri()).equals(DocumentIOType.rest)) { RestTemplate restTemplate = new RestTemplate(); SignRequestStatus status = SignRequestStatus.completed; if (signRequest.getRecipientHasSigned().values().stream().anyMatch(action -> action.getActionType().equals(ActionType.refused))) { @@ -821,7 +821,7 @@ public void sendSignRequestsToTarget(List signRequests, String titl target.setTargetOk(true); updateStatus(signRequest, signRequest.getStatus(), "Exporté vers " + targetUrl, "SUCCESS", authUserEppn, authUserEppn); } catch (EsupSignatureFsException e) { - logger.error("fs export fail : " + target.getTargetUri(), e); + logger.error("fs export fail : " + target.getProtectedTargetUri(), e); allTargetsDone = false; } } diff --git a/src/main/java/org/esupportail/esupsignature/service/TargetService.java b/src/main/java/org/esupportail/esupsignature/service/TargetService.java index 3a2bd64ff..c0fa0071e 100644 --- a/src/main/java/org/esupportail/esupsignature/service/TargetService.java +++ b/src/main/java/org/esupportail/esupsignature/service/TargetService.java @@ -3,7 +3,6 @@ import org.esupportail.esupsignature.entity.SignBook; import org.esupportail.esupsignature.entity.Target; import org.esupportail.esupsignature.entity.enums.DocumentIOType; -import org.esupportail.esupsignature.exception.EsupSignatureException; import org.esupportail.esupsignature.exception.EsupSignatureFsException; import org.esupportail.esupsignature.repository.TargetRepository; import org.esupportail.esupsignature.service.interfaces.fs.FsAccessFactory; @@ -27,19 +26,18 @@ public Target getById(Long id) { } @Transactional - public Target createTarget(String targetUri) throws EsupSignatureFsException { + public Target createTarget(String targetUri) { Target target = new Target(); - target.setTargetType(fsAccessFactory.getPathIOType(targetUri)); target.setTargetUri(targetUri); targetRepository.save(target); return target; } - public void copyTargets(List targets, SignBook signBook, List targetEmails) throws EsupSignatureFsException, EsupSignatureException { + public void copyTargets(List targets, SignBook signBook, List targetEmails) throws EsupSignatureFsException { signBook.getLiveWorkflow().getTargets().clear(); for(Target target : targets) { - if(target.getTargetType() != DocumentIOType.none && target.getTargetType() != DocumentIOType.mail && target.getTargetUri() != null && !target.getTargetUri().isEmpty()) { + if(fsAccessFactory.getPathIOType(target.getTargetUri()) != DocumentIOType.mail && target.getTargetUri() != null && !target.getTargetUri().isEmpty()) { signBook.getLiveWorkflow().getTargets().add(createTarget(target.getTargetUri())); } } @@ -49,10 +47,10 @@ public void copyTargets(List targets, SignBook signBook, List ta public Target addTargetEmails(List targetEmails, List targets) throws EsupSignatureFsException { StringBuilder targetEmailsToAdd = new StringBuilder(); for(Target target1 : targets) { - if(target1.getTargetType().equals(DocumentIOType.mail)) { - for(String targetEmail : target1.getTargetUri().split(";")) { + if(fsAccessFactory.getPathIOType(target1.getTargetUri()).equals(DocumentIOType.mail)) { + for(String targetEmail : target1.getTargetUri().replace("mailto:", "").split(",")) { if (!targetEmailsToAdd.toString().contains(targetEmail)) { - targetEmailsToAdd.append(targetEmail).append(";"); + targetEmailsToAdd.append(targetEmail).append(","); } } } @@ -60,12 +58,13 @@ public Target addTargetEmails(List targetEmails, List targets) t if(targetEmails != null) { for (String targetEmail : targetEmails) { if (!targetEmailsToAdd.toString().contains(targetEmail)) { - targetEmailsToAdd.append(targetEmail).append(";"); + targetEmailsToAdd.append(targetEmail).append(","); } } } if(!targetEmailsToAdd.toString().isEmpty()) { - return createTarget(targetEmailsToAdd.toString()); + targetEmailsToAdd.insert(0,"mailto:"); + return createTarget(targetEmailsToAdd.substring(0, targetEmailsToAdd.length() - 1)); } else { return null; } diff --git a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java index 9629aeb12..551feffb9 100644 --- a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java +++ b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java @@ -89,8 +89,6 @@ public void initCreatorWorkflow() { workflow.setDescription("Signature du créateur de la demande"); workflow.setCreateDate(new Date()); workflow.setCreateBy(userService.getSystemUser()); - workflow.setSourceType(DocumentIOType.none); -// workflow.setTargetType(DocumentIOType.none); WorkflowStep workflowStep = workflowStepService.createWorkflowStep("Ma signature", false, SignType.pdfImageStamp, creator.getEmail()); workflow.getWorkflowSteps().add(workflowStep); workflowRepository.save(workflow); @@ -113,7 +111,6 @@ public void copyClassWorkflowsIntoDatabase() throws EsupSignatureException { toUpdateWorkflow.getRoles().addAll(classWorkflow.getRoles()); toUpdateWorkflow.setDescription(classWorkflow.getDescription()); toUpdateWorkflow.setTitle(classWorkflow.getTitle()); - toUpdateWorkflow.setSourceType(classWorkflow.getSourceType()); toUpdateWorkflow.setDocumentsSourceUri(classWorkflow.getDocumentsSourceUri()); toUpdateWorkflow.getTargets().addAll(classWorkflow.getTargets()); toUpdateWorkflow.setAuthorizedShareTypes(classWorkflow.getAuthorizedShareTypes()); @@ -212,7 +209,6 @@ public Workflow createWorkflow(String title, String description, User user) thro workflow.setCreateBy(user); workflow.setCreateDate(new Date()); workflow.getManagers().removeAll(Collections.singleton("")); - workflow.setSourceType(DocumentIOType.none); workflowRepository.save(workflow); return workflow; } else { @@ -393,7 +389,6 @@ public Workflow getById(Long id) { @Transactional public Workflow initWorkflow(User user, Long id, String name) { Workflow workflow = getById(id); - workflow.setSourceType(DocumentIOType.none); workflow.setCreateBy(user); workflow.setName(name); workflow.setDescription(name); @@ -520,7 +515,6 @@ public Workflow update(Workflow workflow, User user, String[] types, List !shareTypes.contains(shareType)); } - workflowToUpdate.setSourceType(workflow.getSourceType()); workflowToUpdate.getTargets().addAll(workflow.getTargets()); if(!workflow.getDocumentsSourceUri().contains("********")) { workflowToUpdate.setDocumentsSourceUri(workflow.getDocumentsSourceUri()); @@ -550,10 +544,10 @@ public List getWorkflowStepsFromSignRequest(SignRequest signReques } @Transactional - public boolean addTarget(Long id, String documentsTargetUri) throws EsupSignatureFsException, EsupSignatureException { + public boolean addTarget(Long id, String documentsTargetUri) throws EsupSignatureFsException { Workflow workflow = getById(id); DocumentIOType targetType = fsAccessFactory.getPathIOType(documentsTargetUri); - if(!targetType.equals("mail") || workflow.getTargets().stream().map(Target::getTargetType).noneMatch(tt -> tt.equals(DocumentIOType.mail))) { + if(!targetType.equals("mail") || workflow.getTargets().stream().map(Target::getTargetUri).noneMatch(tt -> tt.contains("mailto"))) { Target target = targetService.createTarget(documentsTargetUri); workflow.getTargets().add(target); return true; diff --git a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java index 9e1fae122..1598e7f73 100644 --- a/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java +++ b/src/main/java/org/esupportail/esupsignature/service/interfaces/fs/FsAccessFactory.java @@ -8,8 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; +import java.net.URI; @Service public class FsAccessFactory { @@ -35,6 +34,7 @@ public void setVfsAccessImpl(VfsAccessImpl vfsAccessImpl) { public void setCmisAccessImpl(CmisAccessImpl cmisAccessImpl) { this.cmisAccessImpl = cmisAccessImpl; } + public FsAccessService getFsAccessService(String uri) throws EsupSignatureFsException { DocumentIOType type = getPathIOType(uri); switch (type) { @@ -49,33 +49,27 @@ public FsAccessService getFsAccessService(String uri) throws EsupSignatureFsExce } } - public List getFsAccessServices() { - List fsAccessServices = new ArrayList<>(); - if(smbAccessImpl != null) { - fsAccessServices.add(smbAccessImpl); - } - if(vfsAccessImpl != null) { - fsAccessServices.add(vfsAccessImpl); - } - if(cmisAccessImpl != null) { - fsAccessServices.add(cmisAccessImpl); - } - return fsAccessServices; - } - public DocumentIOType getPathIOType(String path) throws EsupSignatureFsException { try { - var uri = new java.net.URI(path); - switch (uri.getScheme()) { - case "smb": return DocumentIOType.smb; - case "cmis": return DocumentIOType.cmis; - case "file": - case "sftp": - case "ftp": - return DocumentIOType.vfs; - case "http": - case "https": - return DocumentIOType.rest; + URI uri = new URI(path); + if(uri.getScheme() != null) { + switch (uri.getScheme()) { + case "mailto": + return DocumentIOType.mail; + case "smb": + return DocumentIOType.smb; + case "cmis": + return DocumentIOType.cmis; + case "file": + case "sftp": + case "ftp": + return DocumentIOType.vfs; + case "http": + case "https": + return DocumentIOType.rest; + } + } else { + return DocumentIOType.vfs; } throw new EsupSignatureFsException("unknown protocol for url " + path); } catch (java.net.URISyntaxException e) { diff --git a/src/main/java/org/esupportail/esupsignature/service/interfaces/workflow/DefaultWorkflow.java b/src/main/java/org/esupportail/esupsignature/service/interfaces/workflow/DefaultWorkflow.java index 9942ff11f..96e64701a 100644 --- a/src/main/java/org/esupportail/esupsignature/service/interfaces/workflow/DefaultWorkflow.java +++ b/src/main/java/org/esupportail/esupsignature/service/interfaces/workflow/DefaultWorkflow.java @@ -4,7 +4,6 @@ import org.esupportail.esupsignature.entity.User; import org.esupportail.esupsignature.entity.Workflow; import org.esupportail.esupsignature.entity.WorkflowStep; -import org.esupportail.esupsignature.entity.enums.DocumentIOType; import org.esupportail.esupsignature.exception.EsupSignatureUserException; import org.esupportail.esupsignature.service.RecipientService; import org.esupportail.esupsignature.service.UserService; @@ -37,11 +36,6 @@ public String getDescription() { return "Workflow par défaut"; } - @Override - public DocumentIOType getSourceType() { - return DocumentIOType.none; - } - @Override public List getTargets() { return new ArrayList<>(); diff --git a/src/main/java/org/esupportail/esupsignature/service/mail/MailService.java b/src/main/java/org/esupportail/esupsignature/service/mail/MailService.java index 6751c6b20..f07ae64cb 100644 --- a/src/main/java/org/esupportail/esupsignature/service/mail/MailService.java +++ b/src/main/java/org/esupportail/esupsignature/service/mail/MailService.java @@ -342,7 +342,7 @@ public void sendFile(String title, List signRequests, String target mimeMessage.addInline("logo-univ", new ClassPathResource("/static/images/logo-univ.png", MailService.class).getFile()); mimeMessage.setSubject("Nouveau document signé à télécharger : " + title); mimeMessage.setFrom(mailConfig.getMailFrom()); - mimeMessage.setTo(targetUri.split(";")); + mimeMessage.setTo(targetUri.replace("mailto:", "").split(",")); mailSender.send(mimeMessage.getMimeMessage()); } diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java b/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java index a3a7b8aec..20f7a2abb 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/admin/WorkflowAdminController.java @@ -213,7 +213,7 @@ public String getFileFromSource(@ModelAttribute("authUserEppn") String authUserE @PostMapping(value = "/add-target/{id}") public String addTarget(@PathVariable("id") Long id, @RequestParam("documentsTargetUri") String documentsTargetUri, - RedirectAttributes redirectAttributes) throws EsupSignatureException, EsupSignatureFsException { + RedirectAttributes redirectAttributes) throws EsupSignatureFsException { if(workflowService.addTarget(id, documentsTargetUri)) { redirectAttributes.addFlashAttribute("message", new JsonMessage("info", "Destination ajoutée")); } else { diff --git a/src/main/resources/static/js/modules/ui/workflows/WorkflowUi.js b/src/main/resources/static/js/modules/ui/workflows/WorkflowUi.js index db26d55cd..789c13d6c 100644 --- a/src/main/resources/static/js/modules/ui/workflows/WorkflowUi.js +++ b/src/main/resources/static/js/modules/ui/workflows/WorkflowUi.js @@ -2,20 +2,12 @@ export class WorkflowUi { constructor() { console.info("Starting workflow UI"); - this.sourceTypeSelect = $("#sourceTypeSelect"); - this.targetTypeSelect = $("#targetTypeSelect"); this.visibility = $("#visibility"); - this.sourceUri = document.getElementById("documentsSourceUriDiv"); - if (this.sourceTypeSelect != null && this.sourceTypeSelect.value === "none") { - this.sourceUri.style.display = "none"; - } this.initListeners(); } initListeners() { - this.sourceTypeSelect.on('change', e => this.toggleSourceSelector()); - $(document).ready(e => this.initDelListerner()); - ; + $(document).ready(e => this.initDeleteListener()); $("#delete-button").on("click", e => this.confirmDelete()); this.visibility.on("change", function(e){ if(this.checked) { @@ -41,7 +33,7 @@ export class WorkflowUi { }) } - initDelListerner() { + initDeleteListener() { let self = this; $(".del-step-btn").each(function(){ $(this).on("click", e => self.launchDelete(e)); @@ -56,20 +48,4 @@ export class WorkflowUi { }); } - toggleSourceSelector() { - console.log("toggle"); - if (this.sourceTypeSelect.value !== "none") { - this.sourceUri.style.display = "block"; - } else { - this.sourceUri.style.display = "none"; - } - } - - toggleTargetSelector() { - if (this.targetTypeSelect.value !== "none") { - this.targetUri.style.display = "block"; - } else { - this.targetUri.style.display = "none"; - } - } } \ No newline at end of file diff --git a/src/main/resources/templates/admin/workflows/list.html b/src/main/resources/templates/admin/workflows/list.html index fb15cd7c3..1fc9777a8 100644 --- a/src/main/resources/templates/admin/workflows/list.html +++ b/src/main/resources/templates/admin/workflows/list.html @@ -89,7 +89,7 @@ th:href="'/admin/workflows/export/' + ${workflow.id}"> Exporter le circuit - + Scanner la source Nombre de demandes pour ce circuit :
-
- - -

-
+
- - - - -
- - diff --git a/src/main/resources/templates/user/signrequests/cards/stepscard.html b/src/main/resources/templates/user/signrequests/cards/stepscard.html index 11b6a4a2c..ad52977a3 100644 --- a/src/main/resources/templates/user/signrequests/cards/stepscard.html +++ b/src/main/resources/templates/user/signrequests/cards/stepscard.html @@ -93,9 +93,7 @@
Export vers :
-
-
- +
diff --git a/src/main/resources/templates/user/signrequests/show.html b/src/main/resources/templates/user/signrequests/show.html index c09f48280..3942cb6b6 100644 --- a/src/main/resources/templates/user/signrequests/show.html +++ b/src/main/resources/templates/user/signrequests/show.html @@ -601,10 +601,10 @@

-
+
diff --git a/src/main/resources/templates/user/wizard/wiz-setup-workflow.html b/src/main/resources/templates/user/wizard/wiz-setup-workflow.html index 36edb662b..98785fa70 100644 --- a/src/main/resources/templates/user/wizard/wiz-setup-workflow.html +++ b/src/main/resources/templates/user/wizard/wiz-setup-workflow.html @@ -90,10 +90,10 @@

Démarrage du circuit

-
+
diff --git a/src/main/resources/update_1.15.1.sql b/src/main/resources/update_1.15.1.sql new file mode 100644 index 000000000..d2a409cff --- /dev/null +++ b/src/main/resources/update_1.15.1.sql @@ -0,0 +1,3 @@ +-- supprimer les contrainte unique sur les sign_request_params + +alter table target drop column target_type; \ No newline at end of file diff --git a/src/test/java/org/esupportail/esupsignature/DSSTest.java b/src/test/java/org/esupportail/esupsignature/DSSTest.java index dce2a2813..443ff830b 100644 --- a/src/test/java/org/esupportail/esupsignature/DSSTest.java +++ b/src/test/java/org/esupportail/esupsignature/DSSTest.java @@ -10,8 +10,6 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import java.io.IOException; - import static org.junit.Assume.assumeTrue; @RunWith(SpringRunner.class) @@ -25,12 +23,11 @@ public class DSSTest { private OJService ojService; @Test - public void testDss() throws IOException { + public void testDss() { assumeTrue("DSS not configured", ojService != null); logger.info("Updating DSS OJ..."); ojService.getCertificats(); logger.info("Update done."); - assumeTrue("dss cache not fresh !", ojService.checkOjFreshness()); } } diff --git a/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java b/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java index 05bc5f465..939076177 100644 --- a/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java +++ b/src/test/java/org/esupportail/esupsignature/FsAccessServiceTest.java @@ -35,7 +35,7 @@ public void testSmbAccessImpl() throws EsupSignatureFsException { FsAccessService fsAccessService = fsAccessFactory.getFsAccessService("smb://test"); assumeTrue("SMB not configured", fsAccessService != null && fsAccessService.getUri() != null); try { - if (fsAccessService.cd("/") == null) { + if (fsAccessService.cd(fsAccessService.getUri()) == null) { logger.error(fsAccessService.getDriveName() + " unable to change to / directory. Please check configuration"); fail(); } else { @@ -70,7 +70,7 @@ public void testVfsAccessImpl() throws EsupSignatureFsException { FsAccessService fsAccessService = fsAccessFactory.getFsAccessService("ftp://test"); assumeTrue("vfs not configured", fsAccessService != null && fsAccessService.getUri() != null); try { - if (fsAccessService.cd("/") == null) { + if (fsAccessService.cd("file://tmp/") == null) { logger.error(fsAccessService.getDriveName() + " unable to change to / directory. Please check configuration"); fail(); } else { From 25ab442c55ac72ea0be5a544308b2cdcb28b99e4 Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Tue, 26 Oct 2021 14:59:14 +0200 Subject: [PATCH 10/22] cleanning after multi target --- .../esupsignature/config/fs/FsConfig.java | 4 +- .../esupsignature/config/fs/FsProperties.java | 10 ++--- .../repository/SignBookRepository.java | 3 +- .../custom/SignBookRepositoryCustom.java | 9 ---- .../impl/SignBookRepositoryImpl.java | 41 ------------------- .../js/modules/ui/signrequests/SignUi.js | 1 - .../templates/admin/workflows/update.html | 2 - .../templates/managers/workflows/update.html | 12 ------ .../templates/user/signrequests/show.html | 1 + .../esupsignature/FsAccessServiceTest.java | 2 +- 10 files changed, 9 insertions(+), 76 deletions(-) delete mode 100644 src/main/java/org/esupportail/esupsignature/repository/custom/SignBookRepositoryCustom.java delete mode 100644 src/main/java/org/esupportail/esupsignature/repository/impl/SignBookRepositoryImpl.java diff --git a/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java b/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java index 865a92600..9b81e0a97 100644 --- a/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java +++ b/src/main/java/org/esupportail/esupsignature/config/fs/FsConfig.java @@ -52,9 +52,7 @@ public Properties smbProperties(){ public VfsAccessImpl vfsAccessImpl(){ VfsAccessImpl vfsAccessImpl = new VfsAccessImpl(); vfsAccessImpl.setDriveName("VFS"); - vfsAccessImpl.setUri(fsProperties.getVfsUri()); - //vfsAccessImpl.setLogin(login); - //vfsAccessImpl.setPassword(password); + vfsAccessImpl.setUri(fsProperties.getVfsTestUri()); return vfsAccessImpl; } diff --git a/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java b/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java index 3591cc8f7..1e2d11079 100644 --- a/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java +++ b/src/main/java/org/esupportail/esupsignature/config/fs/FsProperties.java @@ -9,7 +9,7 @@ public class FsProperties { private String smbLogin; private String smbPassword; private String smbDomain; - private String vfsUri; + private String vfsTestUri; private String cmisUri; private String cmisLogin; private String cmisPassword; @@ -48,12 +48,12 @@ public void setSmbDomain(String smbDomain) { this.smbDomain = smbDomain; } - public String getVfsUri() { - return vfsUri; + public String getVfsTestUri() { + return vfsTestUri; } - public void setVfsUri(String vfsUri) { - this.vfsUri = vfsUri; + public void setVfsTestUri(String vfsTestUri) { + this.vfsTestUri = vfsTestUri; } public String getCmisUri() { diff --git a/src/main/java/org/esupportail/esupsignature/repository/SignBookRepository.java b/src/main/java/org/esupportail/esupsignature/repository/SignBookRepository.java index e133b1e34..2b68ce02c 100644 --- a/src/main/java/org/esupportail/esupsignature/repository/SignBookRepository.java +++ b/src/main/java/org/esupportail/esupsignature/repository/SignBookRepository.java @@ -5,14 +5,13 @@ import org.esupportail.esupsignature.entity.User; import org.esupportail.esupsignature.entity.Workflow; import org.esupportail.esupsignature.entity.enums.SignRequestStatus; -import org.esupportail.esupsignature.repository.custom.SignBookRepositoryCustom; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; import java.util.List; -public interface SignBookRepository extends CrudRepository, SignBookRepositoryCustom { +public interface SignBookRepository extends CrudRepository { List findByCreateByEppn(String createByEppn); List findByStatus(SignRequestStatus signRequestStatus); @Query("select count(s.id) from SignBook s join s.liveWorkflow.currentStep.recipients r where s.status = 'pending' and r.user.eppn = :recipientUserEppn and r.signed is false") diff --git a/src/main/java/org/esupportail/esupsignature/repository/custom/SignBookRepositoryCustom.java b/src/main/java/org/esupportail/esupsignature/repository/custom/SignBookRepositoryCustom.java deleted file mode 100644 index 79694746f..000000000 --- a/src/main/java/org/esupportail/esupsignature/repository/custom/SignBookRepositoryCustom.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.esupportail.esupsignature.repository.custom; - -import org.esupportail.esupsignature.entity.SignBook; - -import java.util.List; - -public interface SignBookRepositoryCustom { - List findByNotCreateBy(String createBy); -} diff --git a/src/main/java/org/esupportail/esupsignature/repository/impl/SignBookRepositoryImpl.java b/src/main/java/org/esupportail/esupsignature/repository/impl/SignBookRepositoryImpl.java deleted file mode 100644 index 860a04c7c..000000000 --- a/src/main/java/org/esupportail/esupsignature/repository/impl/SignBookRepositoryImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.esupportail.esupsignature.repository.impl; - -import org.esupportail.esupsignature.entity.SignBook; -import org.esupportail.esupsignature.repository.custom.SignBookRepositoryCustom; -import org.springframework.stereotype.Repository; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.criteria.*; -import java.util.ArrayList; -import java.util.List; - -@Repository -public class SignBookRepositoryImpl implements SignBookRepositoryCustom { - - @PersistenceContext - private EntityManager entityManager; - - @Override - public List findByNotCreateBy(String createBy) { - CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); - CriteriaQuery query = criteriaBuilder.createQuery(SignBook.class); - Root queryRoot = query.from(SignBook.class); - - final List predicates = new ArrayList<>(); - final List orders = new ArrayList<>(); - - predicates.add(criteriaBuilder.and(criteriaBuilder.notEqual(queryRoot.get("createBy"), createBy))); - - orders.add(criteriaBuilder.desc(queryRoot.get("signBookType"))); - orders.add(criteriaBuilder.asc(queryRoot.get("name"))); - - query.select(queryRoot); - query.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]))); - query.orderBy(orders); - - return entityManager.createQuery(query).getResultList(); - } - - -} diff --git a/src/main/resources/static/js/modules/ui/signrequests/SignUi.js b/src/main/resources/static/js/modules/ui/signrequests/SignUi.js index 816d5484f..cce4b49ee 100644 --- a/src/main/resources/static/js/modules/ui/signrequests/SignUi.js +++ b/src/main/resources/static/js/modules/ui/signrequests/SignUi.js @@ -28,7 +28,6 @@ export class SignUi { if(status !== "exported") { this.initReportModal(); } - } initListeners() { diff --git a/src/main/resources/templates/admin/workflows/update.html b/src/main/resources/templates/admin/workflows/update.html index b51f86662..6442efe51 100644 --- a/src/main/resources/templates/admin/workflows/update.html +++ b/src/main/resources/templates/admin/workflows/update.html @@ -1,8 +1,6 @@ - - - - + @@ -39,21 +53,6 @@ - - - - - - - - - - - - - - - diff --git a/src/main/resources/templates/fragments/sides/side-home.html b/src/main/resources/templates/fragments/sides/side-home.html index 5892a9816..fc1aa94c1 100644 --- a/src/main/resources/templates/fragments/sides/side-home.html +++ b/src/main/resources/templates/fragments/sides/side-home.html @@ -7,7 +7,7 @@ -