2 * Copyright 2010 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server;
21 import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
22 import gr.ebs.gss.client.exceptions.RpcException;
23 import gr.ebs.gss.server.domain.Invitation;
24 import gr.ebs.gss.server.domain.User;
26 import java.io.IOException;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
35 * The servlet that handles coupons for quota upgrades.
39 public class CouponHandler extends BaseServlet {
41 * The request parameter name for the coupon code.
43 private static final String CODE_PARAM = "code";
46 * The serial version UID of the class.
48 private static final long serialVersionUID = 1L;
53 private static Log logger = LogFactory.getLog(CouponHandler.class);
56 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
57 response.sendRedirect("coupon.jsp");
61 public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
62 String code = request.getParameter(CODE_PARAM);
63 response.setContentType("text/html");
65 // Validate input parameters.
66 if (code == null || code.isEmpty()) {
67 response.sendRedirect("coupon.jsp?error=" + encode("No code was specified"));
72 Invitation invite = getService().findInvite(code);
74 response.sendRedirect("coupon.jsp?code=&error=" + encode("The specified code was not found"));
77 String firstname = invite.getFirstname() == null? "": invite.getFirstname();
78 String lastname = invite.getLastname() == null? "": invite.getLastname();
79 String email = invite.getEmail() == null? "": invite.getEmail();
81 Object usernameAttr = request.getAttribute("REMOTE_USER");
82 if (getConfiguration().getString("testUsername") != null)
83 usernameAttr = getConfiguration().getString("testUsername");
84 if (usernameAttr == null) {
85 Object nameAttr = request.getAttribute("HTTP_SHIB_INETORGPERSON_DISPLAYNAME");
86 Object givennameAttr = request.getAttribute("HTTP_SHIB_INETORGPERSON_GIVENNAME"); // Multi-valued
87 Object cnAttr = request.getAttribute("HTTP_SHIB_PERSON_COMMONNAME"); // Multi-valued
88 Object snAttr = request.getAttribute("HTTP_SHIB_PERSON_SURNAME"); // Multi-valued
89 Object mailAttr = request.getAttribute("HTTP_SHIB_INETORGPERSON_MAIL"); // Multi-valued
90 Object userclassAttr = request.getAttribute("HTTP_SHIB_EP_UNSCOPEDAFFILIATION"); // Multi-valued
91 String authErrorUrl = "authenticationError.jsp";
92 authErrorUrl += "?name=" + (nameAttr==null? "-": nameAttr.toString());
93 authErrorUrl += "&givenname=" + (givennameAttr==null? "-": givennameAttr.toString());
94 authErrorUrl += "&sn=" + (snAttr==null? "-": snAttr.toString());
95 authErrorUrl += "&cn=" + (cnAttr==null? "-": cnAttr.toString());
96 authErrorUrl += "&mail=" + (mailAttr==null? "-": mailAttr.toString());
97 authErrorUrl += "&userclass=" + (userclassAttr==null? "-": userclassAttr.toString());
98 response.sendRedirect(authErrorUrl);
101 String username = decodeAttribute(usernameAttr);
104 user = getService().findUser(username);
106 handleException(response, encode("Your user account was not found!"));
109 } catch (RpcException e) {
110 String error = "An error occurred while communicating with the service";
111 logger.error(error, e);
112 handleException(response, encode(error));
115 response.sendRedirect("couponSubmission.jsp?firstname=" +
116 encode(firstname) + "&lastname=" + encode(lastname) +
117 "&email=" + encode(email) + "&code=" + encode(code) +
118 "&username=" + encode(username));
119 } catch (RpcException e) {
121 handleException(response, encode("An error occurred while communicating with the service"));
125 private void handleException(HttpServletResponse response, String error) throws IOException {
126 String errorUrl = "coupon.jsp?error=" + error;
127 response.sendRedirect(errorUrl);