Creates a promiscuous HostnameVerifier that accepts all host names without further verification. - Java Network

Java examples for Network:SSL

Description

Creates a promiscuous HostnameVerifier that accepts all host names without further verification.

Demo Code


//package com.java2s;

import javax.net.ssl.HostnameVerifier;

import javax.net.ssl.SSLSession;

public class Main {
    /**//from w ww. j a  v a 2  s  .com
     * Creates a promiscuous {@link HostnameVerifier} that accepts all host
     * names without further verification.
     * 
     * @return
     */
    public static HostnameVerifier allowAllHostNames() {
        // Install host name verifier that always approves host names
        HostnameVerifier alwaysAllowHostVerifier = new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        return alwaysAllowHostVerifier;
    }
}

Related Tutorials