-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'verifica-firma-eidas-1.21.0' into 131516_verifica-firma-ei…
…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
Showing
5 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/main/java/it/eng/parer/eidas/core/helper/ApacheClientHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test2 |