Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java @ 2984:06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
If a logged in user is not known add him to the database via the REST protocol.
flys-client/trunk@4994 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 13 Jul 2012 13:38:32 +0000 |
parents | 6266dff93ed2 |
children | 71ba3cf3ec5e |
comparison
equal
deleted
inserted
replaced
2983:725470fc57d2 | 2984:06d999e95615 |
---|---|
12 | 12 |
13 import de.intevation.flys.client.server.auth.Authentication; | 13 import de.intevation.flys.client.server.auth.Authentication; |
14 import de.intevation.flys.client.server.auth.AuthenticationException; | 14 import de.intevation.flys.client.server.auth.AuthenticationException; |
15 import de.intevation.flys.client.server.auth.AuthenticationFactory; | 15 import de.intevation.flys.client.server.auth.AuthenticationFactory; |
16 import de.intevation.flys.client.server.auth.User; | 16 import de.intevation.flys.client.server.auth.User; |
17 import de.intevation.flys.client.server.auth.UserClient; | |
17 | 18 |
18 public class LoginServlet extends HttpServlet { | 19 public class LoginServlet extends HttpServlet { |
19 | 20 |
20 private static Logger logger = Logger.getLogger(LoginServlet.class); | 21 private static Logger logger = Logger.getLogger(LoginServlet.class); |
21 | 22 |
22 private void redirectFailure(HttpServletResponse resp) throws IOException { | 23 private void redirectFailure(HttpServletResponse resp) throws IOException { |
23 resp.sendRedirect("/login.jsp"); | 24 resp.sendRedirect("/login.jsp"); |
24 } | 25 } |
25 | 26 |
26 private void redirectFailure(HttpServletResponse resp, Exception e) throws IOException { | 27 private void redirectFailure(HttpServletResponse resp, Exception e) throws IOException { |
27 resp.sendRedirect("/login.jsp?error=" + e.getMessage()); | 28 this.redirectFailure(resp, e.getMessage()); |
28 } | 29 } |
29 | 30 |
31 private void redirectFailure(HttpServletResponse resp, String message) throws IOException { | |
32 resp.sendRedirect("/login.jsp?error=" + message); | |
33 } | |
30 private void redirectSuccess(HttpServletResponse resp, String uri) throws IOException { | 34 private void redirectSuccess(HttpServletResponse resp, String uri) throws IOException { |
31 if (uri == null) { | 35 if (uri == null) { |
32 uri = "/FLYS.html"; | 36 uri = "/FLYS.html"; |
33 } | 37 } |
34 resp.sendRedirect(uri); | 38 resp.sendRedirect(uri); |
58 Authentication aresp = this.auth(username, password, encoding); | 62 Authentication aresp = this.auth(username, password, encoding); |
59 if (aresp == null || !aresp.isSuccess()) { | 63 if (aresp == null || !aresp.isSuccess()) { |
60 logger.debug("Athentication not successful"); | 64 logger.debug("Athentication not successful"); |
61 this.redirectFailure(resp); | 65 this.redirectFailure(resp); |
62 } | 66 } |
67 User user = aresp.getUser(); | |
68 | |
69 String url = getServletContext().getInitParameter("server-url"); | |
70 UserClient client = new UserClient(url); | |
71 if (!client.userExists(user)) { | |
72 if (!client.createUser(user)) { | |
73 this.redirectFailure(resp, "Could not create new user"); | |
74 } | |
75 } | |
76 | |
63 HttpSession session = req.getSession(); | 77 HttpSession session = req.getSession(); |
64 User user = aresp.getUser(); | |
65 session.setAttribute("user", user); | 78 session.setAttribute("user", user); |
66 | 79 |
67 String uri = (String)session.getAttribute("requesturi"); | 80 String uri = (String)session.getAttribute("requesturi"); |
68 | 81 |
69 this.redirectSuccess(resp, uri); | 82 this.redirectSuccess(resp, uri); |