KickJava   Java API By Example, From Geeks To Geeks.

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


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 reply from a CA.
41  *
42  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
43  */

44 public class ReplyFromCAImportType extends AbstractKeyStoreImportType {
45     
46     
47     /**
48      * Constant for importing a reply from a CA
49      */

50     public final static String JavaDoc REPLY_FROM_CA = "replyFromCA";
51
52     /**
53      * Constructor.
54      */

55     public ReplyFromCAImportType() {
56         super(REPLY_FROM_CA, "keystore", false, false, 10);
57     }
58
59     /* (non-Javadoc)
60      * @see com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType#doInstall(java.io.File, java.lang.String, java.lang.String, com.sslexplorer.wizard.AbstractWizardSequence)
61      */

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