changeset 3696:a050cb5f303f

Cosmetics flys-client/trunk@5395 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Sat, 08 Sep 2012 11:26:30 +0000
parents 5e4d91304484
children 2e12518ff5b4
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java flys-client/src/main/java/de/intevation/flys/client/server/RemoteServiceServlet.java flys-client/src/main/java/de/intevation/flys/client/server/auth/AuthenticationFactory.java flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java
diffstat 7 files changed, 46 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Sep 07 15:58:10 2012 +0000
+++ b/flys-client/ChangeLog	Sat Sep 08 11:26:30 2012 +0000
@@ -1,3 +1,13 @@
+2012-09-08	Christian Lins	<christian.lins@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/RemoteServiceServlet.java,
+	  src/main/java/de/intevation/flys/client/server/LoginServlet.java,
+	  src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java,
+	  src/main/java/de/intevation/flys/client/server/auth/AuthenticationFactory.java,
+	  src/main/java/de/intevation/flys/client/server/auth/UserClient.java,
+	  src/main/java/de/intevation/flys/client/client/FLYS.java:
+	  Cosmetics, add robustness checks etc.
+
 2012-09-07	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/UserServiceImpl.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Fri Sep 07 15:58:10 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Sat Sep 08 11:26:30 2012 +0000
@@ -137,7 +137,7 @@
         Config config = Config.getInstance();
         String locale = config.getLocale();
 
-        getRivers();
+        getRivers(); // Useless call?
 
         userService.getCurrentUser(locale, new AsyncCallback<User>() {
             @Override
--- a/flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java	Fri Sep 07 15:58:10 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java	Sat Sep 08 11:26:30 2012 +0000
@@ -49,7 +49,8 @@
 
     @Override
     protected void doPost(HttpServletRequest req, HttpServletResponse resp)
-    throws ServletException, IOException {
+    throws ServletException, IOException 
+    {
         String encoding = req.getCharacterEncoding();
         String username = req.getParameter("username");
         String password = req.getParameter("password");
@@ -59,11 +60,13 @@
         if (username == null || password == null) {
             logger.debug("No username or password provided");
             this.redirectFailure(resp);
+            return;
         }
+        
         try {
             Authentication aresp = this.auth(username, password, encoding);
             if (aresp == null || !aresp.isSuccess()) {
-                logger.debug("Athentication not successful");
+                logger.debug("Authentication not successful");
                 this.redirectFailure(resp);
             }
             User user = aresp.getUser();
@@ -91,7 +94,8 @@
     }
 
     private Authentication auth(String username, String password, String encoding)
-        throws AuthenticationException, IOException {
+        throws AuthenticationException, IOException 
+    {
         ServletContext sc = this.getServletContext();
         Features features = (Features)sc.getAttribute(Features.CONTEXT_ATTRIBUTE);
         String auth = sc.getInitParameter("authentication");
--- a/flys-client/src/main/java/de/intevation/flys/client/server/RemoteServiceServlet.java	Fri Sep 07 15:58:10 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/RemoteServiceServlet.java	Sat Sep 08 11:26:30 2012 +0000
@@ -9,7 +9,7 @@
 {
     /**
      * Return the current logged in user from the HTTP Session
-    */
+     */
     public User getUser() {
         HttpSession session = this.getThreadLocalRequest().getSession();
         return (User)session.getAttribute("user");
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/AuthenticationFactory.java	Fri Sep 07 15:58:10 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/AuthenticationFactory.java	Sat Sep 08 11:26:30 2012 +0000
@@ -8,19 +8,24 @@
         Logger.getLogger(AuthenticationFactory.class);
 
     public static Authenticator getInstance(String name)
-        throws IllegalArgumentException {
-        if (name == null
-        || name.equalsIgnoreCase("was")
-        || name.equalsIgnoreCase("ggina")) {
+        throws IllegalArgumentException
+    {
+        if (name == null) {
+            throw new IllegalArgumentException("Authentication type name is null");
+        }
+        
+        if (name.equalsIgnoreCase("was") ||
+            name.equalsIgnoreCase("ggina")) {
             log.debug("Using GGinA authenticator.");
             return
                 new de.intevation.flys.client.server.auth.was.Authenticator();
         }
-        if (name.equalsIgnoreCase("plain")) {
+        else if (name.equalsIgnoreCase("plain")) {
             log.debug("Using plain authenticator.");
             return
                 new de.intevation.flys.client.server.auth.plain.Authenticator();
         }
+        
         throw new IllegalArgumentException("Unkown Authentication " + name);
     }
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java	Fri Sep 07 15:58:10 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java	Sat Sep 08 11:26:30 2012 +0000
@@ -50,6 +50,11 @@
     }
 
     public boolean createUser(User user) throws ConnectionException {
+        if(user == null) {
+            logger.warn("createUser: given user is null");
+            return false;
+        }
+        
         logger.debug("Creating new user " + user.getName());
         HttpClient client = new HttpClientImpl(this.url);
 
@@ -107,6 +112,10 @@
     }
 
     public Element findUser(User user) throws ConnectionException {
+        if(user == null) {
+            throw new IllegalArgumentException("user is null");
+        }
+        
         HttpClient client = new HttpClientImpl(this.url);
 
         Document document = XMLUtils.newDocument();
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java	Fri Sep 07 15:58:10 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java	Sat Sep 08 11:26:30 2012 +0000
@@ -16,6 +16,9 @@
 
 import de.intevation.flys.client.server.features.Features;
 
+/**
+ * Authenticator that uses a local file as user backend.
+ */
 public class Authenticator
 implements   de.intevation.flys.client.server.auth.Authenticator
 {
@@ -93,14 +96,15 @@
         try {
             String line;
             while ((line = reader.readLine()) != null) {
-                if ((line = line.trim()).length() == 0
-                || line.startsWith("#")) {
+                if (line.startsWith("#")) {
                     continue;
                 }
-                String [] parts = line.split("\\s+");
+                
+                String[] parts = line.split("\\s+");
                 if (parts.length < 2) {
                     continue;
                 }
+                
                 if (parts[0].equals(username)) {
                     log.debug("user '" + username + "' found.");
                     if (parts[1].equals(password)) {
@@ -123,7 +127,7 @@
             reader.close();
         }
         log.debug("failed");
-        return new Authentication(null, null, new ArrayList<String>(0), features);
+        return null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org