# 12. Web Application Development

Chapter Contents | Prev | Next
Keyword Search:
www.openlinksw.com
docs.openlinksw.com
Book Home
Contents
Preface
Web Application Development
The HTTP Server
Web Services ACL (Access Control List)
General purpose ACLs ACL Definition/Removal Using ACL's Within Application Logic Predefined ACLs
Virtuoso Server Pages (VSP)
Virtuoso Server Pages for XML (VSPX)
Writing ASP.Net Web Applications
ASMX Web Service Hosting
Blogging & Weblogs
Writing PHP Applications
Writing JSP Applications
Perl Hosting
Python Hosting
Ruby Hosting

## 12.2. Web Services ACL (Access Control List)

Virtuoso provides a generic access control list for HTTP and other Internet protocol clients. This mechanism uses wildcard expressions to selectively block and allow ranges of IP addresses. An ordered set of patterns is matched against the origin of the request. The first matching pattern's allow/deny flag determines whether the client is approved or not.

The patterns for designating a range of IP addresses follow the syntax of the SQL 'LIKE' predicate; i.e. '%.foo.bar' or '*.foo.bar' for example.

See Also:

The LIKE Predicate & Search Patterns section.

The following mechanisms for services access restriction are defined by default:

- Web Server ACL - controls access to the Web server (basic fire wall)
- Web Proxy server ACL - controls access to the Web proxy server
- News Server ACL - controls access to the Internet news groups (reading or posting)

### 12.2.1. General purpose ACLs

The system table DB.DBA.HTTP_ACL is used to persist ACL definitions, which can be managed with simple INSERT/UPDATE/DELETE statements. The table has the following layout:

Columns for DB.DBA.HTTP_ACL:

- HA_LIST - ACL name
- HA_ORDER - Position in the list
- HA_OBJECT - Object ID (applicable to news groups also)
- HA_CLIENT_IP - *PATTERN*
- HA_FLAG - Allow/Deny flag, 0 - allow, 1 - deny
- HA_RW - Read/Write flag, 0 - read, 1 - post
- HA_DEST_IP - Destination IP/Host (applicable to the proxy also)

The primary key covers columns HA_LIST, HA_ORDER, HA_CLIENT_IP and HA_FLAG.

See Also

The full schema is listed in the Appendix under System Tables.

HA_LIST (required)

Name of the ACL, This is a label to designate a group of rules applicable to a specific service. There are three pre-defined groups which are: HTTP, NEWS, PROXY. Please note that name of group is treated as case-insensitive string. In other words we can think about HA_LIST as domain of the ACL. Developers can use that table to add their own ACLs , and use them with API functions which are discussed in the next section.

HA_ORDER (required)

Ordinal number of the rule within its list. This number should be unique within a specific group to have a well defined order of rule matching. Please note that if order is equal the one with allow flag equal to zero (HA_FLAG value see below) takes precedence. The order for applying rules for particular list is in ascending order i.e. first will be applied the rule with the smallest value of HA_ORDER.

HA_CLIENT_IP (required)

A pattern to designate separate IP address or group of addresses. This is a string value as for 'LIKE' operator. Some example is: 192.168.*; will match all hosts from local private network.

HA_FLAG (required)

A boolean; zero or positive number designating a rule to be applied for matching address/host. The default option is zero (false) for allowed action; positive (true) for denied action. So application may use it in reverse; but in that case it needs to take in account the order precedence (see HA_ORDER).

HA_OBJECT (optional)

An integer designating an ID used in predefined ACL for Internet News groups to designate ID of the group. This can be used also in other applications where one desires to apply different rules for different objects. We can think of it as a sub list inside an ACL.

HA_RW (optional)

An integer designating a action to be restricted (read/write); used in predefined Internet News groups ACL.

HA_DEST_IP (optional)

A string containing pattern to match another IP number; this is used in Web Proxy server ACL. This can also be used in custom application logic.

### 12.2.2. ACL Definition/Removal

ACL's can be managed from the administration web interface using the following steps.

- From Admin UI main menu open "Web Services" node.
- Choose "Access Control"
- By default three default ACLs are listed:
  - HTTP - rules for the Web server
  - NEWS - rules for the Internet News
  - PROXY - rules for the Web Proxy Server
- New ACLs can be added by entering a list name and clicking "Add" button.
- Existing ACLs can be edited by clicking on the link "Edit" beside each listed ACL.
- To add new rules, enter the requested information and press button "Add".
- To change the order of the rules use the "top", "bottom", "up" and "down" links.
- ACL's can be removed using the Delete button.

Alternately the HTTP_ACL table can be directly manipulated with SQL. To add new rule:

    INSERT INTO HTTP_ACL (HA_LIST, HA_ORDER, HA_CLIENT_IP, HA_FLAG) values
    ('list_name', <order number>, '*pattern*', [1/0]);

To remove existing rule:

    DELETE from HTTP_ACL where HA_LIST = 'list_name' and HA_ORDER = <order number>
    and HA_FLAG = [1/0] and HA_CLIENT_IP = '*pattern*';

### 12.2.3. Using ACL's Within Application Logic

The http_acl_get() function can be used to test an address against an ACL. The http_client_ip() function can be used to determine the IP address or DNS name of a client machine.

Using ACL's with Application Logic

To restrict a 'foo.bar' (network 333.333.333.0) from accessing a SOAP service one could use the following:

    -- deny access from '333.333.333.*'
    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip) values ('MY_SOAP', 1, 1, '333.333.333.*');
    -- allow
    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip) values ('MY_SOAP', 2, 0, '*');

    -- a procedure exposed as SOAP service

    create procedure SumService (in a int, in b int) returns int
    {
      if (0 <> http_acl_get ('MY_SOAP', http_client_ip ()))
        signal ('42000', 'Access denied');
      return (a + b);
    }

### 12.2.4. Predefined ACLs

The following ACLs are predefined and have special treatment in Web Server processing:

HTTP

General Web server ACL, applying rules to it controls access to the Web server. Thus if this ACL is managed via web UI one must pay attention not to disable the current connection and render the administration UI inaccessible. The ACL rules for 'HTTP' must contain HA_ORDER, HA_CLIENT_IP (pattern) and HA_FLAG (access flag) only. The rest of column values are ignored. To add or remove rules to that list see 'ACL definition/removal' where HA_LIST must be equal to 'HTTP'. The value of client's IP address will be tested against rules.

NEWS

controls access to the separate Internet News groups, restricting POST or READ access to them.

All valid rules for 'HTTP' are also valid for 'NEWS' with following difference:

- HA_OBJECT must be specified as ID of News group to control
- HA_RW must be specified as 0/1 to designate which action on group to control: read or post.

The HA_LIST must be equal to 'NEWS' if control is managed with SQL statements. The HA_LIST must be equal to 'NEWS'.

PROXY

This controls access to the Web Proxy Server. Note that Proxy service is disabled by default and can be enabled with 'HTTPProxyEnabled' INI setting. This ACL is similar to the HTTP ACL. Additionally, the pattern in HA_DEST_PATTERN must match the destination server. In this way certain destinations can be restricted.

Note:

HTTP ACLs affect PROXY rules. Therefore if HTTP list rejects a request from a particular client, the proxy access from there also will be rejected.

Adding/removing ACL's

To allow access from localhost only:

    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip) values ('HTTP', 1, 0, '127.0.0.1');
    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip) values ('HTTP', 2, 1, '*');

To allow only local addresses (private.net/192.168.0.0) to access proxy server.

    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip, ha_dest_ip)
                  values ('PROXY', 1, 0, '192.168.1.*', '*');
    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip, ha_dest_ip)
                  values ('PROXY', 2, 1, '*', '*');

To deny web access from some domain (bad.domain/333.333.333.0)

    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip) values ('HTTP', 1, 0, '*');
    insert into http_acl (ha_list, ha_order, ha_flag, ha_client_ip) values ('HTTP', 2, 1, '333.333.333.*');

Previous The HTTP Server | Chapter Contents | Next Virtuoso Server Pages (VSP)