oauth2.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. Configure the GeoServer OAuth2 filter
  2. -------------------------------------
  3. #. Start GeoServer and login to the web admin interface as the ``admin`` user.
  4. #. Click the ``Authentication`` link located under the ``Security`` section of
  5. the navigation sidebar.
  6. .. figure:: images/filter1.jpg
  7. :align: center
  8. #. Scroll down to the ``Authentication Filters`` panel and click the ``Add new`` link.
  9. .. figure:: images/filter2.jpg
  10. :align: center
  11. #. Click the ``OAuth2`` link.
  12. .. figure:: images/filter3.jpg
  13. :align: center
  14. #. Fill in the fields of the settings form as follows:
  15. .. figure:: images/oauth2chain001.png
  16. :align: center
  17. The default values provided with the plugin are valid for the Google OAuth2 Provider and are the following:
  18. .. code-block:: shell
  19. "Enable Redirect Authentication EntryPoint" = False
  20. "Access Token URI" = https://accounts.google.com/o/oauth2/token
  21. "User Authorization URI" = https://accounts.google.com/o/oauth2/auth
  22. "Redirect URI" = http://localhost:8080/geoserver
  23. "Check Token Endpoint URL" = https://www.googleapis.com/oauth2/v1/tokeninfo
  24. "Logout URI" = https://accounts.google.com/logout
  25. "Scopes" = https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile
  26. .. note::
  27. #. ``Client ID`` and ``Client Secret`` are the ones Google provided
  28. #. Choose a ``Role Service`` able to recognize user emails as IDs. By default a connected user will have ``ROLE_USER`` role
  29. .. warning:: A few words on the **Enable Redirect Authentication EntryPoint** option
  30. This option allows you to decide whether or not to *force* automatic redirection to OAuth2 Access Token URI or not for authentication.
  31. What does that mean?
  32. * *Enable Redirect Authentication EntryPoint* = True
  33. If not already authenticated (or no valid **Access Token** is provided in the query string), this option will **force** a redirection to the OAuth2 Provider Login page.
  34. This may cause unwanted behavior since it will override every other explicit login method like ``form``. In other words if the filter is applied for instance to the ``web`` endpoint, it won't be possible to access to the GeoServer Admin GUI using the standard login method via browser.
  35. * *Enable Redirect Authentication EntryPoint* = False
  36. In order to avoid the above issue, by disabling this option you will be **forced** to use an explicit Authentication Endpoint to login via the OAuth2 Provider login page.
  37. If not already authenticated (or no valid **Access Token** is provided in the query string), you **must** authenticate through the following URLs:
  38. #. *GeoServer OAuth2 Authorization Endpoint*; ``http://<host:port>/geoserver/j_spring_oauth2_login``
  39. #. *OAuth2 Provider Explicit User Authorization Endpoint*; this must be adapted for your specific OAuth2 Provider, the protocol stated that it should be
  40. ::
  41. https://<USER_AUTHORIZATION_URI>?scope=<SCOPES>&response_type=code&redirect_uri=<REDIRECT_URI>&client_id=<CLIENT_ID>
  42. For Google OAuth2 Provider is:
  43. ::
  44. https://accounts.google.com/o/oauth2/auth?scope%3Dhttps://www.googleapis.com/auth/userinfo.email%2Bhttps://www.googleapis.com/auth/userinfo.profile%26response_type%3Dcode%26redirect_uri%3D<REDIRECT_URI>%26client_id%3D<CLIENT_ID>
  45. #. Update the filter chains by adding the new OAuth2 filter.
  46. Once everything has been configured you should be able to see the new ``oauth2`` filter available among the ``Authentication Filters`` list
  47. .. figure:: images/oauth2filter001.png
  48. :align: center
  49. Through this it will be always possible to modify / update the filter options, or create more of them.
  50. The next step is to add the filter to the ``Filter Chains`` you want to protect with OAuth2 also
  51. .. figure:: images/oauth2filter002.png
  52. :align: center
  53. #. Select the OAuth2 Filter for each filter chain you want to protect with OAuth2.
  54. If you need to protect **all** the GeoServer services and the GeoServer Admin GUI too with OAuth2, you need to add the ``oauth2`` filter to all the following chains
  55. * ``web``
  56. * ``rest``
  57. * ``gwc``
  58. * ``default``
  59. The order of the authentication filters depends basically on which method you would like GeoServer to *try first*.
  60. .. note:: During the authentication process, the authentication filters of a ``Filter Chain`` are executed serially until one succeed (for more details please see the section :ref:`security_auth_chain`)
  61. .. warning:: If *Enable Redirect Authentication EntryPoint* = **True** for OAuth2 Filter, the ``web`` chain won't be able to login through the ``form`` method.
  62. .. figure:: images/oauth2filter003.png
  63. :align: center
  64. .. note:: Remember that the ``anonymous`` filter must be always the last one.
  65. #. Save.
  66. .. figure:: images/oauth2filter004.png
  67. :align: center
  68. It's now possible to test the authentication:
  69. #. Navigate to the GeoServer home page and log out of the admin account.
  70. #. Try to login again, you should be able now to see the external Google login form.
  71. .. figure:: images/test1.jpg
  72. :align: center
  73. .. figure:: images/test2.jpg
  74. :align: center
  75. .. figure:: images/test3.jpg
  76. :align: center
  77. .. figure:: images/test4.jpg
  78. :align: center
  79. .. figure:: images/test5.jpg
  80. :align: center