@Override
    public Directory<ConnectionGroup> getConnectionGroupDirectory(
            Directory<ConnectionGroup> underlyingDirectory) throws GuacamoleException {

        // A ConnectionGroup directory that will intercept add and update calls to
        // validate KSM configurations, and translate one-time-tokens, if possible,
        // as well as ensuring that all ConnectionGroups returned include the
        // KSM_CONFIGURATION_ATTRIBUTE attribute, so it will be available in the UI.
        // The value of the KSM_CONFIGURATION_ATTRIBUTE will be sanitized if set.
        return new KsmDirectory<ConnectionGroup>(underlyingDirectory) {

            @Override
            public void add(ConnectionGroup connectionGroup) throws GuacamoleException {

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

                super.add(connectionGroup);
            }

            @Override
            public void update(ConnectionGroup connectionGroup) throws GuacamoleException {

                // Unwrap the existing ConnectionGroup
                if (connectionGroup instanceof KsmConnectionGroup)
                    connectionGroup = ((KsmConnectionGroup) connectionGroup).getUnderlyingConnectionGroup();

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

                super.update(connectionGroup);

            }

            @Override
            protected ConnectionGroup wrap(ConnectionGroup object) {

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

                // Sanitize values when a ConnectionGroup is fetched from the directory
                return new KsmConnectionGroup(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