From a3079c033e7923a4076a1cc148c74b5bb86c79a1 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 17 Jun 2013 22:46:37 +0200 Subject: Authentication plugin for Console --- .../java/com/c2kernel/process/ClientShell.java | 30 ++++++---------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/main/java/com/c2kernel/process/ClientShell.java') diff --git a/src/main/java/com/c2kernel/process/ClientShell.java b/src/main/java/com/c2kernel/process/ClientShell.java index c20c1d4..f0c3a0d 100644 --- a/src/main/java/com/c2kernel/process/ClientShell.java +++ b/src/main/java/com/c2kernel/process/ClientShell.java @@ -3,6 +3,7 @@ package com.c2kernel.process; import java.util.Scanner; import com.c2kernel.entity.proxy.AgentProxy; +import com.c2kernel.process.auth.Authenticator; import com.c2kernel.scripting.Script; public class ClientShell extends StandardClient { @@ -10,8 +11,8 @@ public class ClientShell extends StandardClient { AgentProxy user; Script console; - public ClientShell(String username, String pass) throws Exception { - user = Gateway.connect(username, pass); + public ClientShell(AgentProxy user) throws Exception { + this.user = user; console = new Script("javascript", user, System.out); } @@ -38,27 +39,12 @@ public class ClientShell extends StandardClient { public static void main(String[] args) throws Exception { Gateway.init(readC2KArgs(args)); - @SuppressWarnings("resource") // closing the scanner closes system.in - Scanner scan = new Scanner(System.in); - int loginAttempts = 0; - ClientShell shell = null; - while (shell == null && loginAttempts++ < 3) { - System.out.print("User:"); - String username = scan.nextLine(); - System.out.print("Password:"); - String pass = scan.nextLine(); - try { - shell = new ClientShell(username, pass); - } catch (Exception ex) { - System.err.println(ex.getMessage()); - } - } - if (shell == null) { - System.err.println("Bye"); - System.exit(0); - } + String authClassName = Gateway.getProperty("cli.auth"); + Class authClass = Class.forName(authClassName); + Authenticator auth = (Authenticator)authClass.newInstance(); + AgentProxy user = auth.authenticate(Gateway.getProperty("Name")); + ClientShell shell = new ClientShell(user); shell.run(); - } } -- cgit v1.2.3