1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 /***
66 * ControllerSecurityMatrix.java Copyright 2000, 2001 Jcorporate Ltd.
67 */
68 package com.sri.emo.controller;
69
70 import com.jcorporate.expresso.core.controller.*;
71 import com.jcorporate.expresso.core.db.DBException;
72 import com.jcorporate.expresso.core.security.User;
73 import com.jcorporate.expresso.services.controller.SimpleRegistration;
74 import com.jcorporate.expresso.services.dbobj.RegistrationDomain;
75 import com.jcorporate.expresso.services.dbobj.Setup;
76 import com.jcorporate.expresso.services.validation.AuthValidationException;
77 import com.jcorporate.expresso.services.validation.LoginEmailValidator;
78 import com.jcorporate.expresso.services.validation.ValidationEntry;
79 import com.sri.emo.EmoSchema;
80
81 import javax.servlet.http.HttpServletRequest;
82
83
84 /***
85 * This is the implementation of Registration.
86 */
87 public class EmoRegistration
88 extends SimpleRegistration {
89
90 /***
91 *
92 */
93 private static final long serialVersionUID = 1L;
94 private static String[] PUBLIC_METHODS = {"showDBMenu", "emailValidate",
95 "promptSelfRegister", "processSelfRegister", "processRevalidate"};
96
97 /***
98 * constructor.
99 */
100 public EmoRegistration() {
101 }
102
103 /***
104 * Creates the validation entry for validating email.
105 *
106 * @param request The ControllerRequest object
107 * @param response The ControllerResponse object
108 * @param user the user that is registering
109 * @param rd The registration domain that the user is signing up for
110 * @param loginControllerName the name of the login controller used
111 * @throws com.jcorporate.expresso.core.db.DBException
112 * upon data access error
113 * @throws com.jcorporate.expresso.core.controller.ControllerException
114 * for other errors
115 */
116 protected void setupEmailValidation(final ExpressoRequest request,
117 final ExpressoResponse response,
118 final User user,
119 final RegistrationDomain rd,
120 final String loginControllerName) throws DBException, ControllerException {
121 String emailAuthCode = user.getEmailAuthCode();
122 String loginName = user.getLoginName();
123 user.setEmailValCode(emailAuthCode);
124 user.update();
125
126 HttpServletRequest hreq = (HttpServletRequest) ((ServletControllerRequest) request).getServletRequest();
127
128 try {
129
130 ValidationEntry ve = new ValidationEntry(request.getDataContext());
131 ve.expiresAfter(72, 0, 0);
132 ve.setValidationHandler(LoginEmailValidator.class);
133 ve.setTitle("Registration Email Validation");
134 ve.setDesc("user=" + loginName + ", db=" + request.getDataContext());
135 ve.setServer(Setup.getValueRequired("HTTPServ"));
136 ve.setPort(Integer.toString(hreq.getServerPort()));
137 ve.setContextPath(hreq.getContextPath());
138 ve.addParam("db", request.getDataContext());
139 ve.addParam("UserName", loginName);
140 ve.addParam("RegistrationController", this.getClass().getName());
141 ve.addParam("LoginController", loginControllerName);
142
143
144
145
146 ve.addParam("schema", EmoSchema.class.getName());
147
148
149 ve.submit();
150 } catch (AuthValidationException avex) {
151 delayLogin();
152 throw new ControllerException("Validation framework exception",
153 avex);
154 }
155
156 }
157
158
159 /***
160 * For database controllers, we check if the new state is allowed
161 * against the database objects for that purpose
162 *
163 * @param newState The name of the new state that is being requested; controller class is assumed to be 'this'
164 * @param myRequest the <code>ControllerRequest</code> object
165 * @return True if the state is permitted for this user, else false
166 * @throws com.jcorporate.expresso.core.controller.ControllerException
167 * if another undefined error takes place while
168 * checking security.
169 */
170 public boolean stateAllowed(final String newState, final ExpressoRequest myRequest) throws ControllerException {
171
172 for (int i = 0; i < PUBLIC_METHODS.length; i++) {
173 String s = PUBLIC_METHODS[i];
174 if (s.equals(newState)) {
175 return true;
176 }
177 }
178 return super.stateAllowed(newState, myRequest);
179 }
180
181 /***
182 * Processes post Registration If the user is done.
183 *
184 * @param request the ControllerRequest Object
185 * @param response the ControllerResponse object
186 * @param user An instantiated user object representing the current User
187 * registering
188 * @param rd The RegistrationDomain that this user is registering for
189 * @param loginControllerName The name of the login controller used for
190 * referencing back to this class
191 * @return A completed ControllerResponse object
192 * @throws com.jcorporate.expresso.core.controller.NonHandleableException
193 * upon fatal error
194 */
195 protected ExpressoResponse processPostRegistration(ExpressoRequest request,
196 ExpressoResponse response,
197 User user,
198 RegistrationDomain rd,
199 String loginControllerName) throws DBException,
200 ControllerException, NonHandleableException {
201
202
203
204
205
206
207 ExpressoResponse result = super.processPostRegistration(request, response, user, rd, loginControllerName);
208
209 result.add(new Output("email", user.getEmail()));
210 return result;
211
212
213 }
214 }