Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

groovy

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 is working perfectly fine when i run the same code in a JAVA project but Grails is not compiling the code and giving error -- No expression for the array constructor call on the first line.

like image 215
Chetan Hallan Avatar asked Mar 29 '16 06:03

Chetan Hallan


1 Answers

The following piece of code 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[] 

Have a look at this question.

like image 63
Opal Avatar answered Nov 07 '22 09:11

Opal