diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-06-17 22:46:37 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-06-17 22:46:37 +0200 |
| commit | a3079c033e7923a4076a1cc148c74b5bb86c79a1 (patch) | |
| tree | 3057eae4ddd8b58c900d2be10b316e5b8e68927b /src/main/java/com/c2kernel/process/auth | |
| parent | 8d242edc79e015d5f54841a771b6222459e86994 (diff) | |
Authentication plugin for Console
Diffstat (limited to 'src/main/java/com/c2kernel/process/auth')
| -rw-r--r-- | src/main/java/com/c2kernel/process/auth/Authenticator.java | 12 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/process/auth/ConsoleAuth.java | 45 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/process/auth/Authenticator.java b/src/main/java/com/c2kernel/process/auth/Authenticator.java new file mode 100644 index 0000000..ae18474 --- /dev/null +++ b/src/main/java/com/c2kernel/process/auth/Authenticator.java @@ -0,0 +1,12 @@ +package com.c2kernel.process.auth;
+
+import java.util.Properties;
+
+import com.c2kernel.entity.proxy.AgentProxy;
+
+public interface Authenticator {
+
+ public void initialize(Properties props) throws Exception;
+ public AgentProxy authenticate(String resource) throws Exception;
+
+}
diff --git a/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java b/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java new file mode 100644 index 0000000..a3ea521 --- /dev/null +++ b/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java @@ -0,0 +1,45 @@ +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;
+
+ }
+
+}
|
