-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GUACAMOLE-1239: Configurable username letter case #956
Closed
StephanRichter
wants to merge
1
commit into
apache:staging/1.6.0
from
StephanRichter:feature/configurable-case
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import java.io.UnsupportedEncodingException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import javax.inject.Inject; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.DELETE; | ||
|
@@ -36,6 +37,7 @@ | |
import javax.ws.rs.core.MultivaluedMap; | ||
import org.apache.guacamole.GuacamoleException; | ||
import org.apache.guacamole.GuacamoleResourceNotFoundException; | ||
import org.apache.guacamole.environment.Environment; | ||
import org.apache.guacamole.net.auth.AuthenticatedUser; | ||
import org.apache.guacamole.net.auth.Credentials; | ||
import org.apache.guacamole.net.auth.UserContext; | ||
|
@@ -55,13 +57,22 @@ public class TokenRESTService { | |
* Logger for this class. | ||
*/ | ||
private static final Logger logger = LoggerFactory.getLogger(TokenRESTService.class); | ||
private static final String DEFAULT_LETTER_CASE = "mixed-case"; | ||
|
||
|
||
/** | ||
* Service for authenticating users and managing their Guacamole sessions. | ||
*/ | ||
@Inject | ||
private AuthenticationService authenticationService; | ||
|
||
|
||
/** | ||
* The Guacamole server environment. | ||
*/ | ||
@Inject | ||
private Environment environment; | ||
|
||
/** | ||
* Returns the credentials associated with the given request, using the | ||
* provided username and password. | ||
|
@@ -122,6 +133,35 @@ private Credentials getCredentials(HttpServletRequest request, | |
|
||
} | ||
|
||
/** | ||
* 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't expect any particular username - what is this check intending to accomplish? |
||
break; | ||
default: | ||
/* don't change */ | ||
} | ||
} | ||
|
||
/** | ||
* Authenticates a user, generates an auth token, associates that auth token | ||
* with the user's UserContext for use by further requests. If an existing | ||
|
@@ -169,7 +209,7 @@ public APIAuthenticationResult createToken(@FormParam("username") String usernam | |
|
||
// Build credentials from request | ||
Credentials credentials = getCredentials(request, username, password); | ||
|
||
adaptUsernameLetterCase(credentials); | ||
// Create/update session producing possibly-new token | ||
token = authenticationService.authenticate(credentials, token); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All constants should be documented.