Skip to content

Commit

Permalink
Merge pull request #441 from EsupPortail/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
dlemaignent authored Jul 11, 2024
2 parents 6f912b0 + 8973152 commit 931d218
Show file tree
Hide file tree
Showing 26 changed files with 554 additions and 269 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>
<groupId>org.esupportail</groupId>
<artifactId>esup-signature</artifactId>
<version>1.29.10</version>
<version>1.29.12-SNAPSHOT</version>
<name>esup-signature</name>
<properties>
<startClass>org.esupportail.esupsignature.EsupSignatureApplication</startClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WebAppConfig implements WebMvcConfigurer {

public WebAppConfig(GlobalProperties globalProperties) {
this.globalProperties = globalProperties;
}
}

@Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ private void setAuthorizeRequests(HttpSecurity http) throws Exception {
}
String finalHasIpAddresses = hasIpAddresses.toString();
if(StringUtils.hasText(finalHasIpAddresses)) {
http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests.requestMatchers(antMatcher("/ws/**")).access(new WebExpressionAuthorizationManager(finalHasIpAddresses)));
http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests.requestMatchers(antMatcher("/actuator/**")).access(new WebExpressionAuthorizationManager(finalHasIpAddresses)));
http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests.requestMatchers(antMatcher("/ws/**"))
.access(new WebExpressionAuthorizationManager(finalHasIpAddresses)));
http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests.requestMatchers(antMatcher("/actuator/**"))
.access(new WebExpressionAuthorizationManager(finalHasIpAddresses)));
}
// http.authorizeRequests().requestMatchers("/ws/**").access("hasRole('WS')").and().addFilter(apiKeyFilter());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import eu.europa.esig.dss.tsl.alerts.handlers.log.LogOJUrlChangeAlertHandler;
import eu.europa.esig.dss.tsl.alerts.handlers.log.LogTLExpirationAlertHandler;
import eu.europa.esig.dss.tsl.alerts.handlers.log.LogTLSignatureErrorAlertHandler;
import eu.europa.esig.dss.tsl.cache.CacheCleaner;
import eu.europa.esig.dss.tsl.function.OfficialJournalSchemeInformationURI;
import eu.europa.esig.dss.tsl.job.TLValidationJob;
import eu.europa.esig.dss.tsl.source.LOTLSource;
Expand Down Expand Up @@ -241,7 +242,7 @@ public TrustedListsCertificateSource trustedListSource() {
}

@Bean
public TLValidationJob tlValidationJob(TrustedListsCertificateSource trustedListSource, LOTLSource europeanLOTL, DSSFileLoader offlineLoader, DSSFileLoader onlineLoader) {
public TLValidationJob tlValidationJob(TrustedListsCertificateSource trustedListSource, LOTLSource europeanLOTL, DSSFileLoader offlineLoader, DSSFileLoader onlineLoader, CacheCleaner cacheCleaner) {
TLValidationJob tlValidationJob = new TLValidationJob();
if(!dssProperties.getMultiThreadTlValidation()) {
tlValidationJob.setExecutorService(Executors.newSingleThreadExecutor());
Expand All @@ -253,9 +254,20 @@ public TLValidationJob tlValidationJob(TrustedListsCertificateSource trustedList
tlValidationJob.setLOTLAlerts(Arrays.asList(ojUrlAlert(europeanLOTL), lotlLocationAlert(europeanLOTL)));
tlValidationJob.setTLAlerts(Arrays.asList(tlSigningAlert(), tlExpirationDetection()));
tlValidationJob.setDebug(false);
tlValidationJob.setCacheCleaner(cacheCleaner);
return tlValidationJob;
}

@Bean
public CacheCleaner cacheCleaner(DSSFileLoader offlineLoader) {
CacheCleaner cacheCleaner = new CacheCleaner();
cacheCleaner.setCleanMemory(true);
cacheCleaner.setCleanFileSystem(true);
cacheCleaner.setDSSFileLoader(offlineLoader);

return cacheCleaner;
}

@Bean
public File tlCacheDirectory() {
String tmpDirectory = System.getProperty("java.io.tmpdir");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,37 @@ public String getCurrentOjUrl() {
return dssProperties.getOjUrl();
}

public void getCertificats() throws IOException {
public void initializeOj() throws IOException {
logger.info("Updating DSS OJ offline...");
ojContentKeyStore.addAllCertificatesToKeyStore(myTrustedCertificateSource.getCertificates());
tlValidationJob.offlineRefresh();
logger.info("Updating DSS OJ offline done.");
if(refreshIsNeeded()) {
logger.info("Updating DSS OJ online...");
tlValidationJob.onlineRefresh();
logger.info("Updating DSS OJ online done.");
refreshOj();
}
}

public void refreshOj() {
logger.info("Updating DSS OJ online...");
tlValidationJob.onlineRefresh();
logger.info("Updating DSS OJ online done.");
}

public boolean refreshIsNeeded() throws IOException {
TLValidationJobSummary summary = tlValidationJob.getSummary();
if(summary == null) return true;
boolean checkTl = false;
for (LOTLInfo lotlInfo : summary.getLOTLInfos()) {
if(!lotlInfo.getValidationCacheInfo().isValid()
|| lotlInfo.getValidationCacheInfo().isRefreshNeeded()
|| lotlInfo.getParsingCacheInfo().isRefreshNeeded()
|| lotlInfo.getDownloadCacheInfo().isRefreshNeeded()) {
|| !lotlInfo.getParsingCacheInfo().isSynchronized()
|| !lotlInfo.getDownloadCacheInfo().isSynchronized()) {
checkTl = true;
}
}
for (TLInfo tlInfo : summary.getOtherTLInfos()) {
if(!tlInfo.getValidationCacheInfo().isValid()
|| tlInfo.getValidationCacheInfo().isRefreshNeeded()
|| tlInfo.getParsingCacheInfo().isRefreshNeeded()
|| tlInfo.getDownloadCacheInfo().isRefreshNeeded()) {
|| !tlInfo.getParsingCacheInfo().isSynchronized()
|| !tlInfo.getDownloadCacheInfo().isSynchronized()) {
checkTl = true;
}
}
Expand All @@ -140,7 +142,7 @@ public boolean refreshIsNeeded() throws IOException {
@EventListener(ContextRefreshedEvent.class)
public void onApplicationEvent(ContextRefreshedEvent event) {
try {
getCertificats();
initializeOj();
} catch (IOException e) {
logger.error("Error updating certificates", e);
}
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/org/esupportail/esupsignature/dto/HttpSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.esupportail.esupsignature.dto;

import java.util.Date;

public class HttpSession {

Date createdDate;

Date lastRequest;

String sessionId;

String remoteIp;

String originRequestUri;

String userEppn;

boolean expired;

public Date getCreatedDate() {
return createdDate;
}

public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}

public Date getLastRequest() {
return lastRequest;
}

public void setLastRequest(Date lastRequest) {
this.lastRequest = lastRequest;
}

public String getSessionId() {
return sessionId;
}

public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}

public String getRemoteIp() {
return remoteIp;
}

public void setRemoteIp(String remoteIp) {
this.remoteIp = remoteIp;
}

public String getOriginRequestUri() {
return originRequestUri;
}

public void setOriginRequestUri(String originRequestUri) {
this.originRequestUri = originRequestUri;
}

public String getUserEppn() {
return userEppn;
}

public void setUserEppn(String userEppn) {
this.userEppn = userEppn;
}

public boolean isExpired() {
return expired;
}

public void setExpired(boolean expired) {
this.expired = expired;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1260,13 +1260,14 @@ public List<Long> startWorkflow(Long id, MultipartFile[] multipartFiles, String
logger.info("starting workflow " + id + " by " + createByEppn);
Workflow workflow = workflowService.getById(id);
User user = userService.createUserWithEppn(createByEppn);
SignBook signBook = createSignBook(title, workflow, "", user.getEppn(), true, null);
SignBook signBook = createSignBook(title, workflow, "", user.getEppn(), false, null);
signBook.getLiveWorkflow().setWorkflow(workflow);
for(MultipartFile multipartFile : multipartFiles) {
SignRequest signRequest = signRequestService.createSignRequest(multipartFile.getOriginalFilename(), signBook, createByEppn, createByEppn);
signRequest.getSignRequestParams().addAll(signRequestParamses);
signRequestService.addDocsToSignRequest(signRequest, scanSignatureFields, 0, new ArrayList<>(), multipartFile);
}
signBook.setSubject(generateName(signBook.getId(), workflow, user, false));
if (targetUrls != null) {
for (String targetUrl : targetUrls) {
if (signBook.getLiveWorkflow().getTargets().stream().noneMatch(t -> t != null && t.getTargetUri().equals(targetUrl))) {
Expand Down Expand Up @@ -2034,4 +2035,4 @@ public void addToTeam(SignBook signBook, String userEppn) {
signBook.getTeam().add(user);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public StepStatus sign(SignRequest signRequest, String password, String signWith
}
}
} else {
auditTrailService.addAuditStep(signRequest.getToken(), userEppn, "Signature simple", "Pas de timestamp", date, isViewed, null, null, null);
auditTrailService.addAuditStep(signRequest.getToken(), userEppn, "Visa", "Pas de timestamp", date, isViewed, null, null, null);
}
if (isStepAllSignDone(signRequest.getParentSignBook()) && (reports == null || reports.getSimpleReport().getSignatureIdList().isEmpty())) {
signedInputStream = pdfService.convertGS(pdfService.writeMetadatas(signedInputStream, fileName, signRequest, lastSignLogs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@
import org.esupportail.esupsignature.service.SignBookService;
import org.esupportail.esupsignature.service.UserService;
import org.esupportail.esupsignature.service.WorkflowService;
import org.esupportail.esupsignature.dss.service.DSSService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
Expand All @@ -51,17 +48,14 @@ public class ScheduledTaskService {

private final SignRequestRepository signRequestRepository;

private final DSSService dssService;

public ScheduledTaskService(GlobalProperties globalProperties, SignBookRepository signBookRepository, SignBookService signBookService, TaskService taskService, WorkflowService workflowService, UserService userService, SignRequestRepository signRequestRepository, @Autowired(required = false) DSSService dssService) {
public ScheduledTaskService(GlobalProperties globalProperties, SignBookRepository signBookRepository, SignBookService signBookService, TaskService taskService, WorkflowService workflowService, UserService userService, SignRequestRepository signRequestRepository) {
this.globalProperties = globalProperties;
this.signBookRepository = signBookRepository;
this.signBookService = signBookService;
this.taskService = taskService;
this.workflowService = workflowService;
this.userService = userService;
this.signRequestRepository = signRequestRepository;
this.dssService = dssService;
}


Expand Down Expand Up @@ -137,11 +131,9 @@ public void cleanUploadingSignBooks() {
taskService.initCleanUploadingSignBooks();
}

@Scheduled(cron="00 02 02 * * *")
public void refreshOJKeystore() throws IOException {
if(dssService != null) {
dssService.getCertificats();
}
@Scheduled(cron="0 0 * * * *")
public void refreshOJKeystore() {
taskService.initDssRefresh();
}

@Scheduled(initialDelay = 12000, fixedRate = 300000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.esupportail.esupsignature.service.scheduler;

import org.esupportail.esupsignature.config.GlobalProperties;
import org.esupportail.esupsignature.dss.service.DSSService;
import org.esupportail.esupsignature.entity.SignBook;
import org.esupportail.esupsignature.entity.enums.SignRequestStatus;
import org.esupportail.esupsignature.exception.EsupSignatureRuntimeException;
import org.esupportail.esupsignature.repository.SignBookRepository;
import org.esupportail.esupsignature.service.SignBookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

Expand All @@ -25,8 +27,11 @@ public class TaskService {

private final GlobalProperties globalProperties;

public TaskService(GlobalProperties globalProperties) {
private final DSSService dssService;

public TaskService(GlobalProperties globalProperties, @Autowired(required = false) DSSService dssService) {
this.globalProperties = globalProperties;
this.dssService = dssService;
}

@Resource
Expand All @@ -41,6 +46,7 @@ public TaskService(GlobalProperties globalProperties) {

private boolean enableCleanUploadingSignBookTask = false;

private boolean enableDssRefreshTask = false;

public boolean isEnableArchiveTask() {
return enableArchiveTask;
Expand All @@ -67,6 +73,14 @@ public void setEnableCleanUploadingSignBookTask(boolean enableCleanUploadingSign
this.enableCleanUploadingSignBookTask = enableCleanUploadingSignBookTask;
}

public boolean isEnableDssRefreshTask() {
return enableDssRefreshTask;
}

public void setEnableDssRefreshTask(boolean enableDssRefreshTask) {
this.enableDssRefreshTask = enableDssRefreshTask;
}

@Async
public void initCleanning(String userEppn) {
if(globalProperties.getDelayBeforeCleaning() > -1 && !isEnableCleanTask()) {
Expand Down Expand Up @@ -148,4 +162,19 @@ public void initCleanUploadingSignBooks() {

}

@Async
public void initDssRefresh() {
if(!isEnableDssRefreshTask()) {
setEnableDssRefreshTask(true);
try {
if(dssService != null) {
dssService.refreshOj();
}
} catch (Exception e) {
logger.error("Error updating certificates", e);
}
setEnableDssRefreshTask(false);
}
}

}
Loading

0 comments on commit 931d218

Please sign in to comment.