RealityServer Web Services API Programmer's Manual

User Access Control

[RealityServer Web Services API]

Description

RealityServer Web Services User Access Control system. The RealityServer Web Services User Access Control (UAC) system is (optionally) the first step applied when processing an HTTP request. UAC allows to set a maximum number of users that can access RealityServer Web Services at a time. Individual users are identified by a session ID which is managed via an HTTP cookie. When a request comes in that does not contain this cookie (or an unknown cookie) the UAC system checks to see if there is a free user slot, and if so, sets a cookie containing the session ID. If there are no free slots then the server returns a 503 'Service Unavailable' status code.

The UAC service fires events whenever a session is added or removed. These events can be monitored by installing an event handler on the RealityServer Web Services event context. Handlers could then perform any number of actions such as logging or informing admins when a server is full, controlling load balancers to raise or lower the priority of a given instance depending on usage or even fire up a new instance on another server when the user limit is reached.

Sample UAC Event Handler.

This sample simply sends a notification when the server reaches the maximum # of users or when the server is completely idle.

‎#include <mi/rswservices.h>

// method defined elsewhere to notify when server is full
void notify_full();

// method defined elsewhere to notify when server is empty
void notify_idle();

class Sample_uac_event_handler : public
    mi::base::Interface_implement<mi::nservices::IEvent_handler>
{
public:
    virtual const char *get_name() const { return "sample_uac_handler" };

    // handle the event
    virtual mi::Sint32 handle(
        mi::nservices::IEvent_handler_context *context,
        mi::nservices::IEvent *event)
    {
        // Get the arguments from the event
        mi::base::Handle<mi::IString> session(event->get_event_data<mi::IString>(0)); // session name
        mi::base::Handle<mi::INumber> curr_users(event->get_event_data<mi::INumber>(1)); // curr # of users
        mi::base::Handle<mi::INumber> max_users(event->get_event_data<mi::INumber>(2)); // max allowed users
        mi::Size curr = curr_users->get_value<mi::Size>();
        mi::Size max = max_users->get_value<mi::Size>();

        if (curr == 0) {
            notify_full();
        } else if (curr == max) {
            notify_idle();
        }
        return 0; // return value is ignored for UAC events
    }
}

Install the sample handler.

The handler is installed in the plugins mi::rswservices::IServices_plugin::initialize() implementation.

‎void RSWS_plugin::initialize(mi::rswservices::IExtension_context* context)
{
    if (context == NULL) {
        return;
    }
    // make the handler
    mi::base::Handle<mi::nservices::IEvent_handler> uac_sample_handler(new Sample_uac_event_handler());
    // install it
    context->install_event_handler(haproxy_handler.get());

    // Associate the handler with UAC add and remove session events. Note we can associate the sample
    // handler with both the add and remove events.
    mi::base::Handle<mi::nservices::IEvent_context> event_context(context->get_event_context());
    event_context->register_handler(mi::rswservices::UAC_SESSION_ADDED(),
                                        uac_sample_handler->get_name(),
                                        "uac_sample_add",0);
    event_context->register_handler(mi::rswservices::UAC_SESSION_REMOVED(),
                                        uac_sample_handler->get_name(),
                                        "uac_sample_remove",0);

    ...

}