KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > client > TrustAnyTrustManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.appserv.management.client;
24
25 import java.security.cert.X509Certificate JavaDoc;
26 import java.security.cert.CertificateException JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 import javax.net.ssl.X509TrustManager;
30
31
32 /**
33     This TrustManager applies no logic as to whether its peer
34     certificate is trusted; it trusts all peers.
35     This is a security risk, and should be used only for convenience
36     in testing or where security is explicitly not an issue.
37  */

38 public final class TrustAnyTrustManager implements X509TrustManager
39 {
40     private static TrustAnyTrustManager INSTANCE = null;
41     private static TrustAnyTrustManager[] INSTANCE_ARRAY = null;
42     
43     private TrustAnyTrustManager() {}
44     
45     /**
46         Get an instance; only one is ever created.
47      */

48         public static synchronized TrustAnyTrustManager
49     getInstance()
50     {
51         if ( INSTANCE == null )
52         {
53             INSTANCE = new TrustAnyTrustManager();
54             INSTANCE_ARRAY = new TrustAnyTrustManager[] { INSTANCE };
55         }
56         return( INSTANCE );
57     }
58     
59     /**
60         Calls getInstance() and returns an array containing it.
61      */

62         public static TrustAnyTrustManager[]
63     getInstanceArray()
64     {
65         getInstance();
66         return( INSTANCE_ARRAY );
67     }
68     
69     /**
70         WARNING: does nothing; all clients are always trusted.
71      */

72         public void
73     checkClientTrusted( X509Certificate JavaDoc[] chain, String JavaDoc authType)
74         throws CertificateException JavaDoc
75     {
76         //trace( "checkClientTrusted, authType = " + authType +
77
// ", " + SmartStringifier.toString( chain ) );
78
}
79     
80     /**
81         WARNING: does nothing; all servers are always trusted.
82      */

83         public void
84     checkServerTrusted( X509Certificate JavaDoc[] chain, String JavaDoc authType)
85         throws CertificateException JavaDoc
86     {
87         //trace( "checkServerTrusted, authType = " + authType +
88
// ", " + SmartStringifier.toString( chain ) );
89
}
90     
91     /**
92         @return an empty array.
93      */

94         public X509Certificate JavaDoc[]
95     getAcceptedIssuers()
96     {
97         return( new X509Certificate JavaDoc[ 0 ] );
98     }
99     
100         public String JavaDoc
101     toString()
102     {
103         return( "TrustAnyTrustManager--trusts all certificates with no check whatsoever" );
104     }
105 }
Popular Tags