Merge patch branch changes to main.

This commit is contained in:
Virtually Nick committed 2025-09-03 19:46:31 -04:00
commit ed54b5b12a
10 files changed
+28 -17

No files matched your search

@@ -59,7 +59,8 @@ public class ActiveConnectionObjectTranslator
@Override @Override
public void filterExternalObject(UserContext context, public void filterExternalObject(UserContext context,
APIActiveConnection object) throws GuacamoleException { ActiveConnection existingObject, APIActiveConnection object)
throws GuacamoleException {
// Nothing to filter on ActiveConnections (no attributes) // Nothing to filter on ActiveConnections (no attributes)
} }
@@ -62,7 +62,8 @@ public class ConnectionObjectTranslator
@Override @Override
public void filterExternalObject(UserContext userContext, public void filterExternalObject(UserContext userContext,
APIConnection object) throws GuacamoleException { Connection existingObject, APIConnection object)
throws GuacamoleException {
// Filter object attributes by defined schema // Filter object attributes by defined schema
object.setAttributes(filterAttributes( object.setAttributes(filterAttributes(
@@ -56,7 +56,8 @@ public class ConnectionGroupObjectTranslator
@Override @Override
public void filterExternalObject(UserContext userContext, public void filterExternalObject(UserContext userContext,
APIConnectionGroup object) throws GuacamoleException { ConnectionGroup existingObject, APIConnectionGroup object)
throws GuacamoleException {
// Filter object attributes by defined schema // Filter object attributes by defined schema
object.setAttributes(filterAttributes( object.setAttributes(filterAttributes(
@@ -311,7 +311,7 @@ public abstract class DirectoryObjectResource<InternalType extends Identifiable,
throw new GuacamoleClientException("Data must be submitted when updating objects."); throw new GuacamoleClientException("Data must be submitted when updating objects.");
// Filter/sanitize object contents // Filter/sanitize object contents
translator.filterExternalObject(userContext, modifiedObject); translator.filterExternalObject(userContext, object, modifiedObject);
// Perform update // Perform update
translator.applyExternalChanges(object, modifiedObject); translator.applyExternalChanges(object, modifiedObject);
@@ -106,6 +106,10 @@ public abstract class DirectoryObjectTranslator<InternalType extends Identifiabl
* @param userContext * @param userContext
* The UserContext associated with the object being filtered. * The UserContext associated with the object being filtered.
* *
* @param existingObject
* The existing object from the Guacamole extension API which is being
* modified, or null if the object is being created.
*
* @param object * @param object
* The object to modify such that it strictly conforms to the declared * The object to modify such that it strictly conforms to the declared
* schema. * schema.
@@ -114,7 +118,8 @@ public abstract class DirectoryObjectTranslator<InternalType extends Identifiabl
* If the object cannot be filtered due to an error. * If the object cannot be filtered due to an error.
*/ */
public abstract void filterExternalObject(UserContext userContext, public abstract void filterExternalObject(UserContext userContext,
ExternalType object) throws GuacamoleException; InternalType existingObject, ExternalType object)
throws GuacamoleException;
/** /**
* Filters the given map of attribute name/value pairs, producing a new * Filters the given map of attribute name/value pairs, producing a new
@@ -355,8 +355,9 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
} }
/** /**
* Filter and sanitize the provided external object, translate to the * Filter and sanitize the provided external object that is being created
* internal type, and return the translated internal object. * (does not already exist), translate to the internal type, and return the
* translated internal object.
* *
* @param object * @param object
* The external object to filter and translate. * The external object to filter and translate.
@@ -368,11 +369,11 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
* If an error occurs while filtering or translating the external * If an error occurs while filtering or translating the external
* object. * object.
*/ */
private InternalType filterAndTranslate(ExternalType object) private InternalType filterAndTranslateNewObject(ExternalType object)
throws GuacamoleException { throws GuacamoleException {
// Filter and sanitize the external object // Filter and sanitize the external object
translator.filterExternalObject(userContext, object); translator.filterExternalObject(userContext, null, object);
// Translate to the internal type // Translate to the internal type
return translator.toInternalObject(object); return translator.toInternalObject(object);
@@ -599,7 +600,7 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
if (op == APIPatch.Operation.add) { if (op == APIPatch.Operation.add) {
// Filter/sanitize object contents // Filter/sanitize object contents
InternalType internal = filterAndTranslate(patch.getValue()); InternalType internal = filterAndTranslateNewObject(patch.getValue());
try { try {
@@ -823,7 +824,7 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
throw new GuacamoleClientException("Data must be submitted when creating objects."); throw new GuacamoleClientException("Data must be submitted when creating objects.");
// Filter/sanitize object contents // Filter/sanitize object contents
InternalType internal = filterAndTranslate(object); InternalType internal = filterAndTranslateNewObject(object);
// Create the new object within the directory // Create the new object within the directory
try { try {
@@ -56,7 +56,8 @@ public class SharingProfileObjectTranslator
@Override @Override
public void filterExternalObject(UserContext userContext, public void filterExternalObject(UserContext userContext,
APISharingProfile object) throws GuacamoleException { SharingProfile existingObject, APISharingProfile object)
throws GuacamoleException {
// Filter object attributes by defined schema // Filter object attributes by defined schema
object.setAttributes(filterAttributes( object.setAttributes(filterAttributes(
@@ -59,11 +59,11 @@ public class UserObjectTranslator
} }
@Override @Override
public void filterExternalObject(UserContext userContext, APIUser object) public void filterExternalObject(UserContext userContext,
throws GuacamoleException { User existingObject, APIUser object) throws GuacamoleException {
// If a user is editing themselves ... // If a user is editing themselves ...
if (object.getUsername().equals(userContext.self().getIdentifier())) { if (existingObject != null && existingObject.getIdentifier().equals(userContext.self().getIdentifier())) {
// ... they may only edit preference attributes // ... they may only edit preference attributes
object.setAttributes(filterAttributes(userContext.getUserPreferenceAttributes(), object.setAttributes(filterAttributes(userContext.getUserPreferenceAttributes(),
@@ -138,7 +138,7 @@ public class UserResource
try { try {
User currentUser = getUserContext().self(); User currentUser = getUserContext().self();
if ( if (
currentUser.getIdentifier().equals(modifiedObject.getUsername()) currentUser.getIdentifier().equals(getInternalObject().getIdentifier())
&& modifiedObject.getPassword() != null) { && modifiedObject.getPassword() != null) {
throw new GuacamoleSecurityException( throw new GuacamoleSecurityException(
"Permission denied. The password update endpoint must" "Permission denied. The password update endpoint must"
@@ -56,7 +56,8 @@ public class UserGroupObjectTranslator
} }
@Override @Override
public void filterExternalObject(UserContext userContext, APIUserGroup object) public void filterExternalObject(UserContext userContext,
UserGroup existingObject, APIUserGroup object)
throws GuacamoleException { throws GuacamoleException {
// Filter object attributes by defined schema // Filter object attributes by defined schema