mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Per-client authorization
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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 {
|
||||
|
@@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user