Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2008, Jay Rosenthal |
3 |
* |
4 |
* All rights reserved. This program and the accompanying materials |
5 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* which accompanies this distribution, and is available at |
7 |
* http://www.eclipse.org/legal/epl-v10.html |
8 |
* |
9 |
* Contributors: |
10 |
* Jay Rosenthal - initial API and implementation |
11 |
*******************************************************************************/ |
12 |
|
13 |
package org.eclipse.equinox.internal.provisional.security.ui; |
14 |
|
15 |
import java.security.cert.X509Certificate; |
16 |
import java.text.DateFormat; |
17 |
import org.eclipse.equinox.internal.security.ui.Activator; |
18 |
import org.eclipse.equinox.internal.security.ui.SecurityUIMsg; |
19 |
import org.eclipse.equinox.internal.security.ui.wizard.CertificateViewer; |
20 |
import org.eclipse.jface.dialogs.IDialogConstants; |
21 |
import org.eclipse.jface.dialogs.TitleAreaDialog; |
22 |
import org.eclipse.jface.resource.JFaceResources; |
23 |
import org.eclipse.swt.SWT; |
24 |
import org.eclipse.swt.graphics.Font; |
25 |
import org.eclipse.swt.graphics.Image; |
26 |
import org.eclipse.swt.layout.*; |
27 |
import org.eclipse.swt.widgets.*; |
28 |
|
29 |
public class X509CertificateViewDialog extends TitleAreaDialog { |
30 |
private final static String titleImageName = "/titleAreaCert.gif"; //$NON-NLS-1$ |
31 |
private X509Certificate theCert; |
32 |
private static final DateFormat _df = DateFormat.getDateInstance(DateFormat.LONG); |
33 |
private X500PrincipalHelper nameHelper = new X500PrincipalHelper(); |
34 |
|
35 |
// We use the "bannerFont" for our bold font |
36 |
private static Font boldFont = JFaceResources.getBannerFont(); |
37 |
private Image titleImage; |
38 |
|
39 |
public X509CertificateViewDialog(Shell parentShell, X509Certificate cert) { |
40 |
super(parentShell); |
41 |
this.theCert = cert; |
42 |
} |
43 |
|
44 |
protected Control createContents(Composite parent) { |
45 |
return super.createContents(parent); |
46 |
} |
47 |
|
48 |
protected Control createDialogArea(Composite parent) { |
49 |
nameHelper.setPrincipal(theCert.getSubjectX500Principal()); |
50 |
|
51 |
setTitle((nameHelper.getCN() != null ? nameHelper.getCN() : nameHelper.getOU())); |
52 |
|
53 |
titleImage = Activator.getImageDescriptor(titleImageName).createImage(); |
54 |
|
55 |
if (titleImage != null) |
56 |
setTitleImage(titleImage); |
57 |
|
58 |
Composite composite = (Composite) super.createDialogArea(parent); |
59 |
|
60 |
TabFolder tabFolder = new TabFolder(composite, SWT.BORDER); |
61 |
GridData bdata = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL); |
62 |
tabFolder.setLayoutData(bdata); |
63 |
|
64 |
createBasicTab(tabFolder); |
65 |
|
66 |
createAdvancedTab(tabFolder); |
67 |
|
68 |
return composite; |
69 |
} |
70 |
|
71 |
private void createBasicTab(TabFolder tabFolder) { |
72 |
String displayName = null; |
73 |
int labelIndent = 10; |
74 |
int dataIdent = 10; |
75 |
|
76 |
TabItem basicTab = new TabItem(tabFolder, SWT.NULL); |
77 |
basicTab.setText(SecurityUIMsg.CERTVIEW_LABEL_BASIC); |
78 |
Composite basicTabComposite = new Composite(tabFolder, SWT.NONE); |
79 |
|
80 |
GridLayout tabLayout = new GridLayout(); |
81 |
tabLayout.numColumns = 2; |
82 |
basicTabComposite.setLayout(tabLayout); |
83 |
|
84 |
Label issueToLabel = new Label(basicTabComposite, SWT.NONE); |
85 |
issueToLabel.setText(SecurityUIMsg.CERTPROP_X509_ISSUED_TO); |
86 |
issueToLabel.setFont(boldFont); |
87 |
configureLayout(issueToLabel, 2, 0, 0, 0); |
88 |
|
89 |
// Display the RDNs of the Subject |
90 |
nameHelper.setPrincipal(theCert.getSubjectX500Principal()); |
91 |
|
92 |
Label CNLabel = new Label(basicTabComposite, SWT.NONE); |
93 |
CNLabel.setText(SecurityUIMsg.X500_LABEL_CN); |
94 |
configureLayout(CNLabel, 0, 0, labelIndent, 0); |
95 |
|
96 |
Label subjectCN = new Label(basicTabComposite, SWT.NONE); |
97 |
displayName = nameHelper.getCN(); |
98 |
subjectCN.setText((displayName != null ? displayName : SecurityUIMsg.CERTVAL_UNDEFINED)); |
99 |
configureLayout(subjectCN, 0, 0, dataIdent, 0); |
100 |
|
101 |
Label OLabel = new Label(basicTabComposite, SWT.NONE); |
102 |
OLabel.setText(SecurityUIMsg.X500_LABEL_O); |
103 |
configureLayout(OLabel, 0, 0, labelIndent, 0); |
104 |
|
105 |
Label subjectO = new Label(basicTabComposite, SWT.NONE); |
106 |
displayName = nameHelper.getO(); |
107 |
subjectO.setText((displayName != null ? displayName : SecurityUIMsg.CERTVAL_UNDEFINED)); |
108 |
configureLayout(subjectO, 0, 0, dataIdent, 0); |
109 |
|
110 |
Label OULabel = new Label(basicTabComposite, SWT.NONE); |
111 |
OULabel.setText(SecurityUIMsg.X500_LABEL_OU); |
112 |
configureLayout(OULabel, 0, 0, labelIndent, 0); |
113 |
|
114 |
Label subjectOU = new Label(basicTabComposite, SWT.NONE); |
115 |
displayName = nameHelper.getOU(); |
116 |
subjectOU.setText((displayName != null ? displayName : SecurityUIMsg.CERTVAL_UNDEFINED)); |
117 |
configureLayout(subjectOU, 0, 0, dataIdent, 0); |
118 |
|
119 |
Label issueByLabel = new Label(basicTabComposite, SWT.NONE); |
120 |
issueByLabel.setText(SecurityUIMsg.CERTPROP_X509_ISSUED_BY); |
121 |
configureLayout(issueByLabel, 2, 0, 0, 0); |
122 |
issueByLabel.setFont(boldFont); |
123 |
|
124 |
// Display the RDNs of the Issuer |
125 |
nameHelper.setPrincipal(theCert.getIssuerX500Principal()); |
126 |
|
127 |
Label CNLabel2 = new Label(basicTabComposite, SWT.NONE); |
128 |
CNLabel2.setText(SecurityUIMsg.X500_LABEL_CN); |
129 |
configureLayout(CNLabel2, 0, 0, labelIndent, 0); |
130 |
|
131 |
Label issuerCN = new Label(basicTabComposite, SWT.NONE); |
132 |
displayName = nameHelper.getCN(); |
133 |
issuerCN.setText((displayName != null ? displayName : SecurityUIMsg.CERTVAL_UNDEFINED)); |
134 |
configureLayout(issuerCN, 0, 0, dataIdent, 0); |
135 |
|
136 |
Label OLabel2 = new Label(basicTabComposite, SWT.NONE); |
137 |
OLabel2.setText(SecurityUIMsg.X500_LABEL_O); |
138 |
configureLayout(OLabel2, 0, 0, labelIndent, 0); |
139 |
|
140 |
Label issuerO = new Label(basicTabComposite, SWT.NONE); |
141 |
displayName = nameHelper.getO(); |
142 |
issuerO.setText((displayName != null ? displayName : SecurityUIMsg.CERTVAL_UNDEFINED)); |
143 |
configureLayout(issuerO, 0, 0, dataIdent, 0); |
144 |
|
145 |
Label OULabel2 = new Label(basicTabComposite, SWT.NONE); |
146 |
OULabel2.setText(SecurityUIMsg.X500_LABEL_OU); |
147 |
configureLayout(OULabel2, 0, 0, labelIndent, 0); |
148 |
|
149 |
Label issuerOU = new Label(basicTabComposite, SWT.NONE); |
150 |
displayName = nameHelper.getOU(); |
151 |
issuerOU.setText((displayName != null ? displayName : SecurityUIMsg.CERTVAL_UNDEFINED)); |
152 |
configureLayout(issuerOU, 0, 0, dataIdent, 0); |
153 |
|
154 |
Label datesLabel = new Label(basicTabComposite, SWT.NONE); |
155 |
datesLabel.setText(SecurityUIMsg.CERTVIEW_LABEL_VALIDITY_DATES); |
156 |
configureLayout(datesLabel, 2, 0, 0, 0); |
157 |
datesLabel.setFont(boldFont); |
158 |
|
159 |
Label validFrom = new Label(basicTabComposite, SWT.NONE); |
160 |
validFrom.setText(SecurityUIMsg.CERTPROP_X509_VALID_FROM); |
161 |
configureLayout(validFrom, 0, 0, labelIndent, 0); |
162 |
|
163 |
Label fromDate = new Label(basicTabComposite, SWT.NONE); |
164 |
fromDate.setText(_df.format(theCert.getNotBefore())); |
165 |
configureLayout(fromDate, 0, 0, dataIdent, 0); |
166 |
|
167 |
Label validTo = new Label(basicTabComposite, SWT.NONE); |
168 |
validTo.setText(SecurityUIMsg.CERTPROP_X509_VALID_TO); |
169 |
configureLayout(validTo, 0, 0, labelIndent, 0); |
170 |
|
171 |
Label toDate = new Label(basicTabComposite, SWT.NONE); |
172 |
toDate.setText(_df.format(theCert.getNotAfter())); |
173 |
configureLayout(toDate, 0, 0, dataIdent, 0); |
174 |
|
175 |
basicTab.setControl(basicTabComposite); |
176 |
} |
177 |
|
178 |
protected static void configureLayout(Control c, int horizontalSpan, int verticalSpan, int horizontalIndent, int vertIndent) { |
179 |
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER); |
180 |
|
181 |
gd.horizontalSpan = horizontalSpan; |
182 |
gd.verticalSpan = verticalSpan; |
183 |
gd.horizontalIndent = horizontalIndent; |
184 |
gd.verticalIndent = vertIndent; |
185 |
|
186 |
c.setLayoutData(gd); |
187 |
|
188 |
} |
189 |
|
190 |
private void createAdvancedTab(final TabFolder tabFolder) { |
191 |
TabItem advancedTab = new TabItem(tabFolder, SWT.NULL); |
192 |
advancedTab.setText(SecurityUIMsg.CERTVIEW_LABEL_DETAILS); |
193 |
Composite advTabComposite = new Composite(tabFolder, SWT.NONE); |
194 |
advTabComposite.setLayout(new FillLayout(SWT.VERTICAL)); |
195 |
|
196 |
CertificateViewer certViewer = new CertificateViewer(advTabComposite); |
197 |
certViewer.setCertificate(theCert); |
198 |
advancedTab.setControl(advTabComposite); |
199 |
} |
200 |
|
201 |
protected void setShellStyle(int newShellStyle) { |
202 |
|
203 |
super.setShellStyle(newShellStyle | SWT.RESIZE | SWT.DIALOG_TRIM); |
204 |
} |
205 |
|
206 |
protected void createButtonsForButtonBar(Composite parent) { |
207 |
// The default has only a "Close" button, but it returns the CANCEL Id |
208 |
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CLOSE_LABEL, true); |
209 |
|
210 |
} |
211 |
|
212 |
public boolean close() { |
213 |
if (titleImage != null) { |
214 |
titleImage.dispose(); |
215 |
} |
216 |
return super.close(); |
217 |
} |
218 |
|
219 |
} |