forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Disable SSL check for specific discofeed requests * Fixed checkstyle issues * Do not throw error in private constructor * Fixed failing IT - ssl check wasn't disabled * Ignore integration test which is trying to connect to our private network.
- Loading branch information
1 parent
a2254c2
commit 2553357
Showing
5 changed files
with
125 additions
and
5 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
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
63 changes: 63 additions & 0 deletions
63
dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/ClarinUtils.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,63 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.app.rest.utils; | ||
|
||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.SecureRandom; | ||
import javax.net.ssl.HttpsURLConnection; | ||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Collection of utility methods for clarin customized operations | ||
* | ||
* @author Milan Majchrak (dspace at dataquest.sk) | ||
*/ | ||
@Component | ||
public class ClarinUtils { | ||
|
||
private ClarinUtils() { | ||
} | ||
|
||
/** | ||
* Disables SSL certificate validation for the given connection | ||
* | ||
* @param connection | ||
*/ | ||
public static void disableCertificateValidation(HttpsURLConnection connection) { | ||
try { | ||
// Create a TrustManager that trusts all certificates | ||
TrustManager[] trustAllCerts = { new X509TrustManager() { | ||
public java.security.cert.X509Certificate[] getAcceptedIssuers() { | ||
return null; | ||
} | ||
|
||
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { | ||
} | ||
|
||
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { | ||
} } | ||
}; | ||
|
||
// Install the TrustManager | ||
SSLContext sslContext = SSLContext.getInstance("SSL"); | ||
sslContext.init(null, trustAllCerts, new SecureRandom()); | ||
connection.setSSLSocketFactory(sslContext.getSocketFactory()); | ||
|
||
// Set a HostnameVerifier that accepts all hostnames | ||
connection.setHostnameVerifier((hostname, session) -> true); | ||
|
||
} catch (NoSuchAlgorithmException | KeyManagementException e) { | ||
throw new RuntimeException("Error disabling SSL certificate validation", e); | ||
} | ||
} | ||
} |
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