Java: Added a session handler with authentication capability.
[doldaconnect.git] / lib / java / dolda / dolcon / InteractiveAuth.java
CommitLineData
7131093c
FT
1package dolda.dolcon;
2
3import java.util.List;
4import dolda.dolcon.protocol.Response;
5import dolda.dolcon.protocol.Command;
6
7public abstract class InteractiveAuth implements Authenticator {
8 public String handles(List<String> name) {
9 if(name.contains("pam"))
10 return("pam");
11 return(null);
12 }
13
14 public Command step(Response resp) throws AuthException, ProtocolException, InterruptedException {
15 if(resp.code == 301) {
16 return(new Command("pass", promptnoecho(resp.token(0, 0))));
17 } else if(resp.code == 302) {
18 return(new Command("pass", promptecho(resp.token(0, 0))));
19 } else if(resp.code == 303) {
20 info(resp.token(0, 0));
21 return(new Command("pass", ""));
22 } else if(resp.code == 304) {
23 error(resp.token(0, 0));
24 return(new Command("pass", ""));
25 } else {
26 throw(new ResponseException(resp, 0));
27 }
28 }
29
30 public abstract String promptecho(String msg) throws AuthException;
31 public abstract String promptnoecho(String msg) throws AuthException;
32 public abstract void info(String msg) throws AuthException;
33 public abstract void error(String msg) throws AuthException;
34}