View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     https://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  
21  package org.apache.directory.ldap.client.api;
22  
23  
24  import java.net.Socket;
25  import java.security.cert.CertificateException;
26  import java.security.cert.X509Certificate;
27  
28  import javax.net.ssl.SSLEngine;
29  import javax.net.ssl.X509ExtendedTrustManager;
30  import javax.net.ssl.X509TrustManager;
31  
32  import org.apache.directory.api.i18n.I18n;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  
37  /**
38   * An implementation of {@link X509TrustManager} which trusts the given certificates without verifying them.
39   *
40   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
41   */
42  public class NoVerificationTrustManager extends X509ExtendedTrustManager
43  {
44      /** The logger. */
45      private static final Logger LOG = LoggerFactory.getLogger( NoVerificationTrustManager.class );
46      
47      
48      /**
49       * {@inheritDoc}
50       */
51      @Override
52      public void checkClientTrusted( X509Certificate[] x509Certificates, String authType, Socket socket )
53          throws CertificateException 
54      {
55          if ( LOG.isDebugEnabled() )
56          {
57              LOG.debug( I18n.msg( I18n.MSG_04168_CHECK_CLIENT_TRUSTED, x509Certificates[0] ) );
58          }
59      }
60  
61      
62      /**
63       * {@inheritDoc}
64       */
65      @Override
66      public void checkClientTrusted( X509Certificate[] x509Certificates, String authType, SSLEngine engine )
67          throws CertificateException 
68      {
69          if ( LOG.isDebugEnabled() )
70          {
71              LOG.debug( I18n.msg( I18n.MSG_04168_CHECK_CLIENT_TRUSTED, x509Certificates[0] ) );
72          }
73      }
74      
75      
76      public void checkServerTrusted( X509Certificate[] x509Certificates, String authType, Socket socket )
77          throws CertificateException 
78      {
79          if ( LOG.isDebugEnabled() )
80          {
81              LOG.debug( I18n.msg( I18n.MSG_04169_CHECK_SERVER_TRUSTED, x509Certificates[0] ) );
82          }
83      }
84  
85      /**
86       * {@inheritDoc}
87       */
88      @Override
89      public void checkServerTrusted( X509Certificate[] x509Certificates, String authType, SSLEngine engine )
90          throws CertificateException 
91      {
92          if ( LOG.isDebugEnabled() )
93          {
94              LOG.debug( I18n.msg( I18n.MSG_04169_CHECK_SERVER_TRUSTED, x509Certificates[0] ) );
95          }
96      }
97  
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public void checkClientTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException
104     {
105         if ( LOG.isDebugEnabled() )
106         {
107             LOG.debug( I18n.msg( I18n.MSG_04168_CHECK_CLIENT_TRUSTED, x509Certificates[0] ) );
108         }
109     }
110 
111 
112     /**
113      * {@inheritDoc}
114      */
115     @Override
116     public void checkServerTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException
117     {
118         if ( LOG.isDebugEnabled() )
119         {
120             LOG.debug( I18n.msg( I18n.MSG_04169_CHECK_SERVER_TRUSTED, x509Certificates[0] ) );
121         }
122     }
123 
124 
125     /**
126      * {@inheritDoc}
127      */
128     @Override
129     public X509Certificate[] getAcceptedIssuers()
130     {
131         return new X509Certificate[0];
132     }
133 }