roleservices.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. .. _security_rolesystem_roleservices:
  2. Role services
  3. =============
  4. A **role service** provides the following information for roles:
  5. * List of roles
  6. * Calculation of role assignments for a given user
  7. * Mapping of a role to the system role ``ROLE_ADMINISTRATOR``
  8. * Mapping of a role to the system role ``ROLE_GROUP_ADMIN``
  9. When a user/group service loads information about a user or a group, it delegates to the role service to
  10. determine which roles should be assigned to the user or group. Unlike
  11. :ref:`security_rolesystem_usergroupservices`, only one role service is active at any given time. The default
  12. role service is set on the :ref:`security_webadmin_settings` page.
  13. By default, GeoServer supports two types of role services:
  14. * XML—*(Default)* role service persisted as XML
  15. * JDBC—Role service persisted in a database via JDBC
  16. .. _security_rolesystem_mapping:
  17. Mapping roles to system roles
  18. -----------------------------
  19. To assign the system role ``ROLE_ADMINISTRATOR`` to a user or to a group, a new role with a different name must be created and mapped to the ``ROLE_ADMINISTRATOR`` role. The same holds true for the system role ``ROLE_GROUP_ADMIN``. The mapping is stored in the service's ``config.xml`` file.
  20. .. code-block:: xml
  21. <roleService>
  22. <id>471ed59f:13915c479bc:-7ffc</id>
  23. <name>default</name>
  24. <className>org.geoserver.security.xml.XMLRoleService</className>
  25. <fileName>roles.xml</fileName>
  26. <checkInterval>10000</checkInterval>
  27. <validating>true</validating>
  28. <adminRoleName>ADMIN</adminRoleName>
  29. <groupAdminRoleName>GROUP_ADMIN</groupAdminRoleName>
  30. </roleService>
  31. In this example, a user or a group assigned to the role ``ADMIN`` is also assigned to the system role ``ROLE_ADMINISTRATOR``. The same holds true for ``GROUP_ADMIN`` and ``ROLE_GROUP_ADMIN``.
  32. .. _security_rolesystem_rolexml:
  33. XML role service
  34. ----------------
  35. The XML role service persists the role database in an XML file. This is the default role service for GeoServer.
  36. This service represents the user database as XML, and corresponds to this :download:`XML schema <schemas/roles.xsd>`.
  37. .. note::
  38. The XML role file, :file:`roles.xml`, is located in the GeoServer data directory, ``security/role/<name>/roles.xml``, where ``<name>`` is the name of the role service.
  39. The service is configured to map the local role ``ADMIN`` to the system role ``ROLE_ADMINISTRATOR``. Additionally, ``GROUP_ADMIN`` is mapped to ``ROLE_GROUP_ADMIN``. The mapping is stored the ``config.xml`` file of each role service.
  40. The following provides an illustration of the ``roles.xml`` that ships with the default GeoServer configuration:
  41. .. code-block:: xml
  42. <roleRegistry version="1.0" xmlns="http://www.geoserver.org/security/roles">
  43. <roleList>
  44. <role id="ADMIN"/>
  45. <role id="GROUP_ADMIN"/>
  46. </roleList>
  47. <userList>
  48. <userRoles username="admin">
  49. <roleRef roleID="ADMIN"/>
  50. </userRoles>
  51. </userList>
  52. <groupList/>
  53. </roleRegistry>
  54. This configuration contains two roles named ``ADMIN`` and ``GROUP_ADMIN``. The role ``ADMIN`` is assigned to the ``admin`` user. Since the ``ADMIN`` role is mapped to the system role ``ROLE_ADMINISTRATOR``, the role calculation assigns both roles to the ``admin`` user.
  55. For further information, please refer to :ref:`configuring a role service <security_webadmin_roleservices>` in the :ref:`web_admin`.
  56. .. _security_rolesystem_rolej2ee:
  57. J2EE role service
  58. -----------------
  59. The J2EE role service parses roles from the ``WEB-INF/web.xml`` file. As a consequence, this service is a read only role service.
  60. Roles are extracted from the following XML elements:
  61. ``<security-role>``
  62. ^^^^^^^^^^^^^^^^^^^
  63. .. code-block:: xml
  64. <security-role>
  65. <role-name>role1</role-name>
  66. </security-role>
  67. <security-role>
  68. <role-name>role2</role-name>
  69. </security-role>
  70. <security-role>
  71. <role-name>employee</role-name>
  72. </security-role>
  73. Roles retrieved:
  74. * ``role1``
  75. * ``role2``
  76. * ``employee``
  77. ``<security-constraint>``
  78. ^^^^^^^^^^^^^^^^^^^^^^^^^
  79. .. code-block:: xml
  80. <security-constraint>
  81. <web-resource-collection>
  82. <web-resource-name>Protected Area</web-resource-name>
  83. <url-pattern>/jsp/security/protected/*</url-pattern>
  84. <http-method>PUT</http-method>
  85. <http-method>DELETE</http-method>
  86. <http-method>GET</http-method>
  87. <http-method>POST</http-method>
  88. </web-resource-collection>
  89. <auth-constraint>
  90. <role-name>role1</role-name>
  91. <role-name>employee</role-name>
  92. </auth-constraint>
  93. </security-constraint>
  94. Roles retrieved:
  95. * ``role1``
  96. * ``employee``
  97. ``<security-role-ref>``
  98. ^^^^^^^^^^^^^^^^^^^^^^^
  99. .. code-block:: xml
  100. <security-role-ref>
  101. <role-name>MGR</role-name>
  102. <!-- role name used in code -->
  103. <role-link>employee</role-link>
  104. </security-role-ref>
  105. Roles retrieved:
  106. * ``MGR``
  107. .. _security_rolesystem_rolejdbc:
  108. JDBC role service
  109. -----------------
  110. The JDBC role service persists the role database via JDBC, managing the role information in multiple tables. The role database schema is as follows:
  111. .. list-table:: Table: roles
  112. :widths: 15 15 15 15
  113. :header-rows: 1
  114. * - Field
  115. - Type
  116. - Null
  117. - Key
  118. * - name
  119. - varchar(64)
  120. - NO
  121. - PRI
  122. * - parent
  123. - varchar(64)
  124. - YES
  125. -
  126. .. list-table:: Table: role_props
  127. :widths: 15 15 15 15
  128. :header-rows: 1
  129. * - Field
  130. - Type
  131. - Null
  132. - Key
  133. * - rolename
  134. - varchar(64)
  135. - NO
  136. - PRI
  137. * - propname
  138. - varchar(64)
  139. - NO
  140. - PRI
  141. * - propvalue
  142. - varchar(2048)
  143. - YES
  144. -
  145. .. list-table:: Table: user_roles
  146. :widths: 15 15 15 15
  147. :header-rows: 1
  148. * - Field
  149. - Type
  150. - Null
  151. - Key
  152. * - username
  153. - varchar(128)
  154. - NO
  155. - PRI
  156. * - rolename
  157. - varchar(64)
  158. - NO
  159. - PRI
  160. .. list-table:: Table: group_roles
  161. :widths: 15 15 15 15
  162. :header-rows: 1
  163. * - Field
  164. - Type
  165. - Null
  166. - Key
  167. * - groupname
  168. - varchar(128)
  169. - NO
  170. - PRI
  171. * - rolename
  172. - varchar(64)
  173. - NO
  174. - PRI
  175. The ``roles`` table is the primary table and contains the list of roles. Roles in GeoServer support inheritance, so a role may optionally have a link to a parent role. The ``role_props`` table maps additional properties to a role. (See the section on :ref:`security_rolesystem_roles` for more details.) The ``user_roles`` table maps users to the roles they are assigned. Similarly, the ``group_roles`` table maps which groups have been assigned to which roles.
  176. The default GeoServer security configuration is:
  177. .. list-table:: Table: roles
  178. :widths: 15 15
  179. :header-rows: 1
  180. * - name
  181. - parent
  182. * - *Empty*
  183. - *Empty*
  184. .. list-table:: Table: role_props
  185. :widths: 15 15 15
  186. :header-rows: 1
  187. * - rolename
  188. - propname
  189. - propvalue
  190. * - *Empty*
  191. - *Empty*
  192. - *Empty*
  193. .. list-table:: Table: user_roles
  194. :widths: 15 15
  195. :header-rows: 1
  196. * - username
  197. - rolename
  198. * - *Empty*
  199. - *Empty*
  200. .. list-table:: Table: group_roles
  201. :widths: 15 15
  202. :header-rows: 1
  203. * - groupname
  204. - rolename
  205. * - *Empty*
  206. - *Empty*
  207. For further information, please refer to :ref:`configuring a role service <security_webadmin_roleservices>` in the :ref:`web_admin`.
  208. LDAP role service
  209. -----------------
  210. The LDAP role service is a read only role service that maps groups from an LDAP repository to GeoServer roles.
  211. Groups are extracted from a specific LDAP node, configured as the ``Groups search base``. A role is mapped for every matching group. The role will have a name that is built taking the Group common name (cn attribute), transformed to upper case and with a ``ROLE_`` prefix applied.
  212. It is possible to filter extracted groups using an ``All groups filter`` (defaults to ``cn=*`` that basically extracts all nodes from the configured base). It is also possible to configure the filter for ``users to roles membership`` (defaults to member={0}).
  213. A specific group can be assigned to the ``ROLE_ADMINISTRATOR`` and/or the ``ROLE_GROUP_ADMIN`` administrative roles.
  214. Groups extraction can be done anonymously or using a given username/password if the LDAP repository requires it.
  215. An example of configuration file (config.xml) for this type of role service is the following:
  216. .. code-block:: xml
  217. <org.geoserver.security.ldap.LDAPRoleServiceConfig>
  218. <id>-36dfbd50:1424687f3e0:-8000</id>
  219. <name>ldapacme</name>
  220. <className>org.geoserver.security.ldap.LDAPRoleService</className>
  221. <serverURL>ldap://127.0.0.1:10389/dc=acme,dc=org</serverURL>
  222. <groupSearchBase>ou=groups</groupSearchBase>
  223. <groupSearchFilter>member=uid={0},ou=people,dc=acme,dc=org</groupSearchFilter>
  224. <useTLS>false</useTLS>
  225. <bindBeforeGroupSearch>true</bindBeforeGroupSearch>
  226. <adminGroup>ROLE_ADMIN</adminGroup>
  227. <groupAdminGroup>ROLE_ADMIN</groupAdminGroup>
  228. <user>uid=bill,ou=people,dc=acme,dc=org</user>
  229. <password>hello</password>
  230. <allGroupsSearchFilter>cn=*</allGroupsSearchFilter>
  231. </org.geoserver.security.ldap.LDAPRoleServiceConfig>
  232. For further information, please refer to :ref:`configuring a role service <security_webadmin_roleservices>` in the :ref:`web_admin`.
  233. REST role service
  234. -----------------
  235. The REST role service is a read only role service that maps groups and associated users to roles from a remote REST web service.
  236. The REST service **must** support JSON encoding.
  237. Here is a listing of significant methods provided by the REST Role Service (based on the LDAP role service, which similarly has to make network calls to work):
  238. .. list-table:: Table: roles
  239. :widths: 10 20
  240. :header-rows: 1
  241. * - Method
  242. - Mandatory
  243. * - *getUserNamesForRole(roleName)*
  244. - N (implemented in LDAP, but I don’t see actual users of this method besides a utility method that nobody uses)
  245. * - *getRolesForUser(user)*
  246. - Y
  247. * - *getRolesForGroup(group)*
  248. - N
  249. * - *getRoles()*
  250. - Y (used by the UI)
  251. * - *getParentRole(role)*
  252. - N
  253. * - *getAdminRole()*
  254. - Y
  255. * - *getGroupAdminRole()*
  256. - Y
  257. * - *getRoleCount()*
  258. - Y (does not seem to be used much, we can trivially implement it from getRoles()
  259. REST APIs
  260. ^^^^^^^^^
  261. The following is an example of the REST API the role service may handle. The JSON and remote endpoints may differ; this is configurable via UI, allowing the REST role service to connect to a generic REST Service
  262. From the above we could have the following REST API to talk to
  263. ``../api/roles``
  264. Returns the full list of roles (no paging required, we assume it’s small). Example response:
  265. .. code-block:: json
  266. {"groups":["r1","r2","r3"]}
  267. ``../api/adminrole``
  268. Returns the role of the administrator (yes, just one, it’s strange…):
  269. .. code-block:: json
  270. {"adminRole":["root"]}
  271. ``../api/users/<user>``
  272. Returns the list of roles for a particular user. Example response:
  273. .. code-block:: json
  274. {"users": [{"user":"u1", "groups":["r1","r2"]}]}
  275. Configurable API
  276. ^^^^^^^^^^^^^^^^
  277. The GeoServerRoleService talking to a remote service provides the following config parameters:
  278. * Base URL for the remote service
  279. * Configurable URLs for the various calls
  280. * JSON paths to the properties that contain the list of roles, and the one admin role
  281. The above can be configured via the :ref:`web_admin`. The figure below shows the REST role service options configured to be compatible with the sample APIs above:
  282. .. figure:: images/restroleservice.png
  283. :align: center
  284. *REST based role service configuration panel*