1 64 package com.jcorporate.expresso.services.validation; 65 66 import com.jcorporate.expresso.core.controller.Controller; 67 import com.jcorporate.expresso.core.controller.ControllerException; 68 import com.jcorporate.expresso.core.controller.ControllerRequest; 69 import com.jcorporate.expresso.core.controller.ControllerResponse; 70 import com.jcorporate.expresso.core.controller.NonHandleableException; 71 import com.jcorporate.expresso.core.controller.Transition; 72 import com.jcorporate.expresso.core.db.DBException; 73 import com.jcorporate.expresso.core.i18n.Messages; 74 import com.jcorporate.expresso.core.security.User; 75 import com.jcorporate.expresso.services.dbobj.RegistrationDomain; 76 import com.jcorporate.expresso.services.dbobj.Setup; 77 import org.apache.log4j.Logger; 78 79 import java.util.Hashtable ; 80 import java.util.StringTokenizer ; 81 import java.util.Vector ; 82 83 84 93 public class ApproveRegistrationValidator implements ValidationHandler { 94 97 protected static Logger log = Logger.getLogger(ApproveRegistrationValidator.class); 98 99 103 public ApproveRegistrationValidator() { 104 super(); 105 } 106 107 121 public void notify(Hashtable params, String URL) 122 throws AuthValidationException { 123 String dbName = (String ) params.get("db"); 126 127 String loginName = (String ) params.get("UserName"); 129 Vector addresses = new Vector (0); 130 131 try { 132 User myUser = new User(); 134 myUser.setDataContext(dbName); 135 myUser.setLoginName(loginName); 136 137 if (!myUser.find()) { 138 throw new AuthValidationException("User with login \"" + 139 loginName + "\" not found"); 140 } 141 142 RegistrationDomain rd = new RegistrationDomain(); 143 rd.setDataContext(dbName); 144 rd.setField("Name", myUser.getRegistrationDomain()); 145 146 if (!rd.find()) { 147 throw new AuthValidationException("Registration domain \"" + 148 myUser.getRegistrationDomain() + "\" not found"); 149 } 150 151 String approvers = rd.getField("Approvers"); 152 StringTokenizer stk = new StringTokenizer (approvers, ","); 153 154 while (stk.hasMoreTokens()) { 155 String approverLoginName = stk.nextToken(); 156 User approver = new User(); 157 approver.setDataContext(dbName); 158 approver.setLoginName(approverLoginName); 159 160 if (!approver.find()) { 161 throw new AuthValidationException("Approver (user) with login name \"" + 162 approverLoginName + "\" cannot be found"); 163 } 164 165 addresses.add(approver.getEmail()); 166 } 167 168 StringBuffer msg = new StringBuffer (); 169 msg.append("User \"" + loginName + 170 "\" requires approval for domain \"" + rd.getField("Name") + 171 "\".\n"); 172 msg.append("\nPlease approve or deny by clicking on link below:\n"); 173 msg.append(URL); 174 175 ValidationEntry.notifyByEmail(dbName, 177 Setup.getValue(dbName, "MAILFrom"), addresses, 178 "Registration Approval Requested", msg.toString()); 179 } catch (DBException dbe) { 180 throw new AuthValidationException("DB error accessing user \"" + 181 loginName + "\"", dbe); 182 } 183 } 184 185 202 public ControllerResponse validated(Hashtable params, 203 ControllerRequest request, ControllerResponse response, Controller ctlr) 204 throws ControllerException, NonHandleableException { 205 String dbname = (String ) params.get("db"); 208 209 String loginName = (String ) params.get("UserName"); 211 212 Transition t = new Transition(); 213 t.setControllerObject((String ) params.get("RegistrationController")); 214 t.setState("promptApproval"); 215 t.setName("promptApproval"); 216 t.addParam("db", dbname); 217 t.addParam("UserName", loginName); 218 219 request.getSession().setPersistentAttribute(ValidationEntry.SESSION_KEY, 225 request.getSession().getAttribute(ValidationEntry.SESSION_KEY)); 226 227 t.redirectTransition(request, response); 228 229 return response; 230 } 231 232 239 protected String getString(String stringCode) { 240 Object [] args = {}; 241 242 return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema", 243 stringCode, args); 244 } 245 246 247 257 protected String getString(String stringCode, Object [] args) { 258 return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema", 259 stringCode, args); 260 } 261 262 } 263 | Popular Tags |