Server.java:
package gendwang.cisco.com;
public interface Server
{
public void handleRequest(String request);
}
AAAServer.java:
package gendwang.cisco.com;
public class AAAServer implements Server
{
public void handleRequest(String request)
{
if(request.indexOf("user:gendwang password:123456") != -1)
{
System.out.println("This is an authorized user");
}
else
{
System.out.println("This is not an authorized user");
}
}
}
Proxy.java:
package gendwang.cisco.com;
public class Proxy implements Server
{
private Server server = null;
public void handleRequest(String request)
{
System.out.println("Authenticating is started.");
if(server == null)
{
server = new AAAServer();
}
server.handleRequest(request);
System.out.println("Authenticating is finished");
}
}
Test.java:
package gendwang.cisco.com;
public class Test
{
public static void main(String[] args)
{
Server proxy = new Proxy();
proxy.handleRequest("user:gendwang password:111111");
System.out.println();
proxy.handleRequest("user:gendwang password:123456");
}
}