KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > keystore > wizards > types > RootServerCertificateImportType


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.keystore.wizards.types;
21
22 import java.io.File JavaDoc;
23 import java.security.cert.Certificate JavaDoc;
24 import java.security.cert.X509Certificate JavaDoc;
25
26 import com.sslexplorer.boot.ContextKey;
27 import com.sslexplorer.boot.KeyStoreManager;
28 import com.sslexplorer.core.CoreAttributeConstants;
29 import com.sslexplorer.core.CoreEvent;
30 import com.sslexplorer.core.CoreEventConstants;
31 import com.sslexplorer.core.CoreServlet;
32 import com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType;
33 import com.sslexplorer.properties.Property;
34 import com.sslexplorer.security.SessionInfo;
35 import com.sslexplorer.wizard.AbstractWizardSequence;
36
37
38 /**
39  * Implementation of a {@link com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType}
40  * that imports a root server certifcate.
41  *
42  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
43  */

44 public class RootServerCertificateImportType extends AbstractKeyStoreImportType {
45     /**
46      * Constant for importing a root certificate for the server certificate
47      */

48     public final static String JavaDoc ROOT_SERVER_CERTIFICATE = "rootServerCertificate";
49
50     /**
51      * Constructor.
52      */

53     public RootServerCertificateImportType() {
54         super(ROOT_SERVER_CERTIFICATE, "keystore", false, true, 20);
55     }
56
57     /* (non-Javadoc)
58      * @see com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType#doInstall(java.io.File, java.lang.String, java.lang.String, com.sslexplorer.wizard.AbstractWizardSequence)
59      */

60     public void doInstall(File JavaDoc file, String JavaDoc alias, String JavaDoc passphrase, AbstractWizardSequence seq, SessionInfo sessionInfo) throws Exception JavaDoc {
61         KeyStoreManager mgr = KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE);
62         String JavaDoc pw = Property.getProperty(new ContextKey("webServer.keystore.sslCertificate.password"));
63         mgr.importCert(alias, file, pw);
64         Certificate JavaDoc certif = mgr.getCertificate(alias);
65
66         CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.KEYSTORE_ROOT_CERTIFICATE_IMPORTED, KeyStoreManager.DEFAULT_KEY_STORE, seq.getSession())
67                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ALIAS, alias)
68                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_TYPE, certif.getType())
69                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_HOSTNAME, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "cn"))
70                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ORGANISATIONAL_UNIT, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "ou"))
71                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_COMPANY, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "o"))
72                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_STATE, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "st"))
73                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_LOCATION, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "l"))
74                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_COUNTRY_CODE, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "c"));
75         CoreServlet.getServlet().fireCoreEvent(coreEvent);
76     }
77
78 }
79
Popular Tags