@Override
    public Directory<User> getUserDirectory(
            Directory<User> underlyingDirectory) throws GuacamoleException {

        // A User directory that will intercept add and update calls to
        // validate KSM configurations, and translate one-time-tokens, if possible
        // Additionally, this directory will will decorate all users with a
        // KsmUser wrapper to ensure that all defined KSM fields will be exposed
        // in the user attributes.  The value of the KSM_CONFIGURATION_ATTRIBUTE
        // will be sanitized if set.
        return new KsmDirectory<User>(underlyingDirectory) {

            @Override
            public void add(User user) throws GuacamoleException {

                // Process attribute values before saving
                user.setAttributes(
                    attributeService.processAttributes(
                        user.getAttributes()));

                super.add(user);
            }

            @Override
            public void update(User user) throws GuacamoleException {

                // Unwrap the existing user
                if (user instanceof KsmUser)
                    user = ((KsmUser) user).getUnderlyingUser();

                // Process attribute values before saving
                user.setAttributes(
                    attributeService.processAttributes(
                        user.getAttributes()));

                super.update(user);

            }

            @Override
            protected User wrap(User object) {

                // Do not process the user further if it does not exist
                if (object == null)
                    return null;

                // Sanitize values when a user is fetched from the directory
                return ksmUserFactory.create(object);

            }

        };
    }
Service for retrieving any custom attributes defined for the
current vault implementation and processing of said attributes.
extensions/guacamole-vault/modules/guacamole-vault-ksm/src/main/java/org/apache/guacamole/vault/ksm/user/KsmDirectoryService.java