summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-06-26 17:00:07 +0200
committerSimon Rettberg2020-06-26 17:00:07 +0200
commit8cf718c39bed2de9527c7171263bad5112f7ed16 (patch)
tree999a96099114e31aaa1260a8afd8412ea39efbe5
parentFix resolution detection JS (diff)
downloadbwlp-guacamole-ext-8cf718c39bed2de9527c7171263bad5112f7ed16.tar.gz
bwlp-guacamole-ext-8cf718c39bed2de9527c7171263bad5112f7ed16.tar.xz
bwlp-guacamole-ext-8cf718c39bed2de9527c7171263bad5112f7ed16.zip
Fallback to getIdentifier() if credential's username is null
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java14
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java12
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java20
3 files changed, 40 insertions, 6 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java b/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
index a79fa1c..aba868f 100644
--- a/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
@@ -204,7 +204,17 @@ public class AvailableClient implements Cloneable {
}
public void remoteLogin(Credentials credentials, String resolution) {
- String username = credentials.getUsername();
+ String username = null, password = null;
+ if (credentials != null) {
+ username = credentials.getUsername();
+ password = credentials.getPassword();
+ }
+ if (username == null) {
+ username = "";
+ }
+ if (password == null) {
+ password = "";
+ }
try {
LOGGER.info("Logging in user " + username + " on client " + this);
@@ -215,7 +225,7 @@ public class AvailableClient implements Cloneable {
int version = 1;
output.write(version >> 8);
output.write(version & 0xFF);
- String data = username + "\n" + credentials.getPassword() + "\n" + resolution;
+ String data = username + "\n" + password + "\n" + resolution;
byte[] enc = Base64.getEncoder().encode(data.getBytes(StandardCharsets.UTF_8));
output.write(enc);
output.flush();
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java
index a75d585..088be7f 100644
--- a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java
@@ -58,7 +58,17 @@ public class BwlpAuthenticationProvider implements AuthenticationProvider {
public UserContext redecorate(UserContext decorated, UserContext context, AuthenticatedUser authenticatedUser,
Credentials credentials) throws GuacamoleException {
- String username = authenticatedUser.getCredentials().getUsername();
+ Credentials creds = authenticatedUser.getCredentials();
+ if (creds == null)
+ return context;
+ String username = creds.getUsername();
+ if (username == null) {
+ username = authenticatedUser.getIdentifier();
+ }
+ if (username == null) {
+ LOGGER.warn("redecorate: Ignoring user without name");
+ return context;
+ }
LOGGER.warn("REdecorate called for " + username);
BwlpUserContext user = oldMappings.get(username);
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java
index 88208b9..93fda8d 100644
--- a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java
@@ -5,6 +5,7 @@ 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.Credentials;
import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.UserContext;
@@ -32,17 +33,24 @@ public class BwlpUserContext extends AbstractUserContext {
private final UserContext originalContext;
private final Integer groupid;
private final String resolution;
+ private final String username;
/**
* 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 groupid, String resolution)
throws GuacamoleCredentialsException {
authUser = authenticatedUser;
originalContext = context;
+ Credentials cred = authenticatedUser.getCredentials();
+ if (cred != null && cred.getUsername() != null) {
+ username = cred.getUsername();
+ } else {
+ username = authenticatedUser.getIdentifier();
+ }
this.groupid = groupid;
this.resolution = resolution;
// OK
@@ -52,13 +60,19 @@ public class BwlpUserContext extends AbstractUserContext {
public BwlpUserContext(AuthenticatedUser authenticatedUser, UserContext context, WrappedConnection exConn) {
authUser = authenticatedUser;
originalContext = context;
+ Credentials cred = authenticatedUser.getCredentials();
+ if (cred != null && cred.getUsername() != null) {
+ username = cred.getUsername();
+ } else {
+ username = authenticatedUser.getIdentifier();
+ }
this.groupid = -1;
this.resolution = "";
connectionDirectory = new SimpleDirectory<Connection>(exConn);
}
private void addConn() throws GuacamoleCredentialsException {
- WrappedConnection connection = ConnectionManager.getForUser(authUser.getCredentials().getUsername(), groupid);
+ WrappedConnection connection = ConnectionManager.getForUser(username, groupid);
if (connection != null) {
connection.remoteLogin(authUser.getCredentials(), this.resolution);
connection.setContext(this);
@@ -69,7 +83,7 @@ public class BwlpUserContext extends AbstractUserContext {
}
public User self() {
- return new SimpleUser(authUser.getCredentials().getUsername()) {
+ return new SimpleUser(username) {
@Override
public ObjectPermissionSet getConnectionGroupPermissions() throws GuacamoleException {