4 import dolda.dolcon.protocol.*;
7 private Connection conn;
9 public Session(String aspec, String username, List<Authenticator> auth) throws AuthException, ProtocolException, InterruptedException {
10 conn = new Connection(aspec);
11 conn.expectVersion(2);
14 } catch(ConnectException e) {
15 throw(new ProtocolException(e));
17 authenticate(username, auth);
20 public Session(String aspec, String username, Authenticator... auth) throws AuthException, ProtocolException, InterruptedException {
21 this(aspec, username, Arrays.asList(auth));
24 private void authenticate(String username, List<Authenticator> auth) throws AuthException, ProtocolException, InterruptedException {
28 resp = ResponseException.check(conn.ecmd("lsauth"), 200);
29 List<String> mechs = new LinkedList<String>();
30 for(List<String> mech : resp.lines)
31 mechs.add(mech.get(0).intern());
33 Authenticator au = null;
34 for(Authenticator a : auth) {
35 System.out.println(a);
36 use = a.handles(mechs);
43 throw(new NoMechException());
44 resp = conn.ecmd("login", use, username);
46 if(resp.code == 200) {
48 } else if((resp.code / 100) == 3) {
49 resp = conn.ecmd(au.step(resp));
50 } else if((resp.code / 100) == 5) {
51 throw(new AuthException(resp.token(0, 0)));
53 throw(new ResponseException(resp, 0));
56 } catch(ClosedException e) {
57 throw(new ProtocolException(e));