KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > forms > PromptForPrivateKeyPassphraseForm


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.security.forms;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.struts.Globals;
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionMessage;
28
29 import com.sslexplorer.core.FieldValidationException;
30 import com.sslexplorer.core.forms.CoreForm;
31
32
33 /**
34  * Form implementation this is used to enter the private key passphrase
35  * when it is required.
36  *
37  * This will happen for when the <b>no</b> authentication modules used to login
38  * used the account password.
39  *
40  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
41  * @see com.sslexplorer.security.actions.UpdatePrivateKeyPassphraseDispatchAction
42  */

43 public class PromptForPrivateKeyPassphraseForm extends CoreForm {
44
45     // Private instance varaibles
46
private String JavaDoc passphrase;
47     private String JavaDoc confirmPassphrase;
48     private boolean newKey;
49     
50     /**
51      * Set whether this is a password for a new key or not. If <code>true</code>
52      * then the UI will make <i>Confirm Passphrase</i> available.
53      *
54      * @param newKey new key
55      */

56     public void setNewKey(boolean newKey) {
57         this.newKey = newKey;
58     }
59     
60     /**
61      * Get whether this is a password for a new key or not. If <code>true</code>
62      * then the UI will make <i>Confirm Passphrase</i> available.
63      *
64      * @return new key
65      */

66     public boolean getNewKey() {
67         return newKey;
68     }
69
70     /**
71      * Get the passphrase.
72      *
73      * @return passphrase
74      */

75     public String JavaDoc getPassphrase() {
76         return passphrase;
77     }
78
79     /**
80      * Set the passphrase.
81      *
82      * @param passphrase passphrase
83      */

84     public void setPassphrase(String JavaDoc passphrase) {
85         this.passphrase = passphrase.trim();
86     }
87
88     /**
89      * Get the confirmed passphrase.
90      *
91      * @return confirmed passphrase
92      */

93     public String JavaDoc getConfirmPassphrase() {
94         return confirmPassphrase;
95     }
96
97     /**
98      * Set the confirmed passphrase.
99      *
100      * @param confirmPassphrase confirm passphrase
101      */

102     public void setConfirmPassphrase(String JavaDoc confirmPassphrase) {
103         this.confirmPassphrase = confirmPassphrase.trim();
104     }
105     
106     /* (non-Javadoc)
107      * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
108      */

109     public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest JavaDoc request) {
110         super.reset(mapping, request);
111         passphrase = null;
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
118      * javax.servlet.http.HttpServletRequest)
119      */

120     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
121         if(isCommiting()) {
122             ActionErrors errors = new ActionErrors();
123             try {
124                 if (getPassphrase().length() == 0) {
125                     throw new FieldValidationException("noPassphrase");
126                 }
127                 if(getNewKey()) {
128                     if(!getPassphrase().equals(getConfirmPassphrase())) {
129                         throw new FieldValidationException("passphraseAndConfirmPassphraseDontMatch");
130                     }
131                 }
132             } catch (FieldValidationException fve) {
133                 errors.add(Globals.ERROR_KEY, new ActionMessage("promptForPrivateKeyPassphrase.error." + fve.getResourceKey()));
134             } catch (Exception JavaDoc e) {
135                 errors.add(Globals.ERROR_KEY, new ActionMessage("promptForPrivateKeyPassphrase.error.validateFailed", e.getMessage()));
136             }
137             return errors;
138         }
139         else {
140             return null;
141         }
142     }
143 }
Popular Tags