KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > keystore > wizards > actions > KeyStoreImportFinishAction


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.actions;
21
22 import java.io.File JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34
35 import com.sslexplorer.core.CoreUtil;
36 import com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType;
37 import com.sslexplorer.keystore.wizards.KeyStoreImportTypeManager;
38 import com.sslexplorer.keystore.wizards.forms.KeyStoreImportFileForm;
39 import com.sslexplorer.keystore.wizards.forms.KeyStoreImportTypeForm;
40 import com.sslexplorer.keystore.wizards.types.ReplyFromCAImportType;
41 import com.sslexplorer.policyframework.Permission;
42 import com.sslexplorer.policyframework.PolicyConstants;
43 import com.sslexplorer.security.LogonControllerFactory;
44 import com.sslexplorer.security.SessionInfo;
45 import com.sslexplorer.wizard.AbstractWizardSequence;
46 import com.sslexplorer.wizard.WizardActionStatus;
47 import com.sslexplorer.wizard.actions.AbstractWizardAction;
48 import com.sslexplorer.wizard.forms.AbstractWizardFinishForm;
49
50 /**
51  * Implementation of an {@link com.sslexplorer.wizard.actions.AbstractWizardAction}
52  * that is used in the key store import wizard. This is the final action and
53  * performs the actual import using all data gathered in the wizard.
54  *
55  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
56  */

57
58 public class KeyStoreImportFinishAction extends AbstractWizardAction {
59     final static Log log = LogFactory.getLog(KeyStoreImportFinishAction.class);
60
61     /**
62      * Constructor
63      *
64      */

65     public KeyStoreImportFinishAction() {
66         super(PolicyConstants.KEYSTORE_RESOURCE_TYPE, new Permission[] {
67                         PolicyConstants.PERM_CHANGE
68                     });
69     }
70
71     /* (non-Javadoc)
72      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
73      */

74     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
75         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
76     }
77
78     /* (non-Javadoc)
79      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
80      */

81     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
82                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
83         // Do the install
84
List JavaDoc<WizardActionStatus> actionStatus = new ArrayList JavaDoc<WizardActionStatus>();
85         AbstractWizardSequence seq = getWizardSequence(request);
86         AbstractKeyStoreImportType importType = KeyStoreImportTypeManager.getInstance().getType(
87             (String JavaDoc)seq.getAttribute(KeyStoreImportTypeForm.ATTR_TYPE, ReplyFromCAImportType.REPLY_FROM_CA));
88         File JavaDoc f = (File JavaDoc)seq.getAttribute(KeyStoreImportFileForm.ATTR_UPLOADED_FILE, null);
89         String JavaDoc alias = (String JavaDoc)seq.getAttribute(KeyStoreImportFileForm.ATTR_ALIAS, null);
90         String JavaDoc passphrase = (String JavaDoc)seq.getAttribute(KeyStoreImportFileForm.ATTR_PASSPHRASE, null);
91         try {
92             importType.doInstall(f, alias, passphrase, seq, LogonControllerFactory.getInstance().getSessionInfo(request));
93             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "keyStoreImportType." + importType.getName() + ".installed", alias, "", "", "", "", importType.getBundle()));
94         }
95         catch(Exception JavaDoc e) {
96             log.error("Failed to load key.", e);
97             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS, "keyStoreImportType." + importType.getName() + ".installFailed", alias, e.getMessage(), "", "", "", importType.getBundle()));
98         }
99         ((AbstractWizardFinishForm) form).setActionStatus(actionStatus);
100         return super.unspecified(mapping, form, request, response);
101     }
102
103     /**
104      * Exit the wizard.
105      *
106      * @param mapping mapping
107      * @param form form
108      * @param request request
109      * @param response response
110      * @return forward
111      * @throws Exception on any error
112      */

113     public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
114                     throws Exception JavaDoc {
115         ActionForward fwd = cancel(mapping, form, request, response);
116         String JavaDoc orig = fwd.getPath();
117         fwd = mapping.findForward("restartRequired");
118         fwd = CoreUtil.addParameterToForward(fwd, "no", orig);
119         return fwd;
120     }
121
122     /* (non-Javadoc)
123      * @see com.sslexplorer.wizard.actions.AbstractWizardAction#rerun(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
124      */

125     public ActionForward rerun(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
126                     throws Exception JavaDoc {
127         return mapping.findForward("rerun");
128     }
129
130     protected WizardActionStatus serverAuthenticationKey(AbstractWizardSequence seq) {
131         try {
132            
133         } catch (Exception JavaDoc e) {
134             log.error("Failed to install server authentication key.", e);
135             return new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
136                 "keyStoreImportWizard.keyStoreImportFinish.status.failedToInstallServerAuthenticationKey", e.getMessage());
137         }
138         return new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "keyStoreImportWizard.keyStoreImportFinish.status.serverAuthenticationKeyInstalled");
139     }
140 }
141
Popular Tags