Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java @ 3485:71ba3cf3ec5e
Refactor Authentication to allow to pass the Freatures to the user class
The Features class can be used to receive the allowed features for the users
roles.
flys-client/trunk@5183 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 10 Aug 2012 07:06:18 +0000 |
parents | 1f64ee424f92 |
children | 04977c883369 |
comparison
equal
deleted
inserted
replaced
3484:83845aa322ea | 3485:71ba3cf3ec5e |
---|---|
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; | 15 import org.apache.log4j.Logger; |
16 | 16 |
17 import de.intevation.flys.client.server.features.Features; | |
18 | |
17 public class Authenticator | 19 public class Authenticator |
18 implements de.intevation.flys.client.server.auth.Authenticator | 20 implements de.intevation.flys.client.server.auth.Authenticator |
19 { | 21 { |
20 private static final Logger log = | 22 private static final Logger log = |
21 Logger.getLogger(Authenticator.class); | 23 Logger.getLogger(Authenticator.class); |
24 implements de.intevation.flys.client.server.auth.Authentication | 26 implements de.intevation.flys.client.server.auth.Authentication |
25 { | 27 { |
26 protected String user; | 28 protected String user; |
27 protected String password; | 29 protected String password; |
28 protected List<String> roles; | 30 protected List<String> roles; |
31 protected Features features; | |
29 | 32 |
30 public Authentication( | 33 public Authentication( |
31 String user, | 34 String user, |
32 String password, | 35 String password, |
33 List<String> roles | 36 List<String> roles, |
37 Features features | |
34 ) { | 38 ) { |
35 this.user = user; | 39 this.user = user; |
36 this.password = password; | 40 this.password = password; |
37 this.roles = roles; | 41 this.roles = roles; |
42 this.features = features; | |
38 } | 43 } |
39 | 44 |
40 @Override | 45 @Override |
41 public boolean isSuccess() { | 46 public boolean isSuccess() { |
42 return user != null; | 47 return user != null; |
43 } | 48 } |
44 | 49 |
45 @Override | 50 @Override |
46 public User getUser() { | 51 public User getUser() { |
47 return isSuccess() | 52 return isSuccess() |
48 ? new DefaultUser(user, password, false, roles) | 53 ? new DefaultUser(user, password, false, roles, this.features.getFeatures(roles)) |
49 : null; | 54 : null; |
50 } | 55 } |
51 } // class Authentication | 56 } // class Authentication |
52 | 57 |
53 public Authenticator() { | 58 public Authenticator() { |
68 | 73 |
69 @Override | 74 @Override |
70 public de.intevation.flys.client.server.auth.Authentication auth( | 75 public de.intevation.flys.client.server.auth.Authentication auth( |
71 String username, | 76 String username, |
72 String password, | 77 String password, |
73 String encoding | 78 String encoding, |
79 Features features | |
74 ) | 80 ) |
75 throws AuthenticationException, IOException | 81 throws AuthenticationException, IOException |
76 { | 82 { |
77 File file = credentialsFile(); | 83 File file = credentialsFile(); |
78 if (!file.canRead() || !file.isFile()) { | 84 if (!file.canRead() || !file.isFile()) { |
79 log.error("cannot find user file '" + file + "'"); | 85 log.error("cannot find user file '" + file + "'"); |
80 return new Authentication(null, null, new ArrayList<String>(0)); | 86 return new Authentication(null, null, new ArrayList<String>(0), features); |
81 } | 87 } |
82 | 88 |
83 BufferedReader reader = | 89 BufferedReader reader = |
84 new BufferedReader( | 90 new BufferedReader( |
85 new FileReader(file)); | 91 new FileReader(file)); |
103 for (int i = 2; i < parts.length; i++) { | 109 for (int i = 2; i < parts.length; i++) { |
104 roles.add(parts[i]); | 110 roles.add(parts[i]); |
105 } | 111 } |
106 | 112 |
107 log.debug("success"); | 113 log.debug("success"); |
108 return new Authentication(username, password, roles); | 114 return new Authentication(username, password, roles, features); |
109 } | 115 } |
110 // Stop: user found, wrong password | 116 // Stop: user found, wrong password |
111 break; | 117 break; |
112 } | 118 } |
113 } | 119 } |
114 } | 120 } |
115 finally { | 121 finally { |
116 reader.close(); | 122 reader.close(); |
117 } | 123 } |
118 log.debug("failed"); | 124 log.debug("failed"); |
119 return new Authentication(null, null, new ArrayList<String>(0)); | 125 return new Authentication(null, null, new ArrayList<String>(0), features); |
120 } | 126 } |
121 } | 127 } |
122 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 128 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |