KickJava   Java API By Example, From Geeks To Geeks.

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


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 old password when the users
35  * private key passphrase must be changed.
36  *
37  * This may happen for example if the key was created using their account password
38  * which has since changed.
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 UpdatePrivateKeyPassphraseForm extends CoreForm {
44
45     // Private instance varaibles
46
String JavaDoc oldPassphrase;
47     boolean resetPrivateKey = false;
48
49     /**
50      * Get the old password.
51      *
52      * @return old password
53      */

54     public String JavaDoc getOldPassphrase() {
55         return oldPassphrase;
56     }
57
58     /**
59      * Set the old password.
60      *
61      * @param oldPassword old password
62      */

63     public void setOldPassphrase(String JavaDoc oldPassword) {
64         this.oldPassphrase = oldPassword.trim();
65     }
66     
67     /* (non-Javadoc)
68      * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
69      */

70     public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest JavaDoc request) {
71         super.reset(mapping, request);
72         oldPassphrase = null;
73         resetPrivateKey = false;
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
80      * javax.servlet.http.HttpServletRequest)
81      */

82     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
83         if(isCommiting()) {
84             ActionErrors errors = new ActionErrors();
85             try {
86                 if (getOldPassphrase().length() == 0 && !resetPrivateKey) {
87                     throw new FieldValidationException("noOldPassphrase");
88                 }
89             } catch (FieldValidationException fve) {
90                 errors.add(Globals.ERROR_KEY, new ActionMessage("updatePrivateKeyPassphrase.error." + fve.getResourceKey()));
91             } catch (Exception JavaDoc e) {
92                 errors.add(Globals.ERROR_KEY, new ActionMessage("updatePrivateKeyPassphrase.error.validateFailed", e.getMessage()));
93             }
94             return errors;
95         }
96         else {
97             return null;
98         }
99     }
100
101     public boolean isResetPrivateKey() {
102         return resetPrivateKey;
103     }
104
105     public void setResetPrivateKey(boolean resetPrivateKey) {
106         this.resetPrivateKey = resetPrivateKey;
107     }
108 }
Popular Tags