001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024:
025: package com.bostechcorp.cbesb.ui.ide.security;
026:
027: import java.io.File;
028: import java.util.Arrays;
029: import java.util.Collections;
030: import java.util.List;
031:
032: import org.eclipse.jface.wizard.IWizardPage;
033: import org.eclipse.swt.SWT;
034: import org.eclipse.swt.events.FocusAdapter;
035: import org.eclipse.swt.events.FocusEvent;
036: import org.eclipse.swt.events.KeyAdapter;
037: import org.eclipse.swt.events.KeyEvent;
038: import org.eclipse.swt.events.ModifyEvent;
039: import org.eclipse.swt.events.ModifyListener;
040: import org.eclipse.swt.events.SelectionAdapter;
041: import org.eclipse.swt.events.SelectionEvent;
042: import org.eclipse.swt.layout.GridData;
043: import org.eclipse.swt.layout.GridLayout;
044: import org.eclipse.swt.widgets.Button;
045: import org.eclipse.swt.widgets.Combo;
046: import org.eclipse.swt.widgets.Composite;
047: import org.eclipse.swt.widgets.Label;
048: import org.eclipse.swt.widgets.Text;
049:
050: import com.bostechcorp.cbesb.common.i18n.I18N;
051: import com.bostechcorp.cbesb.common.i18n.Messages;
052: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
053: import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
054: import com.bostechcorp.cbesb.ui.util.AuthenticationUtil;
055:
056: public class CMWAdvDeleteCertificate extends CMWContextAwarePage {
057:
058: private String NO_ALIAS = I18N
059: .getString(Messages.CMW_ADVANCED_LABEL_COMBO_NOALIAS);
060: private Text text_4;
061: private Combo combo;
062: private Text text_2;
063: private Text text;
064: private Button deleteButton;
065:
066: protected CMWAdvDeleteCertificate(String pageName) {
067: super (pageName);
068:
069: setTitle(I18N.getString(Messages.CMW_ADVANCED_DELETE_TITLE));
070: setDescription(I18N
071: .getString(Messages.CMW_ADVANCED_DELETE_DESCRIPTION));
072: }
073:
074: public void createControl(Composite parent) {
075: Composite shell = new Composite(parent, SWT.NONE);
076: final GridLayout gridLayout = new GridLayout();
077: gridLayout.numColumns = 3;
078: shell.setLayout(gridLayout);
079: // shell.setSize(329, 260);
080: // shell.setText("Delete Certificate");
081:
082: final Label trustStoreFileLabel = new Label(shell, SWT.NONE);
083: trustStoreFileLabel.setLayoutData(new GridData(SWT.FILL,
084: SWT.CENTER, false, false));
085: trustStoreFileLabel.setText(I18N
086: .getString(Messages.CMW_ADVANCED_LABEL_TRUSTSTORE));
087:
088: text = new Text(shell, SWT.READ_ONLY | SWT.BORDER);
089: text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
090: false));
091:
092: final Button browseButton = new Button(shell, SWT.NONE);
093: browseButton.addSelectionListener(new SelectionAdapter() {
094: public void widgetSelected(final SelectionEvent e) {
095: projectCersBrowse(text);
096: text_2.setEditable(true);
097: text_2.setText("");
098: combo.removeAll();
099: combo.add(NO_ALIAS);
100: }
101: });
102: browseButton.setText(I18N
103: .getString(Messages.CMW_ADVANCED_LABEL_BROWSE));
104:
105: final Label passwordLabel = new Label(shell, SWT.NONE);
106: passwordLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
107: false, false));
108: passwordLabel
109: .setText(I18N
110: .getString(Messages.CMW_ADVANCED_LABEL_PASSWORD_TRUST_STORE));
111:
112: text_2 = new Text(shell, SWT.PASSWORD | SWT.BORDER);
113: text_2.addKeyListener(new KeyAdapter() {
114: public void keyReleased(final KeyEvent e) {
115: if (text_2.getText().length() > 0)
116: if (e.keyCode == SWT.CR)
117: extractAliasEntries();
118: }
119: });
120: text_2.addFocusListener(new FocusAdapter() {
121: public void focusLost(final FocusEvent e) {
122: if (text_2.getText().length() > 0)
123: extractAliasEntries();
124: }
125: });
126: text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
127: false, 2, 1));
128:
129: final Label certificateLabel = new Label(shell, SWT.NONE);
130: certificateLabel.setLayoutData(new GridData(SWT.FILL,
131: SWT.CENTER, false, false));
132: certificateLabel
133: .setText(I18N
134: .getString(Messages.CMW_ADVANCED_DELETE_LABEL_ALIAS_COMBO));
135:
136: combo = new Combo(shell, SWT.READ_ONLY);
137: combo.addSelectionListener(new SelectionAdapter() {
138: public void widgetSelected(final SelectionEvent e) {
139: updatePageComplete();
140: }
141: });
142: combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
143: false, 2, 1));
144:
145: text_4 = new Text(shell, SWT.V_SCROLL | SWT.MULTI
146: | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
147: text_4.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
148: true, 3, 1));
149:
150: final Label label = new Label(shell, SWT.SEPARATOR
151: | SWT.HORIZONTAL);
152: label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
153: false, 3, 1));
154:
155: deleteButton = new Button(shell, SWT.NONE);
156: deleteButton.addSelectionListener(new SelectionAdapter() {
157: public void widgetSelected(final SelectionEvent e) {
158: performAction();
159: }
160: });
161: final GridData gridData_1 = new GridData(SWT.FILL, SWT.CENTER,
162: false, false);
163: gridData_1.widthHint = 51;
164: deleteButton.setLayoutData(gridData_1);
165: deleteButton
166: .setText(I18N
167: .getString(Messages.CMW_ADVANCED_DELETE_LABEL_DELETE_BUTTON));
168: new Label(shell, SWT.NONE);
169: new Label(shell, SWT.NONE);
170: //
171: setControl(shell);
172:
173: //some Listeners
174: ModifyListener mody = new ModifyListener() {
175: public void modifyText(ModifyEvent e) {
176: updatePageComplete();
177: }
178: };
179:
180: text.addModifyListener(mody);
181: text_2.addModifyListener(mody);
182: //
183: updatePageComplete();
184: }
185:
186: @Override
187: public IWizardPage getNextPage() {
188: CertificateManagerWizard parent = (CertificateManagerWizard) getWizard();
189: return parent.getNextPage(this );
190: }
191:
192: @Override
193: public IWizardPage getPreviousPage() {
194: CertificateManagerWizard parent = (CertificateManagerWizard) getWizard();
195: return parent.getPreviousPage(this );
196: }
197:
198: @Override
199: protected void updatePageComplete() {
200: boolean b = verify();
201: setPageComplete(b);
202: if (deleteButton != null)
203: deleteButton.setEnabled(b);
204: //System.out.println("Veryfy "+verify());
205: }
206:
207: private boolean verify() {
208: if (text == null)
209: return false;
210: if (text.getText().equals("")) {
211: showError(I18N
212: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_SELECT_TRUST_FILE));
213: return false;
214: } else if (text_2.getText().equals("")) {
215: showError(I18N
216: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_PASSWORD_MISSING));
217: return false;
218: } else if (text_2.getText().length() < 6) {
219: showError(I18N
220: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_PASSWORD_SHORT));
221: return false;
222: }
223:
224: else if (combo.getText().equals("")) {
225: showError(I18N
226: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_SELECT_ALIAS));
227: return false;
228: } else if (combo.getText().equals(this .NO_ALIAS)) {
229: //showError(I18N.getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_SELECT_ALIAS));
230: return false;
231: }
232:
233: showClean();
234: return true;
235: }
236:
237: /**
238: * executes action if Finish is pressed
239: */
240: public boolean performFinish() {
241: //return performAction();
242: return false;
243: }
244:
245: /**
246: * Executes the certificate deletion
247: * @return
248: */
249: protected boolean performAction() {
250: /*String filePath=getPro_path()+"/"+text.getText().substring(text.getText().indexOf("::")+2);
251: File file= new File(filePath);
252: */
253: String filePath = "";
254: try {
255: filePath = EsbPathHelper.getFullPathForDef(MacroUtil
256: .resolveBuiltinMacro(text.getText(), this
257: .getCurr_pro_name()));
258: } catch (Exception e1) {
259: setPageComplete(false);
260: showError(I18N
261: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_EXCEPTION));
262: e1.printStackTrace();
263: currentExceptionMessage = e1.getMessage();
264: }
265: File file = new File(filePath);
266:
267: showWarning(I18N
268: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_PRGRESS));
269: try {
270: AuthenticationUtil.deleteTrustedCertificate(file, text_2
271: .getText(), combo.getText());
272: extractAliasEntries();//refreshing the page
273: showInfo(I18N
274: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_SUCCES));
275: } catch (Exception e) {
276: setPageComplete(false);
277: showError(I18N
278: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_EXCEPTION));
279: e.printStackTrace();
280: currentExceptionMessage = e.getMessage();
281:
282: combo.removeAll();
283: combo.add(this .NO_ALIAS);
284: combo.setText(this .NO_ALIAS);
285: updatePageComplete();
286: return false;
287: }
288: return true;
289: }
290:
291: @Override
292: public boolean canFinish() {
293: //if ( getWizard().getNextPage(this)==null && verify()) return true;
294: return false;
295: }
296:
297: /**
298: * extract all the certificate aliases from the trusstorefile
299: *
300: */
301: @SuppressWarnings({"unchecked","static-access"})
302: protected void extractAliasEntries() {
303: text_2.setEditable(false);
304: combo.removeAll();
305: //String filePath=getPro_path()+"/"+text.getText().substring(text.getText().indexOf("::")+2);
306: //File file= new File(filePath);
307: String filePath = "";
308: try {
309: filePath = EsbPathHelper.getFullPathForDef(MacroUtil
310: .resolveBuiltinMacro(text.getText(), this
311: .getCurr_pro_name()));
312: } catch (Exception e1) {
313: setPageComplete(false);
314: showError(I18N
315: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_EXCEPTION));
316: e1.printStackTrace();
317: currentExceptionMessage = e1.getMessage();
318: }
319: File file = new File(filePath);
320:
321: String[] aliases = null;
322: showWarning(I18N
323: .getString(Messages.CMW_ADVANCED_MESSAGE_PREVIEW_PRGRESS));
324: try {
325: aliases = AuthenticationUtil.getTrustStoreEntries(file,
326: text_2.getText());
327: text_4.setText(AuthenticationUtil.trustStoreFileToString(
328: file, text_2.getText()));
329: showInfo(I18N
330: .getString(Messages.CMW_ADVANCED_MESSAGE_PREVIEW_SUCCES));
331: //updatePageComplete();
332: } catch (Exception e) {
333: setPageComplete(false);
334: showError(I18N
335: .getString(Messages.CMW_ADVANCED_MESSAGE_PREVIEW_EXCEPTION));
336: currentExceptionMessage = e.getMessage();
337: text_2.setEditable(true);
338: text_4.setText("");
339: e.printStackTrace();
340: }
341: //
342: if (aliases != null) {
343: combo.removeAll();
344:
345: if (aliases.length == 0) {
346: combo.removeAll();
347: combo.add(this .NO_ALIAS);
348: combo.setText(this .NO_ALIAS);
349: } else {
350: List l = Arrays.asList(aliases);
351: Collections.sort(l);
352: aliases = (String[]) l.toArray();
353:
354: for (int i = 0; i < aliases.length; i++) {
355: combo.add(aliases[i]);
356: }
357: combo.setText(aliases[0]);
358: }
359: } else {
360: combo.removeAll();
361: combo.add(this.NO_ALIAS);
362: combo.setText(this.NO_ALIAS);
363: }
364: updatePageComplete();
365: }
366:
367: }
|