summaryrefslogtreecommitdiffstats
path: root/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java')
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java
new file mode 100644
index 0000000..7f0856c
--- /dev/null
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java
@@ -0,0 +1,109 @@
+package de.bwlehrpool.bwlp_guac;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AbstractUserContext;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.Directory;
+import org.apache.guacamole.net.auth.User;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
+import org.apache.guacamole.net.auth.simple.SimpleConnection;
+import org.apache.guacamole.net.auth.simple.SimpleDirectory;
+import org.apache.guacamole.net.auth.simple.SimpleObjectPermissionSet;
+import org.apache.guacamole.net.auth.simple.SimpleUser;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BwlpUserContext extends AbstractUserContext {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(BwlpUserContext.class);
+
+ private static final SimpleConnection FAKE = new SimpleConnection("FAKE", "FAKE", new GuacamoleConfiguration());
+
+ static {
+ FAKE.setParentIdentifier(DEFAULT_ROOT_CONNECTION_GROUP);
+ }
+
+ private final AuthenticatedUser authUser;
+ private final UserContext originalContext;
+
+ /**
+ * The Directory with access to all connections within the root group associated
+ * with this UserContext.
+ */
+ private Directory<Connection> connectionDirectory;
+
+ public BwlpUserContext(AuthenticatedUser authenticatedUser, UserContext context) {
+ authUser = authenticatedUser;
+ originalContext = context;
+ // OK
+ addConn();
+ }
+
+ private void addConn() {
+ WrappedConnection connection = ConnectionManager.getForUser(authUser.getCredentials().getUsername());
+ if (connection != null) {
+ connectionDirectory = new SimpleDirectory<Connection>(connection);
+ } else {
+ connectionDirectory = new SimpleDirectory<Connection>();
+ }
+ }
+
+ public User self() {
+ return new SimpleUser(authUser.getCredentials().getUsername()) {
+
+ @Override
+ public ObjectPermissionSet getConnectionGroupPermissions() throws GuacamoleException {
+ return new SimpleObjectPermissionSet(getConnectionDirectory().getIdentifiers());
+ }
+
+ @Override
+ public ObjectPermissionSet getConnectionPermissions() throws GuacamoleException {
+ return new SimpleObjectPermissionSet(getConnectionGroupDirectory().getIdentifiers());
+ }
+
+ };
+ }
+
+ @Override
+ public Object getResource() throws GuacamoleException {
+ return null;
+ }
+
+ public AuthenticationProvider getAuthenticationProvider() {
+ return originalContext.getAuthenticationProvider();
+ }
+
+ @Override
+ public Directory<Connection> getConnectionDirectory() throws GuacamoleException {
+ return connectionDirectory;
+ }
+
+ public boolean hasValidConnection() {
+ boolean ok = false;
+ try {
+ synchronized (this) {
+ for (String id : connectionDirectory.getIdentifiers()) {
+ Connection con = connectionDirectory.get(id);
+ if (con instanceof WrappedConnection) {
+ if (((WrappedConnection) con).checkConnection(3)) {
+ ok = true;
+ }
+ } else {
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.warn("hasValidConnection", e);
+ }
+ return ok;
+ }
+
+ public UserContext getOriginalContext() {
+ return originalContext;
+ }
+
+}