KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
26
27 import javax.net.ssl.X509TrustManager;
28 import javax.net.ssl.HandshakeCompletedListener;
29
30 /**
31     Class encapsulating parameters available for use with TLS.
32     
33     @see com.sun.appserv.management.client.TrustStoreTrustManager
34     @see com.sun.appserv.management.client.TrustAnyTrustManager
35     @see com.sun.appserv.management.client.HandshakeCompletedListenerImpl
36  */

37 public final class TLSParams
38 {
39     private final X509TrustManager[] mTrustManagers;
40     private final HandshakeCompletedListener mHandshakeCompletedListener;
41
42     /**
43         Return a X509TrustManager[] supporting trust via
44         the specified trustStore file using the specified password.
45         
46         @param trustStore
47         @param trustStorePassword password to use for the trustStore file
48         @param prompt whether to prompt via System.out/in for addition of new certificates
49      */

50         public static X509TrustManager[]
51     getTrustManagers(
52         final File JavaDoc trustStore,
53         final char[] trustStorePassword,
54         final boolean prompt )
55     {
56         final TrustStoreTrustManager mgr =
57             new TrustStoreTrustManager( trustStore, trustStorePassword );
58         mgr.setPrompt( prompt );
59             
60         final X509TrustManager[] trustMgrs = new X509TrustManager[] { mgr };
61         
62         return( trustMgrs );
63     }
64     
65     /**
66         @param trustStore
67         @param trustStorePassword
68         @param prompt
69         @param handshakeCompletedListener (may be null)
70      */

71         public
72     TLSParams(
73         final File JavaDoc trustStore,
74         final char[] trustStorePassword,
75         final boolean prompt,
76         final HandshakeCompletedListener handshakeCompletedListener )
77     {
78         this( getTrustManagers( trustStore, trustStorePassword, prompt), handshakeCompletedListener );
79         
80     }
81     
82     /**
83         @param trustManagers
84         @param handshakeCompletedListener (may be null)
85      */

86         public
87     TLSParams(
88         final X509TrustManager[] trustManagers,
89         final HandshakeCompletedListener handshakeCompletedListener )
90     {
91         if ( trustManagers == null )
92         {
93             throw new IllegalArgumentException JavaDoc();
94         }
95         
96         mTrustManagers = trustManagers;
97         mHandshakeCompletedListener = handshakeCompletedListener;
98     }
99     
100     /**
101         @param trustManager
102         @param handshakeCompletedListener (may be null)
103      */

104         public
105     TLSParams(
106         final X509TrustManager trustManager,
107         final HandshakeCompletedListener handshakeCompletedListener )
108     {
109         this( new X509TrustManager[] { trustManager }, handshakeCompletedListener );
110     }
111     
112     /**
113         @return the TrustManagers in use
114      */

115         public X509TrustManager[]
116     getTrustManagers( )
117     {
118         return( mTrustManagers );
119     }
120     
121     /**
122         @return the HandshakeCompletedListener in use or null if none
123      */

124         public HandshakeCompletedListener
125     getHandshakeCompletedListener( )
126     {
127         return( mHandshakeCompletedListener );
128     }
129 }
130
Popular Tags