KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.struts.action.ActionMessages;
27
28 import com.sslexplorer.boot.KeyStoreManager;
29 import com.sslexplorer.core.CoreAttributeConstants;
30 import com.sslexplorer.core.CoreEvent;
31 import com.sslexplorer.core.CoreEventConstants;
32 import com.sslexplorer.core.CoreServlet;
33 import com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType;
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 server authentication key.
41  *
42  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
43  */

44 public class ServerAuthenticationKeyImportType extends AbstractKeyStoreImportType {
45     
46     
47     /**
48      * Constant for importing a certificate authentication for a server SSL explorer will connect to
49      */

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

55     public ServerAuthenticationKeyImportType() {
56         super(SERVER_AUTHENTICATION_KEY, "keystore", true, true, 40);
57     }
58
59     /* (non-Javadoc)
60      * @see com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType#validate(org.apache.struts.action.ActionMessages, java.lang.String, java.lang.String, com.sslexplorer.wizard.AbstractWizardSequence, com.sslexplorer.security.SessionInfo)
61      */

62     public void validate(ActionMessages errs, String JavaDoc alias, String JavaDoc passphrase, AbstractWizardSequence seq, SessionInfo sessionInfo) {
63        // We *can* take an alias but do not have to
64
}
65
66     /* (non-Javadoc)
67      * @see com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType#doInstall(java.io.File, java.lang.String, java.lang.String, com.sslexplorer.wizard.AbstractWizardSequence)
68      */

69     public void doInstall(File JavaDoc file, String JavaDoc alias, String JavaDoc passphrase, AbstractWizardSequence seq, SessionInfo sessionInfo) throws Exception JavaDoc {
70         KeyStoreManager mgr = KeyStoreManager.getInstance(KeyStoreManager.SERVER_AUTHENTICATION_CERTIFICATES_KEY_STORE);
71         alias = mgr.importPKCS12Key(file, passphrase, alias, alias);
72         mgr.reloadKeystore();
73         Certificate JavaDoc certif = mgr.getCertificate(alias);
74
75         CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.KEYSTORE_SERVER_AUTHENTICATION_CERTIFICATE_IMPORTED, KeyStoreManager.SERVER_AUTHENTICATION_CERTIFICATES_KEY_STORE, seq.getSession())
76                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ALIAS, alias)
77                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_TYPE, certif.getType())
78                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_HOSTNAME, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "cn"))
79                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ORGANISATIONAL_UNIT, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "ou"))
80                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_COMPANY, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "o"))
81                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_STATE, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "st"))
82                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_LOCATION, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "l"))
83                         .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_COUNTRY_CODE, KeyStoreManager.getX509CertificateEntity((X509Certificate JavaDoc)certif, "c"));
84         CoreServlet.getServlet().fireCoreEvent(coreEvent);
85
86     }
87 }
88
Popular Tags