Mercurial > dive4elements > river
changeset 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 | 5161e25392ea |
children | 193a113888d4 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/auth/DefaultUser.java flys-client/src/main/java/de/intevation/flys/client/server/auth/User.java flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Response.java flys-client/src/main/java/de/intevation/flys/client/server/auth/was/User.java |
diffstat | 6 files changed, 50 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri Jul 13 08:54:57 2012 +0000 +++ b/flys-client/ChangeLog Fri Jul 13 09:27:53 2012 +0000 @@ -1,3 +1,12 @@ +2012-07-13 Björn Ricks <bjoern.ricks@intevation.de> + + * src/main/java/de/intevation/flys/client/server/auth/User.java, + src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java + src/main/java/de/intevation/flys/client/server/auth/DefaultUser.java + src/main/java/de/intevation/flys/client/server/auth/was/Response.java + src/main/java/de/intevation/flys/client/server/auth/was/User.java: + Implement getting a list of roles from a logged in user. + 2012-07-13 Raimund Renkert <raimund.renkert@intevation.de> * main/java/de/intevation/flys/client/server/CollectionHelper.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/DefaultUser.java Fri Jul 13 08:54:57 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/DefaultUser.java Fri Jul 13 09:27:53 2012 +0000 @@ -1,19 +1,24 @@ package de.intevation.flys.client.server.auth; +import java.util.List; +import java.util.LinkedList; + public class DefaultUser implements User { protected String name; protected String password; protected boolean expired; + protected List<String> roles; public DefaultUser() { } - public DefaultUser(String name, String password, boolean expired) { + public DefaultUser(String name, String password, boolean expired, List<String> roles) { this.name = name; this.password = password; this.expired = expired; + this.roles = roles; } @Override @@ -42,5 +47,15 @@ public void setExpired(boolean expired) { this.expired = expired; } + + @Override + public List<String> getRoles() { + // return clone of the list? + return this.roles; + } + + public void setRoles(List<String> roles) { + this.roles = roles; + } } // vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/User.java Fri Jul 13 08:54:57 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/User.java Fri Jul 13 09:27:53 2012 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.client.server.auth; +import java.util.List; + public interface User { public String getName(); @@ -7,5 +9,7 @@ public String getPassword(); public boolean hasExpired(); + + public List<String> getRoles(); } // vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- 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 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Response.java Fri Jul 13 08:54:57 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Response.java Fri Jul 13 09:27:53 2012 +0000 @@ -2,6 +2,8 @@ import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.codec.binary.Base64InputStream; @@ -102,7 +104,7 @@ if (assertion == null) { throw new AuthenticationException("Response doesn't contain an assertion"); } - return new User(this.username, this.password, assertion); + return new User(this.username, this.password, this.assertion.getRoles(), assertion); } } // vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/User.java Fri Jul 13 08:54:57 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/User.java Fri Jul 13 09:27:53 2012 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.client.server.auth.was; import java.util.Date; +import java.util.List; import de.intevation.flys.client.server.auth.DefaultUser; @@ -10,9 +11,10 @@ private Assertion assertion; - public User(String name, String password, Assertion assertion) { - this.name = name; - this.password = password; + public User(String name, String password, List<String> roles, Assertion assertion) { + this.setName(name); + this.setPassword(password); + this.setRoles(roles); this.assertion = assertion; }