KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > install > forms > SelectCertificateSourceForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.install.forms;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import com.sslexplorer.boot.KeyStoreManager;
25 import com.sslexplorer.wizard.AbstractWizardSequence;
26 import com.sslexplorer.wizard.forms.DefaultWizardForm;
27
28
29 /**
30  * Extensions of a {@link com.sslexplorer.wizard.forms.DefaultWizardForm} that
31  * allows a source for the SSL certificate to use. The user may choose to
32  * create a new certificate, use the existing one (if it exists) or import
33  * a certificate.
34  *
35  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
36  */

37 public class SelectCertificateSourceForm extends DefaultWizardForm {
38     
39     /**
40      * Constant for create new certificate. See {@link #setCertificateSource(String)}.
41      */

42     public final static String JavaDoc CREATE_NEW_CERTIFICATE = "createNew";
43
44     /**
45      * Constant for import existing certificate. See {@link #setCertificateSource(String)}.
46      */

47     public final static String JavaDoc IMPORT_EXISTING_CERTIFICATE = "importExisting";
48
49     /**
50      * Constant for use current certificate. See {@link #setCertificateSource(String)}.
51      */

52     public final static String JavaDoc USE_CURRENT_CERTIFICATE = "useCurrent";
53     
54     // Statics for sequence attributes
55

56     /**
57      * Selected Certificate source
58      */

59     public final static String JavaDoc ATTR_CERTIFICATE_SOURCE = "certificateSource";
60
61     // Private instance variables
62

63     private String JavaDoc certificateSource;
64
65     /**
66      * Constructor
67      */

68     public SelectCertificateSourceForm() {
69         super(true, false, "/WEB-INF/jsp/content/install/selectCertificateSource.jspf",
70             "", true, false, "selectCertificateSource", "install", "installation.selectCertificateSource", 1);
71     }
72
73     /* (non-Javadoc)
74      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence)
75      */

76     public void init(AbstractWizardSequence sequence, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
77         setCertificateSource((String JavaDoc)sequence.getAttribute(ATTR_CERTIFICATE_SOURCE, getCertificatesAvailable() ? USE_CURRENT_CERTIFICATE : CREATE_NEW_CERTIFICATE));
78     }
79
80     /**
81      * Get the currently selected certificate source. Can be one
82      * of {@link SelectCertificateSourceForm#CREATE_NEW_CERTIFICATE}, {@link #IMPORT_EXISTING_CERTIFICATE}
83      * or {@link #USE_CURRENT_CERTIFICATE}.
84      *
85      * @return the selected certificate source.
86      */

87     public String JavaDoc getCertificateSource() {
88         return certificateSource;
89     }
90
91     /**
92      * Set the currently selected certificate source. Can be one
93      * of {@link SelectCertificateSourceForm#CREATE_NEW_CERTIFICATE}, {@link #IMPORT_EXISTING_CERTIFICATE}
94      * or {@link #USE_CURRENT_CERTIFICATE}.
95      *
96      * @param certificateSource the selected certificate source.
97      */

98     public void setCertificateSource(String JavaDoc certificateSource) {
99         this.certificateSource = certificateSource;
100     }
101     
102     /**
103      * Get if the key store exists, is not empty and does not contain any errors. If so
104      * the user may select 'Use Current'
105      *
106      * @return certificates available
107      */

108     public boolean getCertificatesAvailable() {
109         return KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).isKeyStoreExists() &&
110             !KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).isKeyStoreEmpty() &&
111             KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).getKeyStoreException() == null;
112     }
113
114     /* (non-Javadoc)
115      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
116      */

117     public void apply(AbstractWizardSequence sequence) throws Exception JavaDoc {
118         sequence.putAttribute(ATTR_CERTIFICATE_SOURCE, getCertificateSource());
119     }
120 }
121
Popular Tags