public SharedConnectionDefinition shareConnection(ModeledAuthenticatedUser user,
            ActiveConnectionRecord activeConnection,
            String sharingProfileIdentifier) throws GuacamoleException {

        // If a sharing profile is provided, verify that permission to use that
        // profile to share the given connection is actually granted
        ModeledSharingProfile sharingProfile = null;
        if (sharingProfileIdentifier != null) {

            // Pull sharing profile (verifying access)
            sharingProfile = sharingProfileService.retrieveObject(user, sharingProfileIdentifier);

            // Verify that this profile is indeed a sharing profile for the
            // requested connection
            String connectionIdentifier = activeConnection.getConnectionIdentifier();
            if (sharingProfile == null || !sharingProfile.getPrimaryConnectionIdentifier().equals(connectionIdentifier))
                throw new GuacamoleSecurityException("Permission denied.");

        }

        // Generate a share key for the requested connection
        String key = keyGenerator.getShareKey();
        SharedConnectionDefinition definition = new SharedConnectionDefinition(activeConnection, sharingProfile, key);
        connectionMap.add(definition);

        // Ensure the share key is properly invalidated when the original
        // connection is closed
        activeConnection.registerShareKey(key);

        return definition;

    }
Creates a new SharedConnectionDefinition which can be used to connect to
the given connection, optionally restricting access to the shared
connection using the given sharing profile. If the user does not have
permission to share the connection via the given sharing profile,
permission will be denied.

@see GuacamoleTunnelService#getGuacamoleTunnel(RemoteAuthenticatedUser,
         SharedConnectionDefinition, GuacamoleClientInformation, Map)

@see #getSharingCredentials(SharedConnectionDefinition)

@param user
    The user sharing the connection.

@param activeConnection
    The active connection being shared.

@param sharingProfileIdentifier
    The identifier of the sharing profile dictating the semantics or
    restrictions applying to the shared session, or null if no such
    restrictions should apply.

@return
    A new SharedConnectionDefinition which can be used to connect to the
    given connection.

@throws GuacamoleException
    If permission to share the given connection is denied.
extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/ConnectionSharingService.java