    001/*
    002 * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.15/src/java/org/apache/commons/ssl/LDAPSocket.java $
    003 * $Revision: 165 $
    004 * $Date: 2014-04-24 16:48:09 -0700 (Thu, 24 Apr 2014) $
    005 *
    006 * ====================================================================
    007 * Licensed to the Apache Software Foundation (ASF) under one
    008 * or more contributor license agreements.  See the NOTICE file
    009 * distributed with this work for additional information
    010 * regarding copyright ownership.  The ASF licenses this file
    011 * to you under the Apache License, Version 2.0 (the
    012 * "License"); you may not use this file except in compliance
    013 * with the License.  You may obtain a copy of the License at
    014 *
    015 *   http://www.apache.org/licenses/LICENSE-2.0
    016 *
    017 * Unless required by applicable law or agreed to in writing,
    018 * software distributed under the License is distributed on an
    019 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    020 * KIND, either express or implied.  See the License for the
    021 * specific language governing permissions and limitations
    022 * under the License.
    023 * ====================================================================
    024 *
    025 * This software consists of voluntary contributions made by many
    026 * individuals on behalf of the Apache Software Foundation.  For more
    027 * information on the Apache Software Foundation, please see
    028 * <http://www.apache.org/>.
    029 *
    030 */
    031
    032package org.apache.commons.ssl;
    033
    034import javax.net.SocketFactory;
    035import java.io.IOException;
    036import java.security.GeneralSecurityException;
    037
    038/**
    039 * @author Credit Union Central of British Columbia
    040 * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
    041 * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
    042 * @since 28-Feb-2006
    043 */
    044public class LDAPSocket extends SSLClient {
    045    private final static LDAPSocket instance;
    046
    047    static {
    048        LDAPSocket sf = null;
    049        try {
    050            sf = new LDAPSocket();
    051        }
    052        catch (Exception e) {
    053            System.out.println("could not create LDAPSocket: " + e);
    054            e.printStackTrace();
    055        }
    056        finally {
    057            instance = sf;
    058        }
    059    }
    060
    061    private LDAPSocket() throws GeneralSecurityException, IOException {
    062        super();
    063
    064        // For now we setup the usual trust infrastructure, but consumers
    065        // are encouraged to call getInstance().addTrustMaterial() or
    066        // getInstance().setTrustMaterial() to customize the trust.
    067        if (TrustMaterial.JSSE_CACERTS != null) {
    068            setTrustMaterial(TrustMaterial.JSSE_CACERTS);
    069        } else {
    070            setTrustMaterial(TrustMaterial.CACERTS);
    071        }
    072    }
    073
    074    public static SocketFactory getDefault() {
    075        return getInstance();
    076    }
    077
    078    public static LDAPSocket getInstance() {
    079        return instance;
    080    }
    081
    082
    083}