comparison flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Response.java @ 2968:3e0567e02577

Extend Authentication and Response to throw additional exceptions flys-client/trunk@4964 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 13 Jul 2012 06:46:27 +0000
parents 5ba0a6efdf3b
children 98514ab2c9ba
comparison
equal deleted inserted replaced
2967:ce07c6a1e96b 2968:3e0567e02577
13 import org.jdom.Element; 13 import org.jdom.Element;
14 import org.jdom.JDOMException; 14 import org.jdom.JDOMException;
15 import org.jdom.input.SAXBuilder; 15 import org.jdom.input.SAXBuilder;
16 16
17 import de.intevation.flys.client.server.auth.Authentication; 17 import de.intevation.flys.client.server.auth.Authentication;
18 import de.intevation.flys.client.server.auth.AuthenticationException;
18 19
19 public class Response implements Authentication { 20 public class Response implements Authentication {
20 21
21 private static Logger logger = Logger.getLogger(Response.class); 22 private static Logger logger = Logger.getLogger(Response.class);
22 23
24 private Assertion assertion; 25 private Assertion assertion;
25 private String username; 26 private String username;
26 private String password; 27 private String password;
27 28
28 29
29 public Response(HttpEntity entity, String username, String password) throws ServiceException { 30 public Response(HttpEntity entity, String username, String password) throws AuthenticationException, IOException {
30 31
31 if (entity == null) { 32 if (entity == null) {
32 throw new ServiceException("Invalid response"); 33 throw new ServiceException("Invalid response");
33 } 34 }
34 35
55 this.username = username; 56 this.username = username;
56 this.password = password; 57 this.password = password;
57 58
58 } 59 }
59 catch(JDOMException e) { 60 catch(JDOMException e) {
60 logger.error(e); 61 throw new AuthenticationException(e);
61 }
62 catch(IOException e) {
63 logger.error(e);
64 } 62 }
65 } 63 }
66 64
67 public Element getRoot() { 65 public Element getRoot() {
68 return this.root; 66 return this.root;
97 } 95 }
98 return this.assertion; 96 return this.assertion;
99 } 97 }
100 98
101 @Override 99 @Override
102 public User getUser() { 100 public User getUser() throws AuthenticationException {
103 return new User(this.username, this.password); 101 Assertion assertion = this.getAssertion();
102 if (assertion == null) {
103 throw new AuthenticationException("Response doesn't contain an assertion");
104 }
105 return new User(this.username, this.password, assertion);
104 } 106 }
105 } 107 }
106 // vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80: 108 // vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:

http://dive4elements.wald.intevation.org