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:
@@ -42,7 +42,7 @@ public abstract class RemoteAuthenticatedUser implements AuthenticatedUser {
|
|||||||
* The host from which this user authenticated.
|
* The host from which this user authenticated.
|
||||||
*/
|
*/
|
||||||
private final String remoteHost;
|
private final String remoteHost;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new RemoteAuthenticatedUser, deriving the associated remote
|
* Creates a new RemoteAuthenticatedUser, deriving the associated remote
|
||||||
* host from the given credentials.
|
* host from the given credentials.
|
||||||
|
@@ -95,6 +95,45 @@ public class Credentials implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private transient HttpSession session;
|
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.
|
* Returns the password associated with this set of credentials.
|
||||||
* @return The password associated with this username/password pair, or
|
* @return The password associated with this username/password pair, or
|
||||||
@@ -150,21 +189,6 @@ public class Credentials implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public void setRequest(HttpServletRequest request) {
|
public void setRequest(HttpServletRequest request) {
|
||||||
this.request = 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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -55,7 +55,7 @@ public class TokenRESTService {
|
|||||||
* Logger for this class.
|
* Logger for this class.
|
||||||
*/
|
*/
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TokenRESTService.class);
|
private static final Logger logger = LoggerFactory.getLogger(TokenRESTService.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for authenticating users and managing their Guacamole sessions.
|
* Service for authenticating users and managing their Guacamole sessions.
|
||||||
*/
|
*/
|
||||||
@@ -117,13 +117,7 @@ public class TokenRESTService {
|
|||||||
} // end Authorization header fallback
|
} // end Authorization header fallback
|
||||||
|
|
||||||
// Build credentials
|
// Build credentials
|
||||||
Credentials credentials = new Credentials();
|
return new Credentials(username, password, request);
|
||||||
credentials.setUsername(username);
|
|
||||||
credentials.setPassword(password);
|
|
||||||
credentials.setRequest(request);
|
|
||||||
credentials.setSession(request.getSession(false));
|
|
||||||
|
|
||||||
return credentials;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -155,11 +155,8 @@ public class UserResource
|
|||||||
@Context HttpServletRequest request) throws GuacamoleException {
|
@Context HttpServletRequest request) throws GuacamoleException {
|
||||||
|
|
||||||
// Build credentials
|
// Build credentials
|
||||||
Credentials credentials = new Credentials();
|
Credentials credentials = new Credentials(user.getIdentifier(),
|
||||||
credentials.setUsername(user.getIdentifier());
|
userPasswordUpdate.getOldPassword(), request);
|
||||||
credentials.setPassword(userPasswordUpdate.getOldPassword());
|
|
||||||
credentials.setRequest(request);
|
|
||||||
credentials.setSession(request.getSession(false));
|
|
||||||
|
|
||||||
// Verify that the old password was correct
|
// Verify that the old password was correct
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user