package com.c2kernel.process.auth; import java.util.Properties; import java.util.Scanner; import com.c2kernel.entity.proxy.AgentProxy; import com.c2kernel.process.Gateway; public class ConsoleAuth implements Authenticator { public ConsoleAuth() { } @Override public void initialize(Properties props) throws Exception { } @Override public AgentProxy authenticate(String resource) throws Exception { AgentProxy user = null; if (resource!=null) System.out.println("Please log in"+(resource.length()>0?"to "+resource:"")); @SuppressWarnings("resource") // closing the scanner closes system.in Scanner scan = new Scanner(System.in); int loginAttempts = 0; while (user == null && loginAttempts++ < 3) { System.out.print("User:"); String username = scan.nextLine(); System.out.print("Password:"); String pass = scan.nextLine(); try { user = Gateway.connect(username, pass); } catch (Exception ex) { System.err.println(ex.getMessage()); } } if (user == null) { System.err.println("Bye"); System.exit(0); } return user; } }