blob: a6af253c2c77b2b4573bb1515e86974984c38926 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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:""));
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;
}
}
|