comparison flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java @ 2985:1f64ee424f92

Corrected broken web.xml flys-client/trunk@4996 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 13 Jul 2012 13:51:58 +0000
parents cc126abafeab
children 71ba3cf3ec5e
comparison
equal deleted inserted replaced
2984:06d999e95615 2985:1f64ee424f92
10 import java.io.IOException; 10 import java.io.IOException;
11 11
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.List; 13 import java.util.List;
14 14
15 import org.apache.log4j.Logger;
16
15 public class Authenticator 17 public class Authenticator
16 implements de.intevation.flys.client.server.auth.Authenticator 18 implements de.intevation.flys.client.server.auth.Authenticator
17 { 19 {
20 private static final Logger log =
21 Logger.getLogger(Authenticator.class);
22
18 public static class Authentication 23 public static class Authentication
19 implements de.intevation.flys.client.server.auth.Authentication 24 implements de.intevation.flys.client.server.auth.Authentication
20 { 25 {
21 protected String user; 26 protected String user;
22 protected String password; 27 protected String password;
69 ) 74 )
70 throws AuthenticationException, IOException 75 throws AuthenticationException, IOException
71 { 76 {
72 File file = credentialsFile(); 77 File file = credentialsFile();
73 if (!file.canRead() || !file.isFile()) { 78 if (!file.canRead() || !file.isFile()) {
79 log.error("cannot find user file '" + file + "'");
74 return new Authentication(null, null, new ArrayList<String>(0)); 80 return new Authentication(null, null, new ArrayList<String>(0));
75 } 81 }
76 82
77 BufferedReader reader = 83 BufferedReader reader =
78 new BufferedReader( 84 new BufferedReader(
87 String [] parts = line.split("\\s+"); 93 String [] parts = line.split("\\s+");
88 if (parts.length < 2) { 94 if (parts.length < 2) {
89 continue; 95 continue;
90 } 96 }
91 if (parts[0].equals(username)) { 97 if (parts[0].equals(username)) {
98 log.debug("user '" + username + "' found.");
92 if (parts[1].equals(password)) { 99 if (parts[1].equals(password)) {
93 List<String> roles = 100 List<String> roles =
94 new ArrayList<String>(parts.length - 2); 101 new ArrayList<String>(parts.length - 2);
95 102
96 for (int i = 2; i < parts.length; i++) { 103 for (int i = 2; i < parts.length; i++) {
97 roles.add(parts[i]); 104 roles.add(parts[i]);
98 } 105 }
99 106
107 log.debug("success");
100 return new Authentication(username, password, roles); 108 return new Authentication(username, password, roles);
101 } 109 }
102 // Stop: user found, wrong password 110 // Stop: user found, wrong password
103 break; 111 break;
104 } 112 }
105 } 113 }
106 } 114 }
107 finally { 115 finally {
108 reader.close(); 116 reader.close();
109 } 117 }
118 log.debug("failed");
110 return new Authentication(null, null, new ArrayList<String>(0)); 119 return new Authentication(null, null, new ArrayList<String>(0));
111 } 120 }
112 } 121 }
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 122 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org