Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / server / Policy.java @ 092998fe

History | View | Annotate | Download (2.9 kB)

1 0a4b8f82 pastith
/*
2 0a4b8f82 pastith
 * Copyright 2009 Electronic Business Systems Ltd.
3 0a4b8f82 pastith
 *
4 0a4b8f82 pastith
 * This file is part of GSS.
5 0a4b8f82 pastith
 *
6 0a4b8f82 pastith
 * GSS is free software: you can redistribute it and/or modify
7 0a4b8f82 pastith
 * it under the terms of the GNU General Public License as published by
8 0a4b8f82 pastith
 * the Free Software Foundation, either version 3 of the License, or
9 0a4b8f82 pastith
 * (at your option) any later version.
10 0a4b8f82 pastith
 *
11 0a4b8f82 pastith
 * GSS is distributed in the hope that it will be useful,
12 0a4b8f82 pastith
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 0a4b8f82 pastith
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 0a4b8f82 pastith
 * GNU General Public License for more details.
15 0a4b8f82 pastith
 *
16 0a4b8f82 pastith
 * You should have received a copy of the GNU General Public License
17 0a4b8f82 pastith
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 0a4b8f82 pastith
 */
19 0a4b8f82 pastith
package gr.ebs.gss.server;
20 0a4b8f82 pastith
21 0a4b8f82 pastith
import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
22 0a4b8f82 pastith
import gr.ebs.gss.client.exceptions.RpcException;
23 0a4b8f82 pastith
import gr.ebs.gss.server.domain.User;
24 0a4b8f82 pastith
25 0a4b8f82 pastith
import java.io.IOException;
26 0a4b8f82 pastith
27 0a4b8f82 pastith
import javax.servlet.http.HttpServletRequest;
28 0a4b8f82 pastith
import javax.servlet.http.HttpServletResponse;
29 0a4b8f82 pastith
30 0a4b8f82 pastith
import org.apache.commons.logging.Log;
31 0a4b8f82 pastith
import org.apache.commons.logging.LogFactory;
32 0a4b8f82 pastith
33 0a4b8f82 pastith
/**
34 0a4b8f82 pastith
 * The servlet that handles user policy acceptance.
35 0a4b8f82 pastith
 *
36 0a4b8f82 pastith
 * @author past
37 0a4b8f82 pastith
 */
38 978061e3 Panagiotis Astithas
public class Policy extends BaseServlet {
39 0a4b8f82 pastith
        /**
40 0a4b8f82 pastith
         * The request parameter name for the acceptance flag.
41 0a4b8f82 pastith
         */
42 0a4b8f82 pastith
        private static final String ACCEPT_PARAM = "accept";
43 0a4b8f82 pastith
44 0a4b8f82 pastith
        /**
45 0a4b8f82 pastith
         * The request parameter name for the original query string to the jsp.
46 0a4b8f82 pastith
         */
47 0a4b8f82 pastith
        private static final String QUERY_PARAM = "queryString";
48 0a4b8f82 pastith
49 0a4b8f82 pastith
        /**
50 0a4b8f82 pastith
         * The request parameter name for the username.
51 0a4b8f82 pastith
         */
52 0a4b8f82 pastith
        private static final String USER_PARAM = "user";
53 0a4b8f82 pastith
54 0a4b8f82 pastith
        /**
55 0a4b8f82 pastith
         * The serial version UID of the class.
56 0a4b8f82 pastith
         */
57 0a4b8f82 pastith
        private static final long serialVersionUID = 1L;
58 0a4b8f82 pastith
59 0a4b8f82 pastith
        /**
60 0a4b8f82 pastith
         * The logger.
61 0a4b8f82 pastith
         */
62 0a4b8f82 pastith
        private static Log logger = LogFactory.getLog(Policy.class);
63 0a4b8f82 pastith
64 0a4b8f82 pastith
        @Override
65 0a4b8f82 pastith
        public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
66 0a4b8f82 pastith
                String queryString = request.getParameter(QUERY_PARAM);
67 0a4b8f82 pastith
                String accept = request.getParameter(ACCEPT_PARAM);
68 0a4b8f82 pastith
                String username = request.getParameter(USER_PARAM);
69 0a4b8f82 pastith
                response.setContentType("text/html");
70 0a4b8f82 pastith
                if (username == null) {
71 0a4b8f82 pastith
                        response.sendError(HttpServletResponse.SC_NOT_FOUND);
72 0a4b8f82 pastith
                        return;
73 0a4b8f82 pastith
                }
74 0a4b8f82 pastith
                User user = null;
75 0a4b8f82 pastith
                try {
76 0a4b8f82 pastith
                        user = getService().findUser(username);
77 0a4b8f82 pastith
                        if (user == null) {
78 0a4b8f82 pastith
                                response.sendError(HttpServletResponse.SC_NOT_FOUND);
79 0a4b8f82 pastith
                                return;
80 0a4b8f82 pastith
                        }
81 0a4b8f82 pastith
                        if ("on".equalsIgnoreCase(accept))
82 0a4b8f82 pastith
                                user = getService().updateUserPolicyAcceptance(user.getId(), true);
83 0a4b8f82 pastith
                        response.sendRedirect(request.getContextPath()+ "/login?" + queryString);
84 0a4b8f82 pastith
                } catch (RpcException e) {
85 0a4b8f82 pastith
                        String error = "An error occurred while communicating with the service";
86 0a4b8f82 pastith
                        logger.error(error, e);
87 0a4b8f82 pastith
                        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
88 0a4b8f82 pastith
                        return;
89 0a4b8f82 pastith
                } catch (ObjectNotFoundException e) {
90 0a4b8f82 pastith
                        String error = "User " + username + " was not found";
91 0a4b8f82 pastith
                        logger.warn(error, e);
92 0a4b8f82 pastith
                        response.sendError(HttpServletResponse.SC_NOT_FOUND, error);
93 0a4b8f82 pastith
                        return;
94 0a4b8f82 pastith
                }
95 0a4b8f82 pastith
        }
96 0a4b8f82 pastith
}