rest.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. .. _security_rest:
  2. REST Security
  3. =============
  4. In addition to providing the ability to secure OWS style services, GeoServer also supports securing RESTful services.
  5. As with layer and service security, RESTful security configuration is based on ``security_roles``. The mapping of request URI to role is defined in a file named ``rest.properties``, located in the ``security`` directory of the GeoServer data directory.
  6. Syntax
  7. ------
  8. The following syntax defines access control rules for RESTful services (parameters in brackets [] are optional)::
  9. uriPattern;method[,method,...]=role[,role,...]
  10. The parameters are:
  11. * **uriPattern**—:ref:`ant pattern <security_rest_ant_patterns>` that matches a set of request URIs
  12. * **method**—HTTP request method, one of ``GET``, ``POST``, ``PUT``, ``POST``, ``DELETE``, or ``HEAD``
  13. * **role**—Name of a predefined role. The wildcard '* is used to indicate the permission is applied to all users, including anonymous users.
  14. .. note::
  15. * URI patterns should account for the first component of the rest path, usually ``rest`` or ``api``
  16. * Method and role lists should **not** contain any spaces
  17. .. _security_rest_ant_patterns:
  18. Ant patterns
  19. ~~~~~~~~~~~~
  20. Ant patterns are commonly used for pattern matching directory and file paths. The :ref:`examples <security_rest_examples>` section contains some basic instructions. The Apache ant `user manual <http://ant.apache.org/manual/dirtasks.html>`_ contains more sophisticated use cases.
  21. .. _security_rest_examples:
  22. Examples
  23. --------
  24. Most of the examples in this section are specific to the GeoServer :ref:`rest` but any RESTful GeoServer service may be configured in the same manner.
  25. Allowing only authenticated access
  26. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. The most secure configuration is one that forces any request to be authenticated. The following example locks down access to all requests::
  28. /**;GET,POST,PUT,DELETE=ROLE_ADMINISTRATOR
  29. A less restricting configuration locks down access to operations under the path ``/rest``, but will allow anonymous access to requests that fall under other paths (for example ``/api``)::
  30. /rest/**;GET,POST,PUT,DELETE=ROLE_ADMINISTRATOR
  31. The following configuration is similar to the previous one except it grants access to a specific role rather than the administrator::
  32. /**;GET,POST,PUT,DELETE=ROLE_TRUSTED
  33. ``ROLE_TRUSTED`` is a role defined in ``users.properties``.
  34. Providing anonymous read-only access
  35. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. The following configuration allows anonymous access when the ``GET`` (read) method is used but forces authentication for a ``POST``, ``PUT``, or ``DELETE`` (write)::
  37. /**;GET=IS_AUTHENTICATED_ANONYMOUSLY
  38. /**;POST,PUT,DELETE=TRUSTED_ROLE
  39. Securing a specific resource
  40. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. The following configuration forces authentication for access to a particular resource (in this case a feature type)::
  42. /rest/**/states*;GET=TRUSTED_ROLE
  43. /rest/**;POST,PUT,DELETE=TRUSTED_ROLE
  44. The following secures access to a set of resources (in this case all data stores)::
  45. /rest/**/datastores/*;GET=TRUSTED_ROLE
  46. /rest/**/datastores/*.*;GET=TRUSTED_ROLE
  47. /rest/**;POST,PUT,DELETE=TRUSTED_ROLE