You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Laurent Mignon
  5. # Copyright 2014 'ACSONE SA/NV'
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. {
  22. 'name': 'Authenticate via HTTP Remote User',
  23. 'version': '1.0',
  24. 'category': 'Tools',
  25. 'description': """
  26. Allow users to be automatically logged in.
  27. ==========================================
  28. This module initialize the session by looking for the field HTTP_REMOTE_USER in
  29. the HEADER of the HTTP request and trying to bind the given value to a user
  30. This module must be loaded at startup; Add the *--load* parameter to the startup
  31. command: ::
  32. --load=web,web_kanban,auth_from_http_remote_user, ...
  33. If the field is not found or no user matches the given one, it can lets the
  34. system redirect to the login page (default) or issue a login error page depending
  35. of the configuration.
  36. How to test the module with Apache [#]_
  37. ----------------------------------------
  38. Apache can be used as a reverse proxy providing the authentication and adding the
  39. required field in the Http headers.
  40. Install apache: ::
  41. $ sudo apt-get install apache2
  42. Define a new vhost to Apache by putting a new file in /etc/apache2/sites-available: ::
  43. $ sudo vi /etc/apache2/sites-available/MY_VHOST.com
  44. with the following content: ::
  45. <VirtualHost *:80>
  46. ServerName MY_VHOST.com
  47. ProxyRequests Off
  48. <Location />
  49. AuthType Basic
  50. AuthName "Test OpenErp auth_from_http_remote_user"
  51. AuthBasicProvider file
  52. AuthUserFile /etc/apache2/MY_VHOST.htpasswd
  53. Require valid-user
  54. RewriteEngine On
  55. RewriteCond %{LA-U:REMOTE_USER} (.+)
  56. RewriteRule . - [E=RU:%1]
  57. RequestHeader set Remote-User "%{RU}e" env=RU
  58. </Location>
  59. ProxyPass / http://127.0.0.1:8069/ retry=10
  60. ProxyPassReverse / http://127.0.0.1:8069/
  61. ProxyPreserveHost On
  62. </VirtualHost>
  63. .. important:: The *RequestHeader* directive is used to add the *Remote-User* field
  64. in the http headers. By default an *'Http-'* prefix is added to the field name.
  65. In OpenErp, header's fields name are normalized. As result of this normalization,
  66. the 'Http-Remote-User' is available as 'HTTP_REMOTE_USER'. If you don't know how
  67. your specified field is seen by OpenErp, run your server in debug mode once the
  68. module is activated and look for an entry like: ::
  69. DEBUG openerp1 openerp.addons.auth_from_http_remote_user.controllers.session:
  70. Field 'HTTP_MY_REMOTE_USER' not found in http headers
  71. {'HTTP_AUTHORIZATION': 'Basic YWRtaW46YWRtaW4=', ..., 'HTTP_REMOTE_USER': 'demo')
  72. Enable the required apache modules: ::
  73. $ sudo a2enmod headers
  74. $ sudo a2enmod proxy
  75. $ sudo a2enmod rewrite
  76. $ sudo a2enmod proxy_http
  77. Enable your new vhost: ::
  78. $ sudo a2ensite MY_VHOST.com
  79. Create the *htpassword* file used by the configured basic authentication: ::
  80. $ sudo htpasswd -cb /etc/apache2/MY_VHOST.htpasswd admin admin
  81. $ sudo htpasswd -b /etc/apache2/MY_VHOST.htpasswd demo demo
  82. For local test, add the *MY_VHOST.com* in your /etc/vhosts file.
  83. Finally reload the configuration: ::
  84. $ sudo service apache2 reload
  85. Open your browser and go to MY_VHOST.com. If everything is well configured, you are prompted
  86. for a login and password outside OpenErp and are automatically logged in the system.
  87. .. [#] Based on a ubuntu 12.04 env
  88. """,
  89. 'author': 'Acsone SA/NV',
  90. 'maintainer': 'ACSONE SA/NV',
  91. 'website': 'http://www.acsone.eu',
  92. 'depends': ['web'],
  93. "license": "AGPL-3",
  94. 'data': [
  95. 'res_config_view.xml',
  96. 'res_config_data.xml'],
  97. "demo": [],
  98. "test": [],
  99. "active": False,
  100. "license": "AGPL-3",
  101. "installable": True,
  102. "auto_install": False,
  103. "application": False,
  104. }