View Javadoc

1   /* ====================================================================
2    * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3    *
4    * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5    *
6    * Redistribution and use in source and binary forms, with or without
7    * modification, are permitted provided that the following conditions
8    * are met:
9    *
10   * 1. Redistributions of source code must retain the above copyright
11   *    notice, this list of conditions and the following disclaimer.
12   *
13   * 2. Redistributions in binary form must reproduce the above copyright
14   *    notice, this list of conditions and the following disclaimer in
15   *    the documentation and/or other materials provided with the
16   *    distribution.
17   *
18   * 3. The end-user documentation included with the redistribution,
19   *    if any, must include the following acknowledgment:
20   *       "This product includes software developed by Jcorporate Ltd.
21   *        (http://www.jcorporate.com/)."
22   *    Alternately, this acknowledgment may appear in the software itself,
23   *    if and wherever such third-party acknowledgments normally appear.
24   *
25   * 4. "Jcorporate" and product names such as "Expresso" must
26   *    not be used to endorse or promote products derived from this
27   *    software without prior written permission. For written permission,
28   *    please contact info@jcorporate.com.
29   *
30   * 5. Products derived from this software may not be called "Expresso",
31   *    or other Jcorporate product names; nor may "Expresso" or other
32   *    Jcorporate product names appear in their name, without prior
33   *    written permission of Jcorporate Ltd.
34   *
35   * 6. No product derived from this software may compete in the same
36   *    market space, i.e. framework, without prior written permission
37   *    of Jcorporate Ltd. For written permission, please contact
38   *    partners@jcorporate.com.
39   *
40   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43   * DISCLAIMED.  IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46   * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51   * SUCH DAMAGE.
52   * ====================================================================
53   *
54   * This software consists of voluntary contributions made by many
55   * individuals on behalf of the Jcorporate Ltd. Contributions back
56   * to the project(s) are encouraged when you make modifications.
57   * Please send them to support@jcorporate.com. For more information
58   * on Jcorporate Ltd. and its products, please see
59   * <http://www.jcorporate.com/>.
60   *
61   * Portions of this software are based upon other open source
62   * products and are subject to their respective licenses.
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); //Expires after 72 hours
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             /// here's the diff
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     } /* stateAllowed(String) */
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         // allow our message bundle to override
203 //        Stack stack = response.getSchemaStack(); // already comes with expresso; assumes this is ONLY place stack is manipulated
204 //        stack.push(EmoSchema.class.getName());
205 //        response.setSchemaStack(stack);
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 }