KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > bridge > X509TrustManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * X509TrustManager.java
21  *
22  * Created on December 8, 2004, 2:54 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.bridge;
26
27 import com.sun.enterprise.admin.jmx.remote.https.SunOneBasicX509TrustManager;
28
29 import java.security.cert.X509Certificate JavaDoc;
30
31
32 /**
33  * An implementation of X509TrustManager that provides basic support for
34  * Trust Management. This implementation prompts for confirmation of the
35  * server certificate.
36  *
37  * @author Ken Paulsen (ken.paulsen@sun.com)
38  */

39 class X509TrustManager extends SunOneBasicX509TrustManager {
40
41     /**
42      * Creates an instance of the X509TrustManager
43      *
44      * @param alias The toString() of the alias object concatenated with a
45      * date/time stamp is used as the alias of the trusted server certificate
46      * in the client side .asadmintruststore. When null only a date /
47      * timestamp is used as an alias.
48      */

49 // public X509TrustManager(Object alias) {
50
// super(alias);
51
// }
52

53
54     /**
55      * Creates an instance of the X509TrustManager. The date/time stamp is
56      * used of the trusted server certificate in the client side
57      * .asadmintruststore
58      */

59     public X509TrustManager() {
60 // this(null);
61
_alreadyInvoked = false;
62     }
63
64
65     /**
66      * Displays the certificate and prompts the user whether or not it is
67      * trusted.
68      *
69      * @param cert
70      * @return true if the user trusts the certificate
71      */

72     protected boolean isItOKToAddCertToTrustStore(X509Certificate JavaDoc cert) {
73         // The alreadyInvoked flag keeps track of whether we have already
74
// prompted the user. Unfortunately, checkServerTrusted is called 2x
75
// and we want to avoid prompting the user twice.
76
if (_alreadyInvoked) {
77             return false;
78         }
79     _alreadyInvoked = true;
80
81     // Make sure we should prompt
82
if (!promptForConfirmation()) {
83         // This should not happen, b/c this TrustManager always returns
84
// true. However, if someone extends this class to change this
85
// method, then return "false" to indicate that we will NOT
86
// blindly accept certs.
87
return false;
88     }
89
90     // Show the prompt...
91
return showConfirmDialog(null, cert.toString());
92
93
94        // return true;
95
}
96     public static boolean showConfirmDialog(java.awt.Component JavaDoc c, String JavaDoc m)
97     {
98         try {
99             // java.awt.Component frame = (c != null)? c : new javax.swing.JFrame();
100
// String title = (t != null)? t : "Confirm Certificate";
101
// int sel = javax.swing.JOptionPane.showConfirmDialog(frame, m, title, javax.swing.JOptionPane.YES_NO_OPTION);
102
// return (sel == javax.swing.JOptionPane.YES_OPTION);
103
return AcceptCertificate.acceptCertificatePanel(m);
104         } catch (Exception JavaDoc ex) {
105             ex.printStackTrace();
106         }
107         return true;
108     }
109
110     /**
111      * This implementation of promptForConfirmation always returns "true".
112      * This method is here to be consistent with the super class.
113      *
114      * @return true if the cert should be displayed and the user asked to
115      * confirm it. A return value of false indicates that the cert will be
116      * implicitly trusted and added to the asadmin truststore.
117      */

118     protected boolean promptForConfirmation() {
119         return true;
120     }
121
122
123     private boolean _alreadyInvoked;
124 }
125
Popular Tags