View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.security.admin.web;
17  
18  import java.security.KeyStoreException;
19  
20  import javax.servlet.http.HttpServletRequest;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.apache.struts.action.ActionErrors;
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionMapping;
26  import org.apache.struts.action.ActionMessage;
27  import org.kuali.rice.ksb.service.KSBServiceLocator;
28  
29  /**
30   * Struts action form for the {@link JavaSecurityManagementAction} 
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   *
34   */
35  public class JavaSecurityManagementForm extends ActionForm {
36  
37      private static final long serialVersionUID = -46462912979586142L;
38  
39      private String alias;
40      private String password;
41      private String passwordVerify;
42      
43      /**
44       * This method is used to check for completeness of the form as well as verification of the desired password
45       */
46      public ActionErrors validateGenerateClientKeystore(ActionMapping mapping, HttpServletRequest request) {
47          ActionErrors errors = new ActionErrors();
48          // check that all data is filled in
49          if (StringUtils.isBlank(getAlias())) {
50              errors.add("property", new ActionMessage("Alias must have a valid value.",false));
51          }
52          if (StringUtils.isBlank(getPassword()) || StringUtils.isBlank(getPasswordVerify()) ) {
53              errors.add("property", new ActionMessage("Password must have a valid value in both fields.",false));
54          }
55          if (errors.isEmpty()) {
56              // if password and passwordVerify are not equal error out
57              if (!StringUtils.equals(getPassword(), getPasswordVerify())) {
58                  errors.add("property", new ActionMessage("Passwords do not match.",false));
59              }
60          }
61          if (errors.isEmpty()) {
62              try {
63                  if (KSBServiceLocator.getJavaSecurityManagementService().isAliasInKeystore(getAlias())) {
64                      errors.add("property", new ActionMessage("Alias '" + getAlias() + "' already exists in keystore.",false));
65                  }
66              } catch (KeyStoreException e) {
67                  errors.add("property", new ActionMessage("Could not check keystore file for alias '" + getAlias(),false));
68              }
69          }
70          return errors;
71      }
72  
73      public String getAlias() {
74          return this.alias;
75      }
76      public void setAlias(String alias) {
77          if (alias == null) {
78              this.alias = null;
79          } else {
80              this.alias = alias.trim();
81          }
82      }
83      public String getPassword() {
84          return this.password;
85      }
86      public void setPassword(String password) {
87          this.password = password;
88      }
89      public String getPasswordVerify() {
90          return this.passwordVerify;
91      }
92      public void setPasswordVerify(String passwordVerify) {
93          this.passwordVerify = passwordVerify;
94      }
95  
96  }