index.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. .. _security:
  2. Security
  3. ========
  4. This section provides an overview of the GeoServer security subsystem API.
  5. .. _security_manager:
  6. Security Manager
  7. ----------------
  8. The ``GeoServerSecurityManager`` class is the main facade for the security
  9. subsystem. It plays a similar role to that of the ``GeoServer`` and ``Catalog``
  10. interfaces for the configuration and catalog subsystems respectively. Some of
  11. the duties of this class include:
  12. * Access to security services such as user group and role services,
  13. authentication providers, etc...
  14. * Manage the lifecycle of security services
  15. * CRUD operations for security service configurations
  16. * Access to various singleton classes such as ``ResourceAccessManager``,
  17. ``KeyStoreProvider``, ``AuthenticationCache``,
  18. ``GeoServerSecurityFilterChain``, etc..
  19. * Implement the spring security AuthenticationProviderManager interface
  20. providing the list of active :ref:`auth_provider` instances.
  21. Security Services
  22. -----------------
  23. ``GeoServerSecurityService`` is the base interface for all security services, including:
  24. * User/group services
  25. * Role services
  26. * Authentication filters
  27. * Authentication providers
  28. * Keystore password providers
  29. The interface provides some common methods for all security services,
  30. including::
  31. void initializeFromConfig(SecurityNamedServiceConfig config);
  32. Every type of security service corresponds to a configuration object for that
  33. service. The configuration object is a simple java bean that contains the
  34. service configuration. These objects are persisted via xstream in the GeoServer
  35. data directory. See :ref:`service_config` for more details.
  36. Security services are created via methods provided by the security manager. For
  37. instance to create a new xml user group service::
  38. GeoServerSecurityManager mgr = ...;
  39. XMLSecurityServiceConfig config = new XMLSecurityServiceConfig();
  40. config.setName("foo");
  41. config.setFilename("users.xml");
  42. mgr.saveUserGroupService(config);
  43. An instance of a security service is obtained by looking it up by the name
  44. matching its configuration object::
  45. GeoServerUserGroupService ugService = mgr.loadUserGroupService("foo");
  46. The config object for the service can be looked up in a similar way::
  47. SecurityUserGroupServiceConfig config = mgr.loadUserGroupServiceConfig("foo");
  48. And modified accordingly::
  49. config.setPasswordEncoderName("digest");
  50. mgr.saveUserGroupServiceConfig(config);
  51. .. _usergroup_service:
  52. UserGroup Service/Store
  53. ^^^^^^^^^^^^^^^^^^^^^^^
  54. The ``GeoServerUserGroupService`` and ``GeoServerUserGroupStore`` interfaces provides a database
  55. for users and groups. A GeoServerUserGroupService may be read only in that it acts solely
  56. as a source without the ability to create new or edit existing users and groups.
  57. The interfaces provide access to users and groups::
  58. GeoServerUserGroupService ugService = mgr.loadUserGroupService("default");
  59. ugService.getUsers();
  60. GeoServerUser user = ugService.getUserByUsername("admin");
  61. ugService.getGroups();
  62. GeoServerUserGroup group = ugService.getGroupByGroupname("users");
  63. The service interface advertises whether it is read only::
  64. if (ugService.canCreateStore()) {
  65. GeoServerUserGroupStore store = ugService.createStore();
  66. store.addUser(new GeoServerUser("bob"));
  67. store.store();
  68. }
  69. The ``GeoServerUserGroupService`` implements the spring security ``UserDetailsService``
  70. interface in order to integrate with existing facilities such as remember me
  71. services which require a user details service for loading user information at
  72. runtime.
  73. .. _role_service:
  74. Role Service/Store
  75. ^^^^^^^^^^^^^^^^^^
  76. ``GeoServerRoleService`` and ``GeoServerRoleStore`` provide a database for roles and role
  77. associations for users and groups. Like user group services a ``GeoServerRoleService``
  78. may be read only::
  79. GeoServerRoleService roleService = mgr.loadRoleService("default");
  80. roleService.getRoles();
  81. roleService.getRolesForUser("admin");
  82. roleService.getRolesForGroup("users");
  83. if (roleService.canCreateStore()) {
  84. GeoServerRoleStore store = roleService.createStore();
  85. GeoServerRole role = new GeoServerRole("ROLE_FOO");
  86. store.addRole(role);
  87. store.associateRoleToGroup(role, "users");
  88. store.store();
  89. }
  90. .. _auth_provider:
  91. Authentication Provider
  92. ^^^^^^^^^^^^^^^^^^^^^^^
  93. ``GeoServerAuthenticationProvider`` is an extension of the spring security ``AuthenticationProvider``
  94. interface and is responsible for performing authentication of user credentials.
  95. The class extends the ``AuthenticationProvider`` contract and provides methods
  96. for authentication that provide access to the current request to make it
  97. easier for providers that require request information to perform authentication::
  98. @Override
  99. public final Authentication authenticate(Authentication authentication)
  100. throws AuthenticationException {
  101. return authenticate(authentication, request());
  102. }
  103. /**
  104. * Same function as {@link #authenticate(Authentication)} but is provided with
  105. * the current request object.
  106. */
  107. public abstract Authentication authenticate(Authentication authentication,
  108. HttpServletRequest request) throws AuthenticationException;
  109. The list of active authentication providers is maintained by the GeoServerSecurityManager
  110. which extends the spring security ``AuthenticationProviderManager`` interface.
  111. .. _auth_filter:
  112. Authentication Filter
  113. ^^^^^^^^^^^^^^^^^^^^^
  114. ``GeoServerSecurityFilter`` is the base class for servlet filters that play a part
  115. in the authentication process. Such filters can play two roles.
  116. The first is to gather authentication credentials to passed off to a provider for
  117. actual authentication. An example would be a filter for doing HTTP basic auth.
  118. The second role is to perform "pre-authentication" in which involves doing
  119. authentication by recognizing authentication that has already taken place "outside"
  120. of GeoServer. An example would be when using a security proxy such as Siteminder or
  121. a "J2ee" authentication which involves delegating to the servlet container for
  122. doing authentication.
  123. Security filters are maintained in the :ref:`filter chain <auth_filter_chain>` which maintains
  124. the mapping of the filters to be applied to a specific type of request. For example
  125. the filters applied to a web UI request are different than those applied to an OGC
  126. or REST request.
  127. .. figure:: images/filter_chain.png
  128. :align: center
  129. Password Policy
  130. ^^^^^^^^^^^^^^^
  131. ``PasswordPolicy`` is the interface for validating user passwords, applying constraints such
  132. as password length, character mix, etc...
  133. RootPasswordProvider
  134. ^^^^^^^^^^^^^^^^^^^^^^
  135. Security service that provides a method for obtaining the GeoServer keystore password.
  136. The keystore password serves two purposes.
  137. #. Is the password for the GeoServer "root" account
  138. #. Protects the GeoServer keystore that is used to store encryption keys
  139. .. _service_config:
  140. Security Plugin Provider
  141. ------------------------
  142. The ``GeoServerSecurityProvider`` is the actual extension point that allows for the
  143. plugging in of instances of the services discussed above. The single interface covers
  144. all the security services.
  145. For each type of security service the provider has two methods to implement. For example
  146. with a user group service::
  147. public Class<? extends GeoServerUserGroupService> getUserGroupServiceClass() {
  148. return null;
  149. }
  150. public GeoServerUserGroupService createUserGroupService(SecurityNamedServiceConfig config)
  151. throws IOException {
  152. return null;
  153. }
  154. The first method reports on the specific class of user group service it implements.
  155. This is how a specific security provider is chosen from a specific configuration object.
  156. ``SecurityNamedServiceConfig.getClassName()`` is used to locate the provider.
  157. The second method creates an instance of the security service from a specified
  158. configuration object. Providers are registered via spring, for example::
  159. <bean id="ldapSecurityProvider" class="org.geoserver.security.ldap.LDAPSecurityProvider">
  160. <constructor-arg ref="geoServerSecurityManager"/>
  161. </bean>
  162. Security Configuration
  163. ----------------------
  164. Service Configuration
  165. ^^^^^^^^^^^^^^^^^^^^^
  166. As mentioned above each type of security service corresponds to a configuration class.
  167. The ``SecurityNamedServiceConfig`` is the base class for all such configuration classes
  168. and maintains three properties that all classes inherit. The first is name for the
  169. configuration::
  170. /**
  171. * The name of the service.
  172. */
  173. String getName();
  174. This name is used to reference both the configuration directly, or to the corresponding
  175. service implementation. For example consider a user group service named "foo"::
  176. GeoServerUserGroupService service = mgr.loadUserGroupService("foo");
  177. SecurityUserGroupServiceConfig config = mgr.loadUserGroupServiceConfig("foo");
  178. The second property is the fully qualified class name of the service implementation
  179. that the config object corresponds to::
  180. /**
  181. * Name of class for implementation of the service.
  182. */
  183. String getClassName();
  184. For instance consider creating an XML user group service::
  185. XMLUserGroupServiceConfig config = new XMLUserGroupServiceConfig();
  186. config.setClassName(XMLUserGroupService.class.getName());
  187. The third property is an internal identifier, similar to how catalog and configuration
  188. objects have an id::
  189. /**
  190. * Internal id of the config object.
  191. * <p>
  192. * This method should be used by client code.
  193. * </p>
  194. */
  195. String getId();
  196. The main purpose of this id is to detect if the security service
  197. config has been persisted or not.
  198. Service configuration objects are persisted in the geoserver data directory under
  199. the ``security`` directory. Under ``security`` are sub directories for each service
  200. type::
  201. security/
  202. auth/
  203. filter/
  204. masterpw/
  205. pwpolicy/
  206. role/
  207. usergroup/
  208. Under each directory are additional subdirectories for each named service of that type.
  209. For example, out of the box GeoServer security is configured with the following:
  210. * Single user/group service named "default"
  211. * Single role service named "default"
  212. * Single authentication provider named "default"
  213. This would correspond to the following directory structure::
  214. security/
  215. auth/
  216. default/
  217. role/
  218. default/
  219. usergroup/
  220. default/
  221. Let's say an additional authentication provider named "ldap" was added. The tree would look
  222. like::
  223. security/
  224. auth/
  225. default/
  226. ldap/
  227. .
  228. .
  229. .
  230. Inside each named configuration directory is a file named ``config.xml`` that contains the
  231. direct xstream serialization of the configuration object. For example the default user
  232. group service configuration is persisted in the file ``security/usergroup/default/config.xml``
  233. and looks like::
  234. <userGroupService>
  235. <id>7aacccc3:13660a38ccb:-7ffd</id>
  236. <name>default</name>
  237. <className>org.geoserver.security.xml.XMLUserGroupService</className>
  238. <fileName>users.xml</fileName>
  239. <checkInterval>10000</checkInterval>
  240. <validating>true</validating>
  241. <passwordEncoderName>pbePasswordEncoder</passwordEncoderName>
  242. <passwordPolicyName>default</passwordPolicyName>
  243. </userGroupService>
  244. Global Configuration
  245. ^^^^^^^^^^^^^^^^^^^^
  246. Aside from configuration objects for the various security services is the ``SecurityManagerConfig``
  247. class which provides the same function but for global security settings. It contains a number of
  248. configuration properties such as the active role service, the list of authentication providers
  249. and filters making up the active :ref:`auth_filter_chain`, and configuration for remember me
  250. services.
  251. Interacting with the global configuration is much like interacting with a security service
  252. configuration::
  253. SecurityManagerConfig config = mgr.getSecurityConfig();
  254. config.setEncryptingUrlParams(false);
  255. config.getAuthProviderNames().add("ldap");
  256. config.saveSecurityConfig(config);
  257. .. _auth_filter_chain:
  258. Authentication Chain
  259. --------------------
  260. The ``GeoServerSecurityFilterChain`` class is a data structure that maintains mappings
  261. from request type to a list of named :ref:`security filters <auth_filter>`. This class is
  262. persisted with the rest of the global security configuration as available as a property
  263. of the ``SecurityManagerConfig`` class::
  264. GeoServerSecurityFilterChain filterChain = mgr.getSecurityConfig().getFilterChain();
  265. The filterChain is essentially a map whose keys are strings corresponding to ant request
  266. patterns. The values are lists of :ref:`auth_filter` names.
  267. ``GeoServerSecurityFilterChainProxy`` is an extension of the spring security ``FilterChainProxy``
  268. and is responsible for creating the actual filter chain from the
  269. ``GeoServerSecurityFilterChain`` configuration object.
  270. Pluggable Login Endpoints
  271. ----------------------------------
  272. To enable a new Login button just add lines similar to the following configuration into the ``applicationContext.xml``::
  273. <!-- login button -->
  274. <bean id="geoserverFormLoginButton" class="org.geoserver.web.LoginFormInfo">
  275. <property name="id" value="geoserverFormLoginButton" />
  276. <property name="titleKey" value="login" />
  277. <property name="descriptionKey" value="GeoServerBasePage.description" />
  278. <property name="componentClass" value="org.geoserver.web.GeoServerBasePage" />
  279. <property name="name" value="form" />
  280. <property name="icon" value="img/icons/silk/door-in.png" />
  281. <property name="include" value="include_login_form.html" />
  282. <property name="loginPath" value="j_spring_security_check" />
  283. </bean>
  284. The same can be done for any other Security Filter which needs a specific button for a Login Endpoint.
  285. The properties of ``LoginFormInfo`` are:
  286. #. **id**; a unique ID to be provided to the extension.
  287. #. **titleKey**; key of the ``GeoServerApplication.properties`` message with internationalization. If **null** or not present, the Login button won't have any text.
  288. #. **descriptionKey**; optional image alt message. This value represents the key of the ``GeoServerApplication.properties`` message with internationalization.
  289. #. **componentClass**; base class which will provide base package path for resources. Wicket will look for resources relative to the *componentClass* package.
  290. #. **name**; used for ordering. The Login buttons will be displayed in alphabetical order accordingly to this value. The name **must** also contain a keyword present on the associated Security Filter name defined by User.
  291. #. **icon**; optional resource path to the button icon. If not specified GeoServer will use the default "door-in" one. The path **must** be relative to the *componentClass* package.
  292. #. **include**; optional static HTML file resource to be rendered into the Login form. The path **must** be relative to the *componentClass* package.
  293. #. **loginPath**; Login custom endpoint used by the associated Security Filter.
  294. Example of **include** HTML can be::
  295. <label class="noshow" for="username"><wicket:message key="username">Username</wicket:message></label>
  296. <input id="username" type="text" name="username" value="" title="username" placeholder="username" wicket:message="title:username,placeholder:username"/>
  297. <label class="noshow" for="password"><wicket:message key="password">Password</wicket:message></label>
  298. <input id="password" type="password" name="password" value="" title="password" placeholder="password" wicket:message="title:password,placeholder:passwordGeoServer"/>
  299. <label class="shown" for="_spring_security_remember_me"><wicket:message key="rememberMe">Remember me</wicket:message></label>
  300. <input id="_spring_security_remember_me" type="checkbox" name="_spring_security_remember_me" />