comparison flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java @ 2980:cc126abafeab

Cosmetics in plain authentication flys-client/trunk@4978 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 13 Jul 2012 09:42:38 +0000
parents 98514ab2c9ba
children 1f64ee424f92
comparison
equal deleted inserted replaced
2979:193a113888d4 2980:cc126abafeab
6 6
7 import java.io.BufferedReader; 7 import java.io.BufferedReader;
8 import java.io.File; 8 import java.io.File;
9 import java.io.FileReader; 9 import java.io.FileReader;
10 import java.io.IOException; 10 import java.io.IOException;
11
12 import java.util.ArrayList;
11 import java.util.List; 13 import java.util.List;
12 import java.util.ArrayList;
13 14
14 public class Authenticator 15 public class Authenticator
15 implements de.intevation.flys.client.server.auth.Authenticator 16 implements de.intevation.flys.client.server.auth.Authenticator
16 { 17 {
17 public static class Authentication 18 public static class Authentication
18 implements de.intevation.flys.client.server.auth.Authentication 19 implements de.intevation.flys.client.server.auth.Authentication
19 { 20 {
20 protected String user; 21 protected String user;
21 protected String password; 22 protected String password;
22 protected List<String> roles; 23 protected List<String> roles;
23 24
24 public Authentication(String user, String password, List<String> roles) { 25 public Authentication(
26 String user,
27 String password,
28 List<String> roles
29 ) {
25 this.user = user; 30 this.user = user;
26 this.password = password; 31 this.password = password;
27 this.roles = roles; 32 this.roles = roles;
28 } 33 }
29 34
64 ) 69 )
65 throws AuthenticationException, IOException 70 throws AuthenticationException, IOException
66 { 71 {
67 File file = credentialsFile(); 72 File file = credentialsFile();
68 if (!file.canRead() || !file.isFile()) { 73 if (!file.canRead() || !file.isFile()) {
69 return new Authentication(null, null, new ArrayList<String>()); 74 return new Authentication(null, null, new ArrayList<String>(0));
70 } 75 }
71 76
72 BufferedReader reader = 77 BufferedReader reader =
73 new BufferedReader( 78 new BufferedReader(
74 new FileReader(file)); 79 new FileReader(file));
83 if (parts.length < 2) { 88 if (parts.length < 2) {
84 continue; 89 continue;
85 } 90 }
86 if (parts[0].equals(username)) { 91 if (parts[0].equals(username)) {
87 if (parts[1].equals(password)) { 92 if (parts[1].equals(password)) {
88 List<String> roles = new ArrayList<String>(parts.length - 2); 93 List<String> roles =
94 new ArrayList<String>(parts.length - 2);
95
89 for (int i = 2; i < parts.length; i++) { 96 for (int i = 2; i < parts.length; i++) {
90 roles.add(parts[i]); 97 roles.add(parts[i]);
91 } 98 }
99
92 return new Authentication(username, password, roles); 100 return new Authentication(username, password, roles);
93 } 101 }
94 // Stop: user found, wrong password 102 // Stop: user found, wrong password
95 break; 103 break;
96 } 104 }
97 } 105 }
98 } 106 }
99 finally { 107 finally {
100 reader.close(); 108 reader.close();
101 } 109 }
102 return new Authentication(null, null, new ArrayList<String>()); 110 return new Authentication(null, null, new ArrayList<String>(0));
103 } 111 }
104 } 112 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org