From 94057ffb4e30707ee5aba08c8d160d799a97ed7b Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Tue, 15 Jun 2021 14:28:03 +0200 Subject: [PATCH] [ADD] auth_saml_enviroment --- auth_saml_environment/README.rst | 118 +++++ auth_saml_environment/__init__.py | 2 + auth_saml_environment/__manifest__.py | 20 + auth_saml_environment/controllers/__init__.py | 1 + auth_saml_environment/controllers/main.py | 16 + auth_saml_environment/models/__init__.py | 1 + .../models/auth_saml_provider.py | 44 ++ auth_saml_environment/readme/CONFIGURE.rst | 18 + auth_saml_environment/readme/CONTRIBUTORS.rst | 2 + auth_saml_environment/readme/DESCRIPTION.rst | 1 + auth_saml_environment/readme/INSTALL.rst | 2 + auth_saml_environment/readme/ROADMAP.rst | 2 + auth_saml_environment/readme/USAGE.rst | 6 + .../static/description/index.html | 448 ++++++++++++++++++ auth_saml_environment/tests/__init__.py | 1 + .../tests/test_environment_variable.py | 35 ++ .../views/saml_provider_view.xml | 26 + oca_dependencies.txt | 1 + .../odoo/addons/auth_saml_environment | 1 + setup/auth_saml_environment/setup.py | 6 + 20 files changed, 751 insertions(+) create mode 100644 auth_saml_environment/README.rst create mode 100644 auth_saml_environment/__init__.py create mode 100644 auth_saml_environment/__manifest__.py create mode 100644 auth_saml_environment/controllers/__init__.py create mode 100644 auth_saml_environment/controllers/main.py create mode 100644 auth_saml_environment/models/__init__.py create mode 100644 auth_saml_environment/models/auth_saml_provider.py create mode 100644 auth_saml_environment/readme/CONFIGURE.rst create mode 100644 auth_saml_environment/readme/CONTRIBUTORS.rst create mode 100644 auth_saml_environment/readme/DESCRIPTION.rst create mode 100644 auth_saml_environment/readme/INSTALL.rst create mode 100644 auth_saml_environment/readme/ROADMAP.rst create mode 100644 auth_saml_environment/readme/USAGE.rst create mode 100644 auth_saml_environment/static/description/index.html create mode 100644 auth_saml_environment/tests/__init__.py create mode 100644 auth_saml_environment/tests/test_environment_variable.py create mode 100644 auth_saml_environment/views/saml_provider_view.xml create mode 120000 setup/auth_saml_environment/odoo/addons/auth_saml_environment create mode 100644 setup/auth_saml_environment/setup.py diff --git a/auth_saml_environment/README.rst b/auth_saml_environment/README.rst new file mode 100644 index 0000000..93125a3 --- /dev/null +++ b/auth_saml_environment/README.rst @@ -0,0 +1,118 @@ +====================== +Auth SAML environement +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github + :target: https://github.com/OCA/server-env/tree/14.0/auth_saml_environment + :alt: OCA/server-env +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-env-14-0/server-env-14-0-auth_saml_environment + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/254/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to use server env for SAML configuration + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +To install this module, you need to have the following modules installed and +properly configured: `server_environment module` `auth_saml` + +Configuration +============= + +To configure this module, you need to: + +Create a module server_environment_file with a cfg file or set the environment variable +SERVER_ENV_CONFIG with the following section: + +[auth_saml_provider.] + +Where is optional and must be equal to the name field you defined in Odoo for the IDP. + + +Example of configuration + +[auth_saml_provider.my_idp] + +idp_metadata=<...> +sp_baseurl=https://odoo-community.org +sp_pem_public_path=/data/cert.pem +sp_pem_private_path=/data/key.pem + +Usage +===== + +Once configured, Odoo will read the Auth SAML Providers values from the +configuration. + +Note that visibility of login button for SAML is changed and differs from `auth_saml` module, +instead of relying on which fields are filled or not, all providers will be displayed as long +as their configuration in Odoo are set to active. + +Known issues / Roadmap +====================== + +* Due to the special nature of this addon, you cannot test it on the OCA + runbot. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp SA + +Contributors +~~~~~~~~~~~~ + +* Denis Leemann +* Yannick Vaucher + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-env `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/auth_saml_environment/__init__.py b/auth_saml_environment/__init__.py new file mode 100644 index 0000000..f7209b1 --- /dev/null +++ b/auth_saml_environment/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import controllers diff --git a/auth_saml_environment/__manifest__.py b/auth_saml_environment/__manifest__.py new file mode 100644 index 0000000..fc30a3b --- /dev/null +++ b/auth_saml_environment/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2021 Camptocamp SA (http://www.camptocamp.ch) +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + "name": "Auth SAML environement", + "summary": "Allows system administrator to authenticate with any account", + "version": "14.0.1.0.0", + "category": "base", + "author": "Camptocamp SA,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/server-env", + "license": "AGPL-3", + "depends": [ + "auth_saml", + "server_environment", + ], + "data": [ + "views/saml_provider_view.xml", + ], + "installable": True, +} diff --git a/auth_saml_environment/controllers/__init__.py b/auth_saml_environment/controllers/__init__.py new file mode 100644 index 0000000..12a7e52 --- /dev/null +++ b/auth_saml_environment/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/auth_saml_environment/controllers/main.py b/auth_saml_environment/controllers/main.py new file mode 100644 index 0000000..3bed7b2 --- /dev/null +++ b/auth_saml_environment/controllers/main.py @@ -0,0 +1,16 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +from odoo.addons.auth_saml.controllers.main import SAMLLogin + + +class SAMLLoginEnv(SAMLLogin): + def _list_saml_providers_domain(self): + """OVERWRITE domain to return all active IDP + + The configuration of an IDP doesn't rely anymore on + sp_pem_public and sp_pem_private as those could be + set through sp_pem_private_path and sp_pem_public_path. + + Keeping it simple by relying only on the active field. + """ + return [] diff --git a/auth_saml_environment/models/__init__.py b/auth_saml_environment/models/__init__.py new file mode 100644 index 0000000..d7324d4 --- /dev/null +++ b/auth_saml_environment/models/__init__.py @@ -0,0 +1 @@ +from . import auth_saml_provider diff --git a/auth_saml_environment/models/auth_saml_provider.py b/auth_saml_environment/models/auth_saml_provider.py new file mode 100644 index 0000000..88883b3 --- /dev/null +++ b/auth_saml_environment/models/auth_saml_provider.py @@ -0,0 +1,44 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import api, fields, models + + +class AuthSamlProvider(models.Model): + _name = "auth.saml.provider" + _inherit = ["auth.saml.provider", "server.env.mixin"] + + sp_pem_public_path = fields.Char( + string="sp_pem_public_path env config value", + ) + + sp_pem_private_path = fields.Char( + string="sp_pem_private_path env config value", + ) + + @property + def _server_env_fields(self): + base_fields = super()._server_env_fields + auth_saml_fields = { + "idp_metadata": {}, + "sp_baseurl": {}, + "sp_pem_public_path": {}, + "sp_pem_private_path": {}, + } + auth_saml_fields.update(base_fields) + return auth_saml_fields + + @api.model + def _server_env_global_section_name(self): + """Name of the global section in the configuration files + Can be customized in your model + """ + return "auth_saml_provider" + + def _get_cert_key_path(self, field="sp_pem_public"): + # If the setup is done in env, we want to bypass the base method + if self.sp_pem_public_path and field == "sp_pem_public": + return self.sp_pem_public_path + if self.sp_pem_private_path and field == "sp_pem_private": + return self.sp_pem_private_path + return super()._get_cert_key_path(field) diff --git a/auth_saml_environment/readme/CONFIGURE.rst b/auth_saml_environment/readme/CONFIGURE.rst new file mode 100644 index 0000000..d21de60 --- /dev/null +++ b/auth_saml_environment/readme/CONFIGURE.rst @@ -0,0 +1,18 @@ +To configure this module, you need to: + +Create a module server_environment_file with a cfg file or set the environment variable +SERVER_ENV_CONFIG with the following section: + +[auth_saml_provider.] + +Where is optional and must be equal to the name field you defined in Odoo for the IDP. + + +Example of configuration + +[auth_saml_provider.my_idp] + +idp_metadata=<...> +sp_baseurl=https://odoo-community.org +sp_pem_public_path=/data/cert.pem +sp_pem_private_path=/data/key.pem diff --git a/auth_saml_environment/readme/CONTRIBUTORS.rst b/auth_saml_environment/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..99bb39f --- /dev/null +++ b/auth_saml_environment/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Denis Leemann +* Yannick Vaucher diff --git a/auth_saml_environment/readme/DESCRIPTION.rst b/auth_saml_environment/readme/DESCRIPTION.rst new file mode 100644 index 0000000..8c7db20 --- /dev/null +++ b/auth_saml_environment/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to use server env for SAML configuration diff --git a/auth_saml_environment/readme/INSTALL.rst b/auth_saml_environment/readme/INSTALL.rst new file mode 100644 index 0000000..8e5864e --- /dev/null +++ b/auth_saml_environment/readme/INSTALL.rst @@ -0,0 +1,2 @@ +To install this module, you need to have the following modules installed and +properly configured: `server_environment module` `auth_saml` diff --git a/auth_saml_environment/readme/ROADMAP.rst b/auth_saml_environment/readme/ROADMAP.rst new file mode 100644 index 0000000..647e064 --- /dev/null +++ b/auth_saml_environment/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* Due to the special nature of this addon, you cannot test it on the OCA + runbot. diff --git a/auth_saml_environment/readme/USAGE.rst b/auth_saml_environment/readme/USAGE.rst new file mode 100644 index 0000000..dc77d18 --- /dev/null +++ b/auth_saml_environment/readme/USAGE.rst @@ -0,0 +1,6 @@ +Once configured, Odoo will read the Auth SAML Providers values from the +configuration. + +Note that visibility of login button for SAML is changed and differs from `auth_saml` module, +instead of relying on which fields are filled or not, all providers will be displayed as long +as their configuration in Odoo are set to active. diff --git a/auth_saml_environment/static/description/index.html b/auth_saml_environment/static/description/index.html new file mode 100644 index 0000000..bb1d9ef --- /dev/null +++ b/auth_saml_environment/static/description/index.html @@ -0,0 +1,448 @@ + + + + + + +Auth SAML environement + + + +
+

Auth SAML environement

+ + +

Beta License: AGPL-3 OCA/server-env Translate me on Weblate Try me on Runbot

+

This module allows to use server env for saml configuration

+

Table of contents

+ +
+

Installation

+

To install this module, you need to have the following modules installed and +properly configured: server_environment module auth_saml

+
+
+

Configuration

+

To configure this module, you need to:

+

TODO

+

Example of configuration

+

TODO

+
+
+

Usage

+

Once configured, Odoo will read the Auth SAML Providers values from the +configuration.

+
+
+

Known issues / Roadmap

+
    +
  • Due to the special nature of this addon, you cannot test it on the OCA +runbot.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp SA
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-env project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/auth_saml_environment/tests/__init__.py b/auth_saml_environment/tests/__init__.py new file mode 100644 index 0000000..120bcdf --- /dev/null +++ b/auth_saml_environment/tests/__init__.py @@ -0,0 +1 @@ +from . import test_environment_variable diff --git a/auth_saml_environment/tests/test_environment_variable.py b/auth_saml_environment/tests/test_environment_variable.py new file mode 100644 index 0000000..12600d2 --- /dev/null +++ b/auth_saml_environment/tests/test_environment_variable.py @@ -0,0 +1,35 @@ +# Copyright 2021 Camptocamp (https://www.camptocamp.com). +# License GPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from unittest.mock import patch + +from odoo.tools.config import config as odoo_config + +from odoo.addons.server_environment import server_env +from odoo.addons.server_environment.tests.common import ServerEnvironmentCase + + +@patch.dict(odoo_config.options, {"running_env": "testing"}) +class TestEnvironmentVariables(ServerEnvironmentCase): + def test_env_variables(self): + env_var = ( + "[auth_saml_provider.sample]\n" + "idp_metadata=foo\n" + "sp_baseurl=bar\n" + "sp_pem_public_path=file1.txt\n" + "sp_pem_private_path=file2.txt" + ) + with self.set_config_dir(None), self.set_env_variables(env_var): + parser = server_env._load_config() + self.assertEqual( + list(parser.keys()), ["DEFAULT", "auth_saml_provider.sample"] + ) + self.assertDictEqual( + dict(parser["auth_saml_provider.sample"].items()), + { + "idp_metadata": "foo", + "sp_baseurl": "bar", + "sp_pem_public_path": "file1.txt", + "sp_pem_private_path": "file2.txt", + }, + ) diff --git a/auth_saml_environment/views/saml_provider_view.xml b/auth_saml_environment/views/saml_provider_view.xml new file mode 100644 index 0000000..4c47d92 --- /dev/null +++ b/auth_saml_environment/views/saml_provider_view.xml @@ -0,0 +1,26 @@ + + + + + auth.saml.provider.form + auth.saml.provider + + + + + + + + + + + 1 + + + 1 + + + + + + diff --git a/oca_dependencies.txt b/oca_dependencies.txt index ca3c726..3f3feb5 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,2 @@ # See https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#oca_dependencies-txt +server-auth diff --git a/setup/auth_saml_environment/odoo/addons/auth_saml_environment b/setup/auth_saml_environment/odoo/addons/auth_saml_environment new file mode 120000 index 0000000..0c7e9ca --- /dev/null +++ b/setup/auth_saml_environment/odoo/addons/auth_saml_environment @@ -0,0 +1 @@ +../../../../auth_saml_environment \ No newline at end of file diff --git a/setup/auth_saml_environment/setup.py b/setup/auth_saml_environment/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/auth_saml_environment/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)