Java: Added a session handler with authentication capability.
[doldaconnect.git] / lib / java / dolda / dolcon / PasswordAuth.java
diff --git a/lib/java/dolda/dolcon/PasswordAuth.java b/lib/java/dolda/dolcon/PasswordAuth.java
new file mode 100644 (file)
index 0000000..9f62d7a
--- /dev/null
@@ -0,0 +1,32 @@
+package dolda.dolcon;
+
+import java.util.List;
+import dolda.dolcon.protocol.Response;
+import dolda.dolcon.protocol.Command;
+
+public class PasswordAuth implements Authenticator {
+    private String password;
+    
+    public PasswordAuth(String password) {
+       this.password = password;
+    }
+    
+    public String handles(List<String> name) {
+       System.out.println(name);
+       if(name.contains("pam"))
+           return("pam");
+       return(null);
+    }
+    
+    public Command step(Response resp) throws ProtocolException {
+       if((password != null) && (resp.code == 301)) {
+           try {
+               return(new Command("pass", password));
+           } finally {
+               password = null;
+           }
+       } else {
+           throw(new ResponseException(resp, 0));
+       }
+    }
+}