diff 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
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java	Fri Jul 13 11:31:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java	Fri Jul 13 13:38:32 2012 +0000
@@ -14,6 +14,7 @@
 import de.intevation.flys.client.server.auth.AuthenticationException;
 import de.intevation.flys.client.server.auth.AuthenticationFactory;
 import de.intevation.flys.client.server.auth.User;
+import de.intevation.flys.client.server.auth.UserClient;
 
 public class LoginServlet extends HttpServlet {
 
@@ -24,9 +25,12 @@
     }
 
     private void redirectFailure(HttpServletResponse resp, Exception e) throws IOException {
-        resp.sendRedirect("/login.jsp?error=" + e.getMessage());
+        this.redirectFailure(resp, e.getMessage());
     }
 
+    private void redirectFailure(HttpServletResponse resp, String message) throws IOException {
+        resp.sendRedirect("/login.jsp?error=" + message);
+    }
     private void redirectSuccess(HttpServletResponse resp, String uri) throws IOException {
         if (uri == null) {
             uri = "/FLYS.html";
@@ -60,8 +64,17 @@
                 logger.debug("Athentication not successful");
                 this.redirectFailure(resp);
             }
+            User user = aresp.getUser();
+
+            String url = getServletContext().getInitParameter("server-url");
+            UserClient client = new UserClient(url);
+            if (!client.userExists(user)) {
+                if (!client.createUser(user)) {
+                    this.redirectFailure(resp, "Could not create new user");
+                }
+            }
+
             HttpSession session = req.getSession();
-            User user = aresp.getUser();
             session.setAttribute("user", user);
 
             String uri = (String)session.getAttribute("requesturi");

http://dive4elements.wald.intevation.org