Per-client authorization

This commit is contained in:
Michael Jumper
2010-11-27 15:31:12 -08:00
parent 9066923298
commit 5339fdf350
4 changed files with 32 additions and 5 deletions

View File

@@ -32,15 +32,35 @@ public class GuacamoleSession {
private GuacamoleConfiguration config;
private final HttpSession session;
private Client client;
private SessionClient client;
private ReentrantLock instructionStreamLock;
private class SessionClient extends Client implements HttpSessionBindingListener {
public class SessionClient extends Client implements HttpSessionBindingListener {
private Client client;
private ReentrantLock authorizedLock;
public SessionClient(Client client) {
this.client = client;
authorizedLock = new ReentrantLock();
authorizedLock.lock();
}
public void authorize() {
authorizedLock.unlock();
}
public void waitForAuthorization() {
if (authorizedLock.isLocked()) {
try {
authorizedLock.lock();
authorizedLock.unlock();
}
catch (Throwable t) {
throw new Error("Internal error waiting for authorization", t);
}
}
}
public void valueBound(HttpSessionBindingEvent event) {
@@ -82,7 +102,7 @@ public class GuacamoleSession {
ServletContext context = session.getServletContext();
config = new GuacamoleConfiguration(context);
client = (Client) session.getAttribute("CLIENT");
client = (SessionClient) session.getAttribute("CLIENT");
instructionStreamLock = (ReentrantLock) session.getAttribute("INSTRUCTION_STREAM_LOCK");
}
}
@@ -119,7 +139,7 @@ public class GuacamoleSession {
return config;
}
public Client getClient() {
public SessionClient getClient() {
synchronized (session) {
return client;
}

View File

@@ -44,10 +44,13 @@ public class Connect extends GuacamoleServlet {
// Obtain new connection
session.connect();
String connectString = "connect:vnc,localhost,5901,potato;";
// Send data
try {
char[] connect = "connect:vnc,localhost,5901,potato;".toCharArray();
char[] connect = connectString.toCharArray();
session.getClient().write(connect, 0, connect.length);
session.getClient().authorize();
}
catch (GuacamoleException e) {
throw new GuacamoleException("Error sending data to server: " + e.getMessage(), e);

View File

@@ -32,6 +32,8 @@ public class Inbound extends GuacamoleServlet {
@Override
protected void handleRequest(GuacamoleSession session, HttpServletRequest request, HttpServletResponse response) throws GuacamoleException {
session.getClient().waitForAuthorization();
// Send data
try {

View File

@@ -35,6 +35,8 @@ public class Outbound extends GuacamoleServlet {
@Override
protected void handleRequest(GuacamoleSession session, HttpServletRequest request, HttpServletResponse response) throws GuacamoleException {
session.getClient().waitForAuthorization();
ReentrantLock instructionStreamLock = session.getInstructionStreamLock();
instructionStreamLock.lock();