Skip to content

Commit

Permalink
work towards fixing [1239]
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Richter committed Mar 11, 2024
1 parent 2a76050 commit dfb95fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public interface Environment {

};


public static final StringGuacamoleProperty USERNAME_LETTER_CASE = new StringGuacamoleProperty() {

@Override
public String getName() { return "username-letter-case"; }

};

/**
* Returns the Guacamole home directory as determined when this Environment
* object was created. The Guacamole home directory is found by checking, in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class AuthenticationService {
* Logger for this class.
*/
private static final Logger logger = LoggerFactory.getLogger(AuthenticationService.class);
private static final String DEFAULT_LETTER_CASE = "mixed-case";

/**
* The Guacamole server environment.
Expand Down Expand Up @@ -462,6 +464,8 @@ public String authenticate(Credentials credentials, String token)
else
existingSession = null;

adaptUsernameLetterCase(credentials);

// Get up-to-date AuthenticatedUser and associated UserContexts
AuthenticatedUser authenticatedUser = getAuthenticatedUser(existingSession, credentials);
List<DecoratedUserContext> userContexts = getUserContexts(existingSession, authenticatedUser, credentials);
Expand All @@ -485,6 +489,35 @@ public String authenticate(Credentials credentials, String token)

}

/**
* Alters letter casing of username, if configured.
* Configuration options:
* <ul>
* <li>mixed-case (default)</li>
* <li>lower-case</li>
* <li>upper-case</li>
* </ul>
* @param credentials
* The Credentials provided by the user in the most recent
* authentication attempt.
* @throws GuacamoleException If an error occurs while parsing the value
* for the given property in
* guacamole.properties, or if the property is
* not specified.
*/
private void adaptUsernameLetterCase(Credentials credentials) throws GuacamoleException {
switch (environment.getProperty(Environment.USERNAME_LETTER_CASE,DEFAULT_LETTER_CASE)){
case "lower-case":
Optional.ofNullable(credentials.getUsername()).map(String::toLowerCase).ifPresent(credentials::setUsername);
break;
case "upper-case":
Optional.ofNullable(credentials.getUsername()).filter(un -> !"guacadmin".equals(un)).map(String::toUpperCase).ifPresent(credentials::setUsername);
break;
default:
/* don't change */
}
}

/**
* Finds the Guacamole session for a given auth token, if the auth token
* represents a currently logged in user. Throws an unauthorized error
Expand Down

0 comments on commit dfb95fb

Please sign in to comment.