1 16 17 package org.apache.webapp.admin.users; 18 19 20 import java.net.URLDecoder ; 21 import javax.management.MBeanServer ; 22 import javax.servlet.http.HttpServletRequest ; 23 import org.apache.struts.action.ActionError; 24 import org.apache.struts.action.ActionErrors; 25 import org.apache.struts.action.ActionForm; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.webapp.admin.ApplicationServlet; 28 import org.apache.webapp.admin.TomcatTreeBuilder; 29 30 37 38 public final class UserForm extends BaseForm { 39 40 41 43 46 private MBeanServer mserver = null; 47 48 50 53 private String fullName = null; 54 55 public String getFullName() { 56 return (this.fullName); 57 } 58 59 public void setFullName(String fullName) { 60 this.fullName = fullName; 61 } 62 63 64 67 private String groups[] = new String [0]; 68 69 public String [] getGroups() { 70 return (this.groups); 71 } 72 73 public void setGroups(String groups[]) { 74 if (groups == null) { 75 groups = new String [0]; 76 } 77 this.groups = groups; 78 } 79 80 81 84 private String password = null; 85 86 public String getPassword() { 87 return (this.password); 88 } 89 90 public void setPassword(String password) { 91 this.password = password; 92 } 93 94 95 98 private String roles[] = new String [0]; 99 100 public String [] getRoles() { 101 return (this.roles); 102 } 103 104 public void setRoles(String roles[]) { 105 if (roles == null) { 106 roles = new String [0]; 107 } 108 this.roles = roles; 109 } 110 111 112 115 private String username = null; 116 117 public String getUsername() { 118 return (this.username); 119 } 120 121 public void setUsername(String username) { 122 this.username = username; 123 } 124 125 126 128 134 public void reset(ActionMapping mapping, HttpServletRequest request) { 135 136 super.reset(mapping, request); 137 fullName = null; 138 groups = new String [0]; 139 password = null; 140 roles = new String [0]; 141 username = null; 142 143 } 144 145 146 156 public ActionErrors validate(ActionMapping mapping, 157 HttpServletRequest request) { 158 159 try { 160 if (mserver == null) { 162 mserver = ((ApplicationServlet) getServlet()).getServer(); 163 } 164 165 String databaseName = 167 URLDecoder.decode(request.getParameter("databaseName"),TomcatTreeBuilder.URL_ENCODING); 168 request.setAttribute("groupsForm", 169 UserUtils.getGroupsForm(mserver, 170 databaseName)); 171 request.setAttribute("rolesForm", 172 UserUtils.getRolesForm(mserver, 173 databaseName)); 174 } catch (Exception e) { 175 } 177 178 ActionErrors errors = new ActionErrors(); 179 180 String submit = request.getParameter("submit"); 181 183 if ((username == null) || (username.length() < 1)) { 185 errors.add("username", 186 new ActionError("users.error.username.required")); 187 } 188 189 if ((password == null) || (username.length() < 1)) { 191 errors.add("password", 192 new ActionError("users.error.password.required")); 193 } 194 195 if ((username != null) && (username.indexOf('"') >= 0)) { 197 errors.add("username", 198 new ActionError("users.error.quotes")); 199 } 200 201 if ((password != null) && (password.indexOf('"') > 0)) { 203 errors.add("description", 204 new ActionError("users.error.quotes")); 205 } 206 207 if ((fullName != null) && (fullName.indexOf('"') > 0)) { 209 errors.add("fullName", 210 new ActionError("users.error.quotes")); 211 } 212 213 215 return (errors); 216 217 } 218 219 220 } 221 | Popular Tags |