Proxy
Example - Secured commands
interface CommandExecutor {
void execute(String s);
}
class CommandExecutorImpl implements CommandExecutor {
@Override
public void execute(String s) {
System.out.println("> " + s);
}
}
class CommandExecutorProxy implements CommandExecutor {
private CommandExecutor executor = new CommandExecutorImpl();
private boolean isAdmin;
public CommandExecutorProxy(String username, String password) {
// TODO: find out if user is admin
isAdmin = true;
}
@Override
public void execute(String command) {
if (isAdmin) {
executor.execute(command);
} else {
throw new RuntimeException("Not authorized!");
}
}
}Example - Proxy in JavaScript
Last updated