2 * Copyright 2009 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 gr.ebs.gss.client.exceptions.ObjectNotFoundException;
22 import gr.ebs.gss.client.exceptions.RpcException;
23 import gr.ebs.gss.server.domain.User;
25 import java.io.IOException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
34 * The servlet that handles user policy acceptance.
38 public class Policy extends BaseServlet {
40 * The request parameter name for the acceptance flag.
42 private static final String ACCEPT_PARAM = "accept";
45 * The request parameter name for the original query string to the jsp.
47 private static final String QUERY_PARAM = "queryString";
50 * The request parameter name for the username.
52 private static final String USER_PARAM = "user";
55 * The serial version UID of the class.
57 private static final long serialVersionUID = 1L;
62 private static Log logger = LogFactory.getLog(Policy.class);
65 public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
66 String queryString = request.getParameter(QUERY_PARAM);
67 String accept = request.getParameter(ACCEPT_PARAM);
68 String username = request.getParameter(USER_PARAM);
69 response.setContentType("text/html");
70 if (username == null) {
71 response.sendError(HttpServletResponse.SC_NOT_FOUND);
76 user = getService().findUser(username);
78 response.sendError(HttpServletResponse.SC_NOT_FOUND);
81 if ("on".equalsIgnoreCase(accept))
82 user = getService().updateUserPolicyAcceptance(user.getId(), true);
83 response.sendRedirect(request.getContextPath()+ "/login?" + queryString);
84 } catch (RpcException e) {
85 String error = "An error occurred while communicating with the service";
86 logger.error(error, e);
87 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
89 } catch (ObjectNotFoundException e) {
90 String error = "User " + username + " was not found";
91 logger.warn(error, e);
92 response.sendError(HttpServletResponse.SC_NOT_FOUND, error);