Using TrustManager [] trustAllCerts = new TrustManager [] in Grails

How can I use the following code in grails -

TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { return; } public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { return; } } }; 

The above code works fine when I run the same code in a JAVA project, but Grails does not compile the code and does not give an error - There is no expression to call the array constructor on the first line.

+5
source share
1 answer

The following code snippet will work:

 import javax.net.ssl.X509TrustManager import javax.net.ssl.TrustManager import java.security.cert.X509Certificate import java.security.cert.CertificateException def trustAllCerts = [ new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null } public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { } public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { } } ] as TrustManager[] 

Take a look at this question.

+5
source

Source: https://habr.com/ru/post/1245959/


All Articles