Skip to content

Commit

Permalink
Merge tag 'verifica-firma-eidas-1.21.0' into 131516_verifica-firma-ei…
Browse files Browse the repository at this point in the history
…das-1.22.0

[maven-release-plugin] copy for tag verifica-firma-eidas-1.21.0

 Conflicts:
	CHANGELOG.md
	CONTAINER-SCAN-REPORT.md
	RELEASE-NOTES.md
	src/main/java/it/eng/parer/eidas/core/bean/CommonsDataHttpClient.java
	src/main/java/it/eng/parer/eidas/core/bean/CustomDataLoaderExt.java
  • Loading branch information
sinattieng committed Jul 11, 2024
2 parents f6bb578 + 5533697 commit 154dc9f
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: GitHub Release
on:
pull_request:
branches:
- main
- master
jobs:
release:
uses: RegioneER/parer-github-template/.github/workflows/github-release.yml@v1
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>verifica-firma-eidas</artifactId>
<version>1.16.1-SNAPSHOT</version>
<version>1.21.0</version>
<packaging>${packaging.type}</packaging>
<name>Verifica Firma EIDAS</name>
<description>Progetto per effettuare firme e validazioni con librerie DSS (EIDAS)</description>
Expand Down Expand Up @@ -44,7 +44,7 @@

<scm>
<developerConnection>scm:git:https://github.com/RegioneER/parer-verifica-firma-eidas.git</developerConnection>
<tag>HEAD</tag>
<tag>verifica-firma-eidas-1.21.0</tag>
</scm>

<distributionManagement>
Expand Down
139 changes: 139 additions & 0 deletions src/main/java/it/eng/parer/eidas/core/helper/ApacheClientHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Engineering Ingegneria Informatica S.p.A.
*
* Copyright (C) 2023 Regione Emilia-Romagna
* <p/>
* This program is free software: you can redistribute it and/or modify it under the terms of
* the GNU Affero General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
* <p/>
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* <p/>
* You should have received a copy of the GNU Affero General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

package it.eng.parer.eidas.core.helper;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeUnit;

import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.apache.hc.client5.http.ssl.TrustAllStrategy;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

@Component
public class ApacheClientHelper {

/*
* Standard client
*/
// default 60 s
@Value("${parer.eidas.uriloader.httpclient.timeout:60}")
long httpClientTimeout;

// default 60 s
@Value("${parer.eidas.uriloader.httpclient.timeoutsocket:60}")
int httpClientSocketTimeout;

// default 4
@Value("${parer.eidas.uriloader.httpclient.connectionsmaxperroute:4}")
int httpClientConnectionsmaxperroute;

// default 40
@Value("${parer.eidas.uriloader.httpclient.connectionsmax:40}")
int httpClientConnectionsmax;

// default 60s
@Value("${parer.eidas.uriloader.httpclient.timetolive:60}")
long httpClientTimeToLive;

// default false
@Value("${parer.eidas.uriloader.httpclient.no-ssl-verify:false}")
boolean noSslVerify;

private CloseableHttpClient client;

@PostConstruct
public void init() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
// client
HttpClientBuilder httpClientBuilder = HttpClients.custom();

final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setConnectionRequestTimeout(httpClientTimeout, TimeUnit.SECONDS)
.setResponseTimeout(httpClientTimeout, TimeUnit.SECONDS)
.setConnectionKeepAlive(TimeValue.ofSeconds(httpClientTimeToLive));

httpClientBuilder.setConnectionManager(getConnectionManager())
.setDefaultRequestConfig(requestConfigBuilder.build());

client = httpClientBuilder.build();
}

private HttpClientConnectionManager getConnectionManager()
throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {

final PoolingHttpClientConnectionManagerBuilder builder = PoolingHttpClientConnectionManagerBuilder.create()
.setDefaultSocketConfig(getSocketConfig()).setMaxConnTotal(httpClientConnectionsmax)
.setMaxConnPerRoute(httpClientConnectionsmaxperroute);
// ssl
if (noSslVerify) {
builder.setSSLSocketFactory(getSSLConnectionSocketFactoryIgnoreSSLValidation());
}

final ConnectionConfig.Builder connectionConfigBuilder = ConnectionConfig.custom()
.setConnectTimeout(httpClientSocketTimeout, TimeUnit.SECONDS)
.setTimeToLive(httpClientTimeToLive, TimeUnit.SECONDS);

final PoolingHttpClientConnectionManager connectionManager = builder.build();
connectionManager.setDefaultConnectionConfig(connectionConfigBuilder.build());

return connectionManager;
}

private SocketConfig getSocketConfig() {
SocketConfig.Builder socketConfigBuilder = SocketConfig.custom();
socketConfigBuilder.setSoTimeout(Timeout.ofSeconds(httpClientTimeout));
return socketConfigBuilder.build();
}

private SSLConnectionSocketFactory getSSLConnectionSocketFactoryIgnoreSSLValidation()
throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
return SSLConnectionSocketFactoryBuilder.create()
.setSslContext(SSLContextBuilder.create().loadTrustMaterial(TrustAllStrategy.INSTANCE).build())
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
}

@PreDestroy
public void destroy() throws IOException {
client.close();
}

public CloseableHttpClient client() {
return client;
}

}
3 changes: 3 additions & 0 deletions src/main/java/it/eng/parer/eidas/core/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ private Constants() {
public static final String STD_MSG_GENERIC_ERROR = "Errore generico";
public static final String STD_MSG_VALIDATION_ERROR = "Chiamata non valida";

public enum URIClientType {
HTTPCLIENT, WEBCLIENT
}
}
1 change: 1 addition & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test2

0 comments on commit 154dc9f

Please sign in to comment.