diff flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java @ 2978:98514ab2c9ba

Implement getting a list of roles from a logged in user flys-client/trunk@4975 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 13 Jul 2012 09:27:53 +0000
parents 5ba0a6efdf3b
children cc126abafeab
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java	Fri Jul 13 08:54:57 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java	Fri Jul 13 09:27:53 2012 +0000
@@ -8,6 +8,8 @@
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
 
 public class Authenticator
 implements   de.intevation.flys.client.server.auth.Authenticator
@@ -17,10 +19,12 @@
     {
         protected String user;
         protected String password;
+        protected List<String> roles;
 
-        public Authentication(String user, String password) {
+        public Authentication(String user, String password, List<String> roles) {
             this.user     = user;
             this.password = password;
+            this.roles    = roles;
         }
 
         @Override
@@ -31,7 +35,7 @@
         @Override
         public User getUser() {
             return isSuccess()
-                ? new DefaultUser(user, password, false)
+                ? new DefaultUser(user, password, false, roles)
                 : null;
         }
     } // class Authentication
@@ -62,7 +66,7 @@
     {
         File file = credentialsFile();
         if (!file.canRead() || !file.isFile()) {
-            return new Authentication(null, null);
+            return new Authentication(null, null, new ArrayList<String>());
         }
 
         BufferedReader reader =
@@ -76,13 +80,16 @@
                     continue;
                 }
                 String [] parts = line.split("\\s+");
-                // TODO: role?
                 if (parts.length < 2) {
                     continue;
                 }
                 if (parts[0].equals(username)) {
                     if (parts[1].equals(password)) {
-                        return new Authentication(username, password);
+                        List<String> roles = new ArrayList<String>(parts.length - 2);
+                        for (int i = 2; i < parts.length; i++) {
+                            roles.add(parts[i]);
+                        }
+                        return new Authentication(username, password, roles);
                     }
                     // Stop: user found, wrong password
                     break;
@@ -92,7 +99,7 @@
         finally {
             reader.close();
         }
-        return new Authentication(null, null);
+        return new Authentication(null, null, new ArrayList<String>());
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org