blob: 05fa78f61d0f3355e590445c99b1903c7b388ed0 (
plain) (
tree)
|
|
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.credentials.GuacamoleCredentialsException;
import org.apache.guacamole.net.auth.credentials.GuacamoleInsufficientCredentialsException;
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;
private final Integer locationid;
/**
* 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, int locationid)
throws GuacamoleCredentialsException {
authUser = authenticatedUser;
originalContext = context;
this.locationid = locationid;
// OK
addConn();
}
private void addConn() throws GuacamoleCredentialsException {
WrappedConnection connection = ConnectionManager.getForUser(authUser.getCredentials().getUsername(), locationid);
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) {
LOGGER.info("Checking connection for " + con.getIdentifier());
if (((WrappedConnection) con).checkConnection(3)) {
ok = true;
}
} else {
}
}
}
} catch (Exception e) {
LOGGER.warn("hasValidConnection", e);
}
return ok;
}
public UserContext getOriginalContext() {
return originalContext;
}
}
|