mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-540: Clean up Credentials with new constructor.
This commit is contained in:
@@ -95,6 +95,45 @@ public class Credentials implements Serializable {
|
||||
*/
|
||||
private transient HttpSession session;
|
||||
|
||||
/**
|
||||
* Construct a Credentials object with the given username, password,
|
||||
* and HTTP request. The information is assigned to the various
|
||||
* storage objects, and the remote hostname and address is parsed out
|
||||
* of the request object.
|
||||
*
|
||||
* @param username
|
||||
* The username that was provided for authentication.
|
||||
*
|
||||
* @param password
|
||||
* The password that was provided for authentication.
|
||||
*
|
||||
* @param request
|
||||
* The HTTP request associated with the authentication
|
||||
* request.
|
||||
*/
|
||||
public Credentials(String username, String password, HttpServletRequest request) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.request = request;
|
||||
|
||||
// Use X-Forwarded-For to get remote address, if present and valid
|
||||
String header = request.getHeader("X-Forwarded-For");
|
||||
if (header != null) {
|
||||
Matcher matcher = X_FORWARDED_FOR.matcher(header);
|
||||
if (matcher.matches())
|
||||
this.remoteAddress = matcher.group(1);
|
||||
}
|
||||
// Header not present, just use remote address
|
||||
else {
|
||||
this.remoteAddress = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
this.remoteHostname = request.getRemoteHost();
|
||||
|
||||
this.session = request.getSession(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password associated with this set of credentials.
|
||||
* @return The password associated with this username/password pair, or
|
||||
@@ -150,21 +189,6 @@ public class Credentials implements Serializable {
|
||||
*/
|
||||
public void setRequest(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
|
||||
// Use X-Forwarded-For to get remote address, if present and valid
|
||||
String header = request.getHeader("X-Forwarded-For");
|
||||
if (header != null) {
|
||||
Matcher matcher = X_FORWARDED_FOR.matcher(header);
|
||||
if (matcher.matches())
|
||||
this.remoteAddress = matcher.group(1);
|
||||
}
|
||||
// Header not present, just use remote address
|
||||
else {
|
||||
this.remoteAddress = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
this.remoteHostname = request.getRemoteHost();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -117,13 +117,7 @@ public class TokenRESTService {
|
||||
} // end Authorization header fallback
|
||||
|
||||
// Build credentials
|
||||
Credentials credentials = new Credentials();
|
||||
credentials.setUsername(username);
|
||||
credentials.setPassword(password);
|
||||
credentials.setRequest(request);
|
||||
credentials.setSession(request.getSession(false));
|
||||
|
||||
return credentials;
|
||||
return new Credentials(username, password, request);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -155,11 +155,8 @@ public class UserResource
|
||||
@Context HttpServletRequest request) throws GuacamoleException {
|
||||
|
||||
// Build credentials
|
||||
Credentials credentials = new Credentials();
|
||||
credentials.setUsername(user.getIdentifier());
|
||||
credentials.setPassword(userPasswordUpdate.getOldPassword());
|
||||
credentials.setRequest(request);
|
||||
credentials.setSession(request.getSession(false));
|
||||
Credentials credentials = new Credentials(user.getIdentifier(),
|
||||
userPasswordUpdate.getOldPassword(), request);
|
||||
|
||||
// Verify that the old password was correct
|
||||
try {
|
||||
|
Reference in New Issue
Block a user