Projet

Général

Profil

0003-misc-apply-isort-52457.patch

Valentin Deniaud, 30 mars 2021 11:39

Télécharger (275 ko)

Voir les différences:

Subject: [PATCH 3/6] misc: apply isort (#52457)

 authentic2-ctl                                |   1 +
 debian/debian_config.py                       |   2 +
 debian/multitenant/debian_config.py           |   1 +
 doc/conf.py                                   |   3 +-
 merge-coverage.py                             |   8 +-
 setup.py                                      |  10 +-
 src/authentic2/__init__.py                    |   3 +-
 src/authentic2/a2_rbac/admin.py               |   2 +-
 src/authentic2/a2_rbac/apps.py                |   6 +-
 src/authentic2/a2_rbac/fields.py              |   2 +-
 src/authentic2/a2_rbac/management.py          |  11 +-
 src/authentic2/a2_rbac/managers.py            |   5 +-
 .../a2_rbac/migrations/0001_initial.py        |   7 +-
 .../migrations/0002_role_external_id.py       |   2 +-
 ...3_partial_unique_index_on_name_and_slug.py |   3 +-
 .../migrations/0004_auto_20150523_0028.py     |   2 +-
 .../migrations/0005_auto_20150526_1406.py     |   2 +-
 .../migrations/0006_auto_20150619_1056.py     |   2 +-
 .../migrations/0007_auto_20150708_1337.py     |   2 +-
 .../migrations/0008_auto_20150810_1953.py     |   2 +-
 ...0009_partial_unique_index_on_permission.py |   3 +-
 .../migrations/0010_auto_20160209_1417.py     |   1 +
 .../migrations/0011_auto_20160209_1511.py     |   2 +-
 ...nizationalunit_user_add_password_policy.py |   2 +-
 .../0020_partial_unique_index_on_name.py      |   3 +-
 .../migrations/0021_auto_20200317_1514.py     |   1 +
 src/authentic2/a2_rbac/models.py              |  23 +--
 src/authentic2/a2_rbac/signal_handlers.py     |  19 +--
 src/authentic2/a2_rbac/utils.py               |   2 +-
 src/authentic2/admin.py                       |  22 +--
 src/authentic2/api_mixins.py                  |   4 +-
 src/authentic2/api_views.py                   |  67 ++++-----
 src/authentic2/app_settings.py                |   4 +-
 src/authentic2/apps/journal/admin.py          |   2 +-
 src/authentic2/apps/journal/forms.py          |   2 +-
 .../apps/journal/migrations/0001_initial.py   |   4 +-
 src/authentic2/apps/journal/models.py         |  10 +-
 src/authentic2/apps/journal/search_engine.py  |   2 +-
 src/authentic2/apps/journal/sql.py            |   2 +-
 src/authentic2/apps/journal/utils.py          |   4 +-
 src/authentic2/apps/journal/views.py          |   2 +-
 .../migrations/0001_initial.py                |   2 +-
 .../migrations/0002_auto_20150409_1840.py     |   2 +-
 .../migrations/0003_auto_20150526_2239.py     |   2 +-
 .../migrations/0004_auto_20150915_2041.py     |   2 +-
 src/authentic2/attribute_kinds.py             |  21 ++-
 src/authentic2/attributes_ng/engine.py        |   2 +-
 .../attributes_ng/sources/django_user.py      |   3 +-
 .../attributes_ng/sources/format.py           |   1 -
 src/authentic2/attributes_ng/sources/ldap.py  |   4 +-
 .../attributes_ng/sources/service_roles.py    |   2 +-
 .../auth2_ssl/migrations/0001_initial.py      |   2 +-
 .../migrations/0002_auto_20150409_1840.py     |   2 +-
 .../auth_migrations_18/0001_initial.py        |   2 +-
 .../0002_auto_20150323_1720.py                |   2 +-
 .../auth_migrations_18/0004_user.py           |   4 +-
 .../0005_auto_20150526_2303.py                |   4 +-
 src/authentic2/authentication.py              |   6 +-
 src/authentic2/authenticators.py              |  13 +-
 src/authentic2/backends/__init__.py           |   1 +
 src/authentic2/backends/ldap_backend.py       |  40 +++---
 src/authentic2/backends/models_backend.py     |   8 +-
 src/authentic2/cbv.py                         |  11 +-
 src/authentic2/compat/drf.py                  |   2 +-
 src/authentic2/compat/misc.py                 |   2 +-
 src/authentic2/context_processors.py          |   4 +-
 src/authentic2/cors.py                        |   4 +-
 src/authentic2/crypto.py                      |   6 +-
 src/authentic2/csv_import.py                  |  11 +-
 src/authentic2/custom_user/apps.py            |   9 +-
 .../management/commands/changepassword.py     |   6 +-
 .../management/commands/fix-attributes.py     |   2 +-
 src/authentic2/custom_user/managers.py        |  15 +-
 .../custom_user/migrations/0001_initial.py    |   3 +-
 .../migrations/0002_auto_20150410_1823.py     |   2 +-
 .../migrations/0003_auto_20150504_1410.py     |   2 +-
 .../custom_user/migrations/0004_user_ou.py    |   2 +-
 .../migrations/0005_auto_20150522_1527.py     |   2 +-
 .../migrations/0006_auto_20150527_1212.py     |   2 +-
 .../migrations/0007_auto_20150610_1527.py     |   2 +-
 .../migrations/0008_auto_20150617_1606.py     |   2 +-
 .../migrations/0009_auto_20150810_1953.py     |   2 +-
 .../migrations/0010_auto_20160307_1418.py     |   2 +-
 .../migrations/0012_user_modified.py          |   3 +-
 .../migrations/0021_set_unusable_password.py  |   3 +-
 .../migrations/0026_remove_user_deleted.py    |   1 +
 src/authentic2/custom_user/models.py          |  17 ++-
 src/authentic2/data_transfer.py               |  16 ++-
 src/authentic2/decorators.py                  |  15 +-
 .../disco_service/disco_responder.py          |   7 +-
 src/authentic2/exponential_retry_timeout.py   |   6 +-
 src/authentic2/forms/authentication.py        |   7 +-
 src/authentic2/forms/fields.py                |  17 ++-
 src/authentic2/forms/honeypot.py              |   2 +-
 src/authentic2/forms/passwords.py             |  12 +-
 src/authentic2/forms/profile.py               |  10 +-
 src/authentic2/forms/registration.py          |  10 +-
 src/authentic2/forms/widgets.py               |  12 +-
 src/authentic2/hashers.py                     |   6 +-
 src/authentic2/idp/migrations/0001_initial.py |   2 +-
 .../idp/migrations/0002_auto_20150526_2239.py |   2 +-
 .../idp/migrations/0003_auto_20150915_2041.py |   2 +-
 src/authentic2/idp/saml/__init__.py           |   4 +-
 src/authentic2/idp/saml/backend.py            |   9 +-
 src/authentic2/idp/saml/common.py             |   6 +-
 src/authentic2/idp/saml/saml2_endpoints.py    | 132 +++++++++---------
 src/authentic2/idp/saml/urls.py               |  17 +--
 src/authentic2/idp/saml/views.py              |   9 +-
 src/authentic2/idp/urls.py                    |   1 +
 src/authentic2/journal.py                     |   3 +-
 src/authentic2/journal_event_types.py         |   5 +-
 src/authentic2/ldap_utils.py                  |   1 -
 src/authentic2/log_filters.py                 |   1 +
 .../management/commands/check-and-repair.py   |   8 +-
 .../commands/clean-unused-accounts.py         |   7 +-
 .../management/commands/import_site.py        |   2 +-
 .../management/commands/load-ldif.py          |  10 +-
 .../management/commands/resetpassword.py      |   3 +-
 .../management/commands/slapd-shell.py        |   8 +-
 src/authentic2/manager/apps.py                |   1 +
 src/authentic2/manager/forms.py               |  40 +++---
 src/authentic2/manager/journal_event_types.py |   4 +-
 src/authentic2/manager/ou_views.py            |   6 +-
 src/authentic2/manager/resources.py           |   3 +-
 src/authentic2/manager/role_views.py          |  27 ++--
 src/authentic2/manager/service_views.py       |   4 +-
 src/authentic2/manager/tables.py              |   8 +-
 src/authentic2/manager/urls.py                |   9 +-
 src/authentic2/manager/user_import.py         |   6 +-
 src/authentic2/manager/user_views.py          | 103 +++++++-------
 src/authentic2/manager/utils.py               |   3 +-
 src/authentic2/manager/views.py               |  49 ++++---
 src/authentic2/manager/widgets.py             |   6 +-
 src/authentic2/managers.py                    |  11 +-
 src/authentic2/middleware.py                  |   7 +-
 src/authentic2/migrations/0001_initial.py     |   2 +-
 .../migrations/0002_auto_20150320_1418.py     |   2 +-
 .../migrations/0003_auto_20150409_1840.py     |   2 +-
 src/authentic2/migrations/0004_service.py     |   2 +-
 src/authentic2/migrations/0005_service_ou.py  |   2 +-
 .../migrations/0006_conditional_slug_index.py |   1 +
 .../migrations/0007_auto_20150523_0028.py     |   2 +-
 .../migrations/0008_auto_20160204_1415.py     |   2 +-
 .../migrations/0009_auto_20160211_2247.py     |   2 +-
 .../0010_attributevalue_multiple.py           |   2 +-
 .../migrations/0011_auto_20160211_2253.py     |   2 +-
 .../migrations/0012_auto_20160211_2255.py     |   2 +-
 .../migrations/0013_auto_20160211_2258.py     |   2 +-
 .../migrations/0015_auto_20160621_1711.py     |   2 +-
 .../migrations/0018_auto_20170524_0842.py     |   2 +-
 .../migrations/0021_attribute_order.py        |   2 +-
 .../migrations/0025_auto_20191009_1047.py     |   2 +-
 src/authentic2/migrations/0026_token.py       |   3 +-
 .../0030_clean_admin_tools_tables.py          |   3 +-
 src/authentic2/models.py                      |  21 ++-
 src/authentic2/natural_key.py                 |   5 +-
 .../nonce/migrations/0001_initial.py          |   2 +-
 src/authentic2/nonce/utils.py                 |   8 +-
 src/authentic2/passwords.py                   |  13 +-
 src/authentic2/plugins.py                     |   3 +-
 src/authentic2/saml/admin.py                  |  22 ++-
 src/authentic2/saml/admin_views.py            |   2 +-
 src/authentic2/saml/common.py                 |  22 ++-
 src/authentic2/saml/fields.py                 |   8 +-
 src/authentic2/saml/forms.py                  |   9 +-
 src/authentic2/saml/lasso_helper.py           |   1 -
 .../saml/management/commands/sync-metadata.py |  19 ++-
 src/authentic2/saml/managers.py               |   8 +-
 .../saml/migrations/0001_initial.py           |   5 +-
 .../migrations/0002_auto_20150320_1245.py     |   2 +-
 src/authentic2/saml/migrations/0003_merge.py  |   2 +-
 .../migrations/0004_auto_20150410_1438.py     |   2 +-
 ...e_liberty_provider_inherit_from_service.py |   2 +-
 .../migrations/0006_restore_foreign_keys.py   |   2 +-
 .../0007_copy_service_ptr_id_to_old_id.py     |   2 +-
 .../migrations/0008_alter_foreign_keys.py     |   2 +-
 src/authentic2/saml/migrations/0009_auto.py   |   2 +-
 src/authentic2/saml/migrations/0010_auto.py   |   2 +-
 src/authentic2/saml/migrations/0011_auto.py   |   2 +-
 .../migrations/0012_auto_20150526_2239.py     |   2 +-
 .../migrations/0013_auto_20150617_1004.py     |   2 +-
 .../migrations/0014_auto_20150617_1216.py     |   2 +-
 .../migrations/0015_auto_20150915_2032.py     |   3 +-
 .../migrations/0016_auto_20150915_2041.py     |   2 +-
 src/authentic2/saml/models.py                 |  23 ++-
 src/authentic2/saml/saml2utils.py             |  11 +-
 src/authentic2/saml/x509utils.py              |   3 +-
 src/authentic2/serializers.py                 |   8 +-
 src/authentic2/settings.py                    |   7 +-
 src/authentic2/urls.py                        |  12 +-
 src/authentic2/user_login_failure.py          |   2 +-
 src/authentic2/utils/__init__.py              |  71 +++++-----
 src/authentic2/utils/evaluate.py              |   6 +-
 src/authentic2/utils/lazy.py                  |   5 +-
 src/authentic2/utils/lookups.py               |   3 +-
 src/authentic2/utils/switch_user.py           |   3 +-
 src/authentic2/utils/template.py              |   4 +-
 src/authentic2/validators.py                  |  10 +-
 src/authentic2/views.py                       |  78 +++++++----
 src/authentic2/wsgi.py                        |   3 +-
 src/authentic2_auth_fc/api_views.py           |   7 +-
 src/authentic2_auth_fc/apps.py                |  12 +-
 src/authentic2_auth_fc/authenticators.py      |   5 +-
 src/authentic2_auth_fc/backends.py            |   6 +-
 .../migrations/0001_initial.py                |   2 +-
 .../migrations/0002_auto_20200416_1439.py     |   2 +-
 src/authentic2_auth_fc/models.py              |  11 +-
 src/authentic2_auth_fc/urls.py                |   2 +-
 src/authentic2_auth_fc/utils.py               |  11 +-
 src/authentic2_auth_fc/views.py               |  33 +++--
 src/authentic2_auth_oidc/admin.py             |   2 +-
 src/authentic2_auth_oidc/apps.py              |   4 +
 src/authentic2_auth_oidc/authenticators.py    |   8 +-
 src/authentic2_auth_oidc/backends.py          |  17 +--
 .../commands/oidc-register-issuer.py          |   6 +-
 .../migrations/0001_initial.py                |   8 +-
 .../migrations/0008_auto_20201102_1142.py     |   2 +-
 src/authentic2_auth_oidc/models.py            |  12 +-
 src/authentic2_auth_oidc/urls.py              |   1 -
 src/authentic2_auth_oidc/utils.py             |  17 +--
 src/authentic2_auth_oidc/views.py             |  15 +-
 src/authentic2_auth_saml/adapters.py          |   9 +-
 src/authentic2_auth_saml/apps.py              |   1 +
 src/authentic2_auth_saml/authenticators.py    |   4 +-
 src/authentic2_auth_saml/urls.py              |   2 +-
 src/authentic2_idp_cas/admin.py               |   3 +-
 src/authentic2_idp_cas/managers.py            |   2 +-
 .../migrations/0001_initial.py                |   3 +-
 .../migrations/0002_auto_20150410_1438.py     |   2 +-
 .../migrations/0003_auto_20150415_2223.py     |   2 +-
 .../migrations/0004_create_services.py        |   2 +-
 .../0005_alter_field_service_ptr.py           |   2 +-
 .../migrations/0006_copy_proxy_m2m.py         |   2 +-
 .../migrations/0007_alter_service.py          |   2 +-
 .../migrations/0008_alter_foreign_keys.py     |   2 +-
 .../migrations/0009_alter_related_models.py   |   2 +-
 .../0010_copy_service_ptr_id_to_old_id.py     |   2 +-
 .../0011_remove_old_id_restore_proxy.py       |   2 +-
 .../0012_copy_service_proxy_to_m2m.py         |   2 +-
 .../0013_delete_model_service_proxy2.py       |   2 +-
 .../migrations/0014_auto_20151204_1606.py     |   2 +-
 src/authentic2_idp_cas/models.py              |   8 +-
 src/authentic2_idp_cas/views.py               |  83 ++++++-----
 src/authentic2_idp_oidc/admin.py              |   3 +-
 src/authentic2_idp_oidc/apps.py               |   7 +-
 .../migrations/0001_initial.py                |   3 +-
 .../migrations/0002_auto_20170121_2346.py     |   1 +
 .../migrations/0003_auto_20170329_1259.py     |   1 +
 .../migrations/0011_auto_20180808_1546.py     |   1 -
 src/authentic2_idp_oidc/models.py             |  15 +-
 src/authentic2_idp_oidc/urls.py               |   1 -
 src/authentic2_idp_oidc/utils.py              |  16 +--
 src/authentic2_idp_oidc/views.py              |  25 ++--
 src/django_rbac/apps.py                       |   3 +-
 src/django_rbac/managers.py                   |   6 +-
 src/django_rbac/migrations/0001_initial.py    |   3 +-
 ...ionalunit_permission_role_roleparenting.py |   2 +-
 .../migrations/0004_auto_20150708_1337.py     |   2 +-
 src/django_rbac/models.py                     |  21 +--
 src/django_rbac/utils.py                      |   2 +-
 tests/auth_fc/conftest.py                     |   4 +-
 tests/auth_fc/test_auth_fc.py                 |   7 +-
 tests/cache_urls.py                           |   2 +-
 tests/conftest.py                             |  31 ++--
 tests/test_a2_rbac.py                         |  23 +--
 tests/test_admin.py                           |   3 +-
 tests/test_all.py                             |  57 ++++----
 tests/test_api.py                             |  22 ++-
 tests/test_attribute_kinds.py                 |   3 +-
 tests/test_auth_oidc.py                       |  39 +++---
 tests/test_auth_saml.py                       |   7 +-
 tests/test_backends.py                        |   2 +-
 tests/test_commands.py                        |  26 ++--
 tests/test_concurrency.py                     |   1 -
 tests/test_crypto.py                          |   3 +-
 tests/test_csv_import.py                      |  21 +--
 tests/test_custom_user.py                     |   5 +-
 tests/test_customfields.py                    |   2 +-
 tests/test_data_transfer.py                   |  15 +-
 tests/test_fields.py                          |   1 -
 tests/test_idp_cas.py                         |   9 +-
 tests/test_idp_oidc.py                        |  44 +++---
 tests/test_idp_saml2.py                       |  29 ++--
 tests/test_import_export_site_cmd.py          |   7 +-
 tests/test_journal.py                         |  10 +-
 tests/test_journal_app/views.py               |   2 +-
 tests/test_large_userbase.py                  |   2 -
 tests/test_ldap.py                            |  25 ++--
 tests/test_login.py                           |   5 +-
 tests/test_manager.py                         |  28 ++--
 tests/test_manager_journal.py                 |  15 +-
 tests/test_manager_user_import.py             |   2 +-
 tests/test_migrations.py                      |   1 -
 tests/test_models.py                          |   2 +-
 tests/test_natural_key.py                     |   5 +-
 tests/test_profile.py                         |   1 -
 tests/test_registration.py                    |   7 +-
 tests/test_role_manager.py                    |   7 +-
 tests/test_saml_x509utils.py                  |   8 +-
 tests/test_template.py                        |   1 -
 tests/test_user_manager.py                    |  24 ++--
 tests/test_user_model.py                      |   6 +-
 tests/test_utils.py                           |  16 +--
 tests/test_utils_evaluate.py                  |   2 +-
 tests/test_utils_lazy.py                      |   1 -
 tests/test_validators.py                      |   3 +-
 tests/test_views.py                           |   7 +-
 tests/test_widgets.py                         |   3 +-
 tests/utils.py                                |  13 +-
 tests_rbac/test_rbac.py                       |   7 +-
 310 files changed, 1307 insertions(+), 1300 deletions(-)
authentic2-ctl
1 1
#!/usr/bin/env python
2 2
import os
3 3
import sys
4

  
4 5
import authentic2.logger
5 6

  
6 7
if __name__ == "__main__":
debian/debian_config.py
1 1
import glob
2 2
import os
3 3
import warnings
4

  
4 5
from authentic2 import logger
5 6

  
6 7
ETC_DIR = '/etc/authentic2/'
......
123 124
# Old settings method
124 125
def extract_settings_from_environ():
125 126
    import json
127

  
126 128
    from django.core.exceptions import ImproperlyConfigured
127 129

  
128 130
    global MANAGERS, DATABASES, SENTRY_TRANSPORT, SENTRY_DSN, INSTALLED_APPS, SECURE_PROXY_SSL_HEADER, CACHES, SESSION_ENGINE, LDAP_AUTH_SETTINGS
debian/multitenant/debian_config.py
1 1
import os
2

  
2 3
from django.utils.translation import ugettext_lazy as _
3 4

  
4 5
# Debian defaults
doc/conf.py
11 11
# All configuration values have a default; values that are commented out
12 12
# serve to show the default.
13 13

  
14
import sys, os
14
import os
15
import sys
15 16

  
16 17
# If extensions (or modules to document with autodoc) are in another directory,
17 18
# add these directories to sys.path here. If the directory is relative to the
merge-coverage.py
1 1
#!/usr/bin/python
2 2
from __future__ import print_function
3 3

  
4
import sys
5
import os
6
import xml.etree.ElementTree as ET
7 4
import logging
5
import os
8 6
import re
9
from shutil import copyfile
7
import sys
8
import xml.etree.ElementTree as ET
10 9
from optparse import OptionParser
10
from shutil import copyfile
11 11

  
12 12
### This file came from the https://github.com/flow123d/flow123d repo they were nice enough to spend time to write this.
13 13
### It is copied here for other people to use on its own.
setup.py
4 4
   Setup script for Authentic 2
5 5
'''
6 6

  
7
import glob
8
import os
7 9
import subprocess
8 10
import sys
9
import os
10
import glob
11
from distutils.cmd import Command
12
from distutils.command.build import build as _build
11 13

  
12
from setuptools import setup, find_packages
14
from setuptools import find_packages, setup
13 15
from setuptools.command.install_lib import install_lib as _install_lib
14 16
from setuptools.command.sdist import sdist as _sdist
15
from distutils.command.build import build as _build
16
from distutils.cmd import Command
17 17

  
18 18

  
19 19
class compile_translations(Command):
src/authentic2/__init__.py
19 19
default_app_config = 'authentic2.app.Authentic2Config'
20 20

  
21 21
if django.VERSION < (2,):
22
    from . import validators
23 22
    from django.forms import fields
24 23

  
24
    from . import validators
25

  
25 26
    # query-string and form parameters used to query database charfield must be checked for NULL characters
26 27
    # https://code.djangoproject.com/ticket/30064
27 28
    if not getattr(fields.CharField, 'a2_workaround', False):
src/authentic2/a2_rbac/admin.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.contrib import admin
18
from django.utils.translation import ugettext_lazy as _
19 18
from django.utils import six
19
from django.utils.translation import ugettext_lazy as _
20 20

  
21 21
from . import models
22 22

  
src/authentic2/a2_rbac/apps.py
22 22
    verbose_name = 'Authentic2 RBAC'
23 23

  
24 24
    def ready(self):
25
        from . import signal_handlers, models
26
        from django.db.models.signals import post_save, post_migrate, post_delete
25
        from django.db.models.signals import post_delete, post_migrate, post_save
26

  
27 27
        from authentic2.models import Service
28 28

  
29
        from . import models, signal_handlers
30

  
29 31
        # update rbac on save to contenttype, ou and roles
30 32
        post_save.connect(signal_handlers.update_rbac_on_ou_post_save, sender=models.OrganizationalUnit)
31 33
        post_delete.connect(signal_handlers.update_rbac_on_ou_post_delete, sender=models.OrganizationalUnit)
src/authentic2/a2_rbac/fields.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.db.models import NullBooleanField
18 17
from django import forms
18
from django.db.models import NullBooleanField
19 19

  
20 20

  
21 21
class UniqueBooleanField(NullBooleanField):
src/authentic2/a2_rbac/management.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.contrib.contenttypes.models import ContentType
17 18
from django.utils import six
18
from django.utils.translation import ugettext_lazy as _, ugettext
19 19
from django.utils.text import slugify
20
from django.contrib.contenttypes.models import ContentType
20
from django.utils.translation import ugettext
21
from django.utils.translation import ugettext_lazy as _
21 22

  
22 23
from django_rbac.models import ADMIN_OP
23
from django_rbac.utils import get_ou_model
24
from django_rbac.utils import get_permission_model
25
from django_rbac.utils import get_role_model
24
from django_rbac.utils import get_ou_model, get_permission_model, get_role_model
26 25

  
27 26
from ..utils import get_fk_model
28
from . import utils, app_settings
27
from . import app_settings, utils
29 28
from .models import MANAGE_MEMBERS_OP
30 29

  
31 30

  
src/authentic2/a2_rbac/managers.py
16 16

  
17 17
from django.contrib.contenttypes.models import ContentType
18 18

  
19
from django_rbac import utils as rbac_utils
20
from django_rbac.managers import AbstractBaseManager
21
from django_rbac.managers import RoleManager as BaseRoleManager
19 22
from django_rbac.models import ADMIN_OP
20
from django_rbac.managers import RoleManager as BaseRoleManager, AbstractBaseManager
21 23
from django_rbac.utils import get_operation
22
from django_rbac import utils as rbac_utils
23 24

  
24 25

  
25 26
class OrganizationalUnitManager(AbstractBaseManager):
src/authentic2/a2_rbac/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5
import authentic2.utils
6
import authentic2.a2_rbac.fields
7 4
from django.conf import settings
5
from django.db import migrations, models
6

  
7
import authentic2.a2_rbac.fields
8
import authentic2.utils
8 9

  
9 10

  
10 11
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0002_role_external_id.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0003_partial_unique_index_on_name_and_slug.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5

  
5 6
from authentic2.migrations import CreatePartialIndexes
6 7

  
7 8

  
src/authentic2/a2_rbac/migrations/0004_auto_20150523_0028.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0005_auto_20150526_1406.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0006_auto_20150619_1056.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0007_auto_20150708_1337.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0008_auto_20150810_1953.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0009_partial_unique_index_on_permission.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5

  
5 6
from authentic2.migrations import CreatePartialIndexes
6 7

  
7 8

  
src/authentic2/a2_rbac/migrations/0010_auto_20160209_1417.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3

  
3 4
from collections import defaultdict
4 5

  
5 6
from django.db import migrations
src/authentic2/a2_rbac/migrations/0011_auto_20160209_1511.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0018_organizationalunit_user_add_password_policy.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/a2_rbac/migrations/0020_partial_unique_index_on_name.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5

  
5 6
from authentic2.migrations import CreatePartialIndexes
6 7

  
7 8

  
src/authentic2/a2_rbac/migrations/0021_auto_20200317_1514.py
3 3
from __future__ import unicode_literals
4 4

  
5 5
from django.db import migrations, models
6

  
6 7
import django_rbac.utils
7 8

  
8 9

  
src/authentic2/a2_rbac/models.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from collections import namedtuple
18

  
19
from django.contrib.contenttypes.models import ContentType
18 20
from django.core.exceptions import ValidationError
19 21
from django.core.validators import MinValueValidator
22
from django.db import models
20 23
from django.utils import six
21
from django.utils.translation import ugettext_lazy as _, pgettext_lazy
22 24
from django.utils.text import slugify
23
from django.db import models
24
from django.contrib.contenttypes.models import ContentType
25
from django.utils.translation import pgettext_lazy
26
from django.utils.translation import ugettext_lazy as _
25 27

  
28
from authentic2.decorators import errorcollector
29
from django_rbac import utils as rbac_utils
26 30
from django_rbac.models import (
27
    RoleAbstractBase,
28
    PermissionAbstractBase,
29
    OrganizationalUnitAbstractBase,
30
    RoleParentingAbstractBase,
31 31
    VIEW_OP,
32 32
    Operation,
33
    OrganizationalUnitAbstractBase,
34
    PermissionAbstractBase,
35
    RoleAbstractBase,
36
    RoleParentingAbstractBase,
33 37
)
34
from django_rbac import utils as rbac_utils
35

  
36
from authentic2.decorators import errorcollector
37 38

  
38 39
try:
39 40
    from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
......
43 44

  
44 45
from authentic2.decorators import GlobalCache
45 46

  
46
from . import managers, fields, app_settings
47
from . import app_settings, fields, managers
47 48

  
48 49

  
49 50
class OrganizationalUnit(OrganizationalUnitAbstractBase):
src/authentic2/a2_rbac/signal_handlers.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.utils.translation import ugettext as _
18
from django.conf import settings
19 17
from django.apps import apps
20
from django.utils.translation import override
18
from django.conf import settings
21 19
from django.db import DEFAULT_DB_ALIAS, router, transaction
20
from django.utils.translation import override
21
from django.utils.translation import ugettext as _
22 22

  
23
from ..utils import get_fk_model
24
from django_rbac.utils import get_ou_model, get_role_model, get_operation
25 23
from django_rbac.managers import defer_update_transitive_closure
24
from django_rbac.utils import get_operation, get_ou_model, get_role_model
25

  
26
from ..utils import get_fk_model
26 27

  
27 28

  
28 29
def create_default_ou(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
......
52 53

  
53 54
def post_migrate_update_rbac(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
54 55
    # be sure new objects names are localized using the default locale
55
    from .management import update_ous_admin_roles, update_content_types_roles
56
    from .management import update_content_types_roles, update_ous_admin_roles
56 57

  
57 58
    if not router.allow_migrate(using, get_role_model()):
58 59
        return
......
85 86

  
86 87
def create_default_permissions(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
87 88
    from .models import (
88
        CHANGE_PASSWORD_OP,
89
        RESET_PASSWORD_OP,
90 89
        ACTIVATE_OP,
91 90
        CHANGE_EMAIL_OP,
92
        MANAGE_MEMBERS_OP,
91
        CHANGE_PASSWORD_OP,
93 92
        MANAGE_AUTHORIZATIONS_OP,
93
        MANAGE_MEMBERS_OP,
94
        RESET_PASSWORD_OP,
94 95
    )
95 96

  
96 97
    if not router.allow_migrate(using, get_ou_model()):
src/authentic2/a2_rbac/utils.py
16 16

  
17 17
from django.contrib.auth import get_user_model
18 18
from django.contrib.contenttypes.models import ContentType
19
from django_rbac.models import VIEW_OP, SEARCH_OP
20 19

  
21 20
from django_rbac import utils as rbac_utils
21
from django_rbac.models import SEARCH_OP, VIEW_OP
22 22

  
23 23
from . import models
24 24

  
src/authentic2/admin.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from copy import deepcopy
18 17
import pprint
18
from copy import deepcopy
19 19

  
20
from django.contrib import admin
20
from django import forms
21 21
from django.conf import settings
22
from django.utils.translation import ugettext_lazy as _
23
from django.utils import timezone
24
from django.views.decorators.cache import never_cache
22
from django.contrib import admin
23
from django.contrib.admin.utils import flatten_fieldsets
25 24
from django.contrib.auth.admin import UserAdmin
25
from django.contrib.auth.forms import ReadOnlyPasswordHashField
26 26
from django.contrib.sessions.models import Session
27
from django.contrib.admin.utils import flatten_fieldsets
28 27
from django.db import transaction
29
from django import forms
30
from django.contrib.auth.forms import ReadOnlyPasswordHashField
28
from django.utils import timezone
29
from django.utils.translation import ugettext_lazy as _
30
from django.views.decorators.cache import never_cache
31 31

  
32
from .nonce.models import Nonce
33
from . import models, app_settings, decorators, attribute_kinds, utils
32
from . import app_settings, attribute_kinds, decorators, models, utils
33
from .custom_user.models import DeletedUser, User
34 34
from .forms.profile import BaseUserForm, modelform_factory
35
from .custom_user.models import User, DeletedUser
35
from .nonce.models import Nonce
36 36

  
37 37

  
38 38
def cleanup_action(modeladmin, request, queryset):
src/authentic2/api_mixins.py
16 16

  
17 17
from django.db import transaction
18 18
from django.utils.translation import ugettext_lazy as _
19

  
20 19
from rest_framework import status
20
from rest_framework.exceptions import APIException, ValidationError
21 21
from rest_framework.settings import api_settings
22
from rest_framework.exceptions import APIException
23
from rest_framework.exceptions import ValidationError
24 22
from rest_framework.utils import model_meta
25 23

  
26 24

  
src/authentic2/api_views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from functools import partial
18 17
import logging
19 18
import smtplib
19
from functools import partial
20 20

  
21
from pytz.exceptions import AmbiguousTimeError
22 21
import django
23
from django.db import models
22
import requests
24 23
from django.conf import settings
25 24
from django.contrib.auth import get_user_model
26 25
from django.contrib.auth.hashers import identify_hasher
27 26
from django.core.exceptions import MultipleObjectsReturned
28
from django.utils.translation import ugettext as _
29
from django.utils.text import slugify
30
from django.utils.encoding import force_text
27
from django.db import models
28
from django.shortcuts import get_object_or_404
31 29
from django.utils.dateparse import parse_datetime
30
from django.utils.encoding import force_text
31
from django.utils.text import slugify
32
from django.utils.translation import ugettext as _
32 33
from django.utils.translation import ugettext_lazy as _
33
from django.views.decorators.vary import vary_on_headers
34 34
from django.views.decorators.cache import cache_control
35
from django.shortcuts import get_object_or_404
36

  
37
from django_rbac.utils import get_ou_model, get_role_model
38
import requests
35
from django.views.decorators.vary import vary_on_headers
36
from django_filters.fields import IsoDateTimeField
37
from django_filters.filters import IsoDateTimeFilter
38
from django_filters.rest_framework import FilterSet
39
from django_filters.utils import handle_timezone
40
from pytz.exceptions import AmbiguousTimeError
39 41
from requests.exceptions import RequestException
40

  
41
from rest_framework import serializers, pagination, VERSION as drf_version
42
from rest_framework.validators import UniqueTogetherValidator
43
from rest_framework.views import APIView
44
from rest_framework.viewsets import ModelViewSet, ViewSet
45
from rest_framework.routers import SimpleRouter
46
from rest_framework.generics import GenericAPIView
47
from rest_framework.response import Response
48
from rest_framework import permissions, status, authentication
49
from rest_framework.exceptions import PermissionDenied, AuthenticationFailed, ValidationError, NotFound
50
from rest_framework.fields import CreateOnlyDefault
51
from authentic2.compat.drf import action
42
from rest_framework import VERSION as drf_version
43
from rest_framework import authentication, pagination, permissions, serializers, status
52 44
from rest_framework.authentication import SessionAuthentication
45
from rest_framework.exceptions import (
46
    AuthenticationFailed,
47
    NotFound,
48
    PermissionDenied,
49
    ValidationError,
50
)
51
from rest_framework.fields import CreateOnlyDefault
53 52
from rest_framework.filters import BaseFilterBackend
53
from rest_framework.generics import GenericAPIView
54
from rest_framework.response import Response
55
from rest_framework.routers import SimpleRouter
54 56
from rest_framework.settings import api_settings
57
from rest_framework.validators import UniqueTogetherValidator
58
from rest_framework.views import APIView
59
from rest_framework.viewsets import ModelViewSet, ViewSet
55 60

  
56
from django_filters.rest_framework import FilterSet
57
from django_filters.filters import IsoDateTimeFilter
58
from django_filters.fields import IsoDateTimeField
59
from django_filters.utils import handle_timezone
61
from authentic2.compat.drf import action
62
from django_rbac.utils import get_ou_model, get_role_model
60 63

  
61
from .passwords import get_password_checker
62
from .custom_user.models import User
63
from . import utils, decorators, attribute_kinds, app_settings, hooks, api_mixins
64
from .models import Attribute, PasswordReset, Service
64
from . import api_mixins, app_settings, attribute_kinds, decorators, hooks, utils
65 65
from .a2_rbac.utils import get_default_ou
66
from .custom_user.models import User
66 67
from .journal_event_types import UserLogin, UserRegistration
68
from .models import Attribute, PasswordReset, Service
69
from .passwords import get_password_checker
67 70
from .utils.lookups import Unaccent
68 71

  
69

  
70 72
# Retro-compatibility with older Django versions
71 73
if django.VERSION < (2,):
72 74
    import rest_framework.fields
75

  
73 76
    from . import validators
74 77

  
75 78
    rest_framework.fields.ProhibitNullCharactersValidator = validators.ProhibitNullCharactersValidator
src/authentic2/app_settings.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import sys
18
import six
19 18

  
20
from django.utils.translation import ugettext_lazy as _
19
import six
21 20
from django.core.exceptions import ImproperlyConfigured
21
from django.utils.translation import ugettext_lazy as _
22 22

  
23 23

  
24 24
class Setting(object):
src/authentic2/apps/journal/admin.py
19 19
from django.contrib import admin
20 20
from django.utils.html import format_html
21 21

  
22
from .models import EventType, Event
22
from .models import Event, EventType
23 23

  
24 24

  
25 25
class EventTypeAdmin(admin.ModelAdmin):
src/authentic2/apps/journal/forms.py
16 16

  
17 17
from datetime import datetime
18 18

  
19
from django import forms
19 20
from django.http import QueryDict
20 21
from django.utils.formats import date_format
21 22
from django.utils.functional import cached_property
22 23
from django.utils.translation import ugettext_lazy as _
23
from django import forms
24 24

  
25 25
from . import models, search_engine
26 26

  
src/authentic2/apps/journal/migrations/0001_initial.py
1 1
# Generated by Django 2.2.15 on 2020-08-23 16:56
2 2

  
3
from django.conf import settings
4 3
import django.contrib.postgres.fields
5 4
import django.contrib.postgres.fields.jsonb
6
from django.db import migrations, models
7 5
import django.db.models.deletion
6
from django.conf import settings
7
from django.db import migrations, models
8 8
from django.utils import timezone
9 9

  
10 10

  
src/authentic2/apps/journal/models.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import logging
18
import re
17 19
from collections import defaultdict
18 20
from contextlib import contextmanager
19 21
from datetime import datetime, timedelta
20
import logging
21
import re
22 22

  
23 23
from django.conf import settings
24 24
from django.contrib.auth import get_user_model
25
from django.contrib.contenttypes.models import ContentType
25 26
from django.contrib.postgres.fields import ArrayField, JSONField
26 27
from django.contrib.postgres.fields.jsonb import KeyTextTransform
27
from django.contrib.contenttypes.models import ContentType
28 28
from django.core.exceptions import ObjectDoesNotExist
29 29
from django.db import models
30
from django.db.models import QuerySet, Q, F, Value, Count
30
from django.db.models import Count, F, Q, QuerySet, Value
31 31
from django.db.models.functions import Trunc
32
from django.utils.timezone import now, utc
32 33
from django.utils.translation import ugettext_lazy as _
33
from django.utils.timezone import utc, now
34 34

  
35 35
from authentic2.decorators import GlobalCache
36 36

  
src/authentic2/apps/journal/search_engine.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from functools import reduce
18 17
import re
18
from functools import reduce
19 19

  
20 20
from django.contrib.auth import get_user_model
21 21
from django.db.models import Q
src/authentic2/apps/journal/sql.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.db.models import Func, Subquery
18 17
from django.contrib.postgres.fields import ArrayField
18
from django.db.models import Func, Subquery
19 19

  
20 20

  
21 21
class ArraySubquery(Func):
src/authentic2/apps/journal/utils.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from datetime import timedelta, date
17
from datetime import date, timedelta
18 18

  
19
from django.db.models import Min, Max, DateField
19
from django.db.models import DateField, Max, Min
20 20

  
21 21

  
22 22
def _json_value(value):
src/authentic2/apps/journal/views.py
17 17
from django.views.generic import TemplateView
18 18
from django.views.generic.edit import FormMixin
19 19

  
20
from . import models, forms
20
from . import forms, models
21 21

  
22 22

  
23 23
class JournalView(FormMixin, TemplateView):
src/authentic2/attribute_aggregator/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/attribute_aggregator/migrations/0002_auto_20150409_1840.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/attribute_aggregator/migrations/0003_auto_20150526_2239.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/attribute_aggregator/migrations/0004_auto_20150915_2041.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/attribute_kinds.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import re
18
import string
19 17
import datetime
20 18
import hashlib
21 19
import os
22

  
20
import re
21
import string
23 22
from itertools import chain
24 23

  
25 24
from django import forms
26 25
from django.conf import settings
27 26
from django.core.exceptions import ValidationError
28
from django.core.validators import RegexValidator
29
from django.urls import reverse
30
from django.utils import six, formats
31
from django.utils.translation import ugettext_lazy as _, pgettext_lazy
32
from django.utils import html
33 27
from django.core.files.storage import default_storage
28
from django.core.validators import RegexValidator
34 29
from django.db.models import query
35

  
30
from django.urls import reverse
31
from django.utils import formats, html, six
36 32
from django.utils.functional import keep_lazy
37

  
33
from django.utils.translation import pgettext_lazy
34
from django.utils.translation import ugettext_lazy as _
38 35
from gadjo.templatetags.gadjo import xstatic
39 36
from rest_framework import serializers
40 37
from rest_framework.fields import empty
41 38

  
39
from . import app_settings
42 40
from .decorators import to_iter
41
from .forms import fields, widgets
43 42
from .plugins import collect_from_plugins
44
from . import app_settings
45
from .forms import widgets, fields
46 43

  
47 44

  
48 45
@keep_lazy(six.text_type)
src/authentic2/attributes_ng/engine.py
18 18

  
19 19
from django.utils.translation import ugettext as _
20 20

  
21
from ..decorators import to_iter, to_list
22 21
from .. import app_settings, plugins, utils
22
from ..decorators import to_iter, to_list
23 23

  
24 24
__ALL__ = ['get_attribute_names', 'get_attributes', 'get_service_attributes']
25 25

  
src/authentic2/attributes_ng/sources/django_user.py
20 20

  
21 21
from django_rbac.utils import get_role_model
22 22

  
23
from ...models import Attribute, AttributeValue
24

  
25 23
from ...decorators import to_list
24
from ...models import Attribute, AttributeValue
26 25

  
27 26

  
28 27
@to_list
src/authentic2/attributes_ng/sources/format.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import six
18

  
19 18
from django.core.exceptions import ImproperlyConfigured
20 19

  
21 20
from ...decorators import to_list
src/authentic2/attributes_ng/sources/ldap.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from ...decorators import to_list
18

  
19 17
from authentic2.backends.ldap_backend import LDAPBackend, LDAPUser
20 18

  
19
from ...decorators import to_list
20

  
21 21

  
22 22
@to_list
23 23
def get_instances(ctx):
src/authentic2/attributes_ng/sources/service_roles.py
16 16

  
17 17
from django.utils.translation import ugettext_lazy as _
18 18

  
19
from ...models import Service
20 19
from authentic2.a2_rbac.models import Role
21 20

  
22 21
from ...decorators import to_list
22
from ...models import Service
23 23

  
24 24

  
25 25
@to_list
src/authentic2/auth2_auth/auth2_ssl/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/auth2_auth/auth2_ssl/migrations/0002_auto_20150409_1840.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/auth_migrations_18/0001_initial.py
2 2
from __future__ import unicode_literals
3 3

  
4 4
from django.core import validators
5
from django.db import models, migrations
5
from django.db import migrations, models
6 6
from django.utils import timezone
7 7

  
8 8

  
src/authentic2/auth_migrations_18/0002_auto_20150323_1720.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
import django.core.validators
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/auth_migrations_18/0004_user.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5
import django.utils.timezone
6 4
import django.core.validators
5
import django.utils.timezone
6
from django.db import migrations, models
7 7

  
8 8

  
9 9
class Migration(migrations.Migration):
src/authentic2/auth_migrations_18/0005_auto_20150526_2303.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5
import django.core.validators
6 4
import django.contrib.auth.models
5
import django.core.validators
6
from django.db import migrations, models
7 7

  
8 8

  
9 9
class Migration(migrations.Migration):
src/authentic2/authentication.py
23 23
except ImportError:
24 24
    CallableTrue = True
25 25

  
26
from authentic2_idp_oidc.models import OIDCClient
27

  
28
from rest_framework.exceptions import AuthenticationFailed
29 26
from rest_framework.authentication import BasicAuthentication
27
from rest_framework.exceptions import AuthenticationFailed
28

  
29
from authentic2_idp_oidc.models import OIDCClient
30 30

  
31 31

  
32 32
class OIDCUser(object):
src/authentic2/authenticators.py
18 18

  
19 19
from django.db.models import Count
20 20
from django.shortcuts import render
21
from django.utils.translation import ugettext as _, ugettext_lazy
21
from django.utils.translation import ugettext as _
22
from django.utils.translation import ugettext_lazy
22 23

  
23
from authentic2.a2_rbac.models import OrganizationalUnit as OU, Role
24
from authentic2.a2_rbac.models import OrganizationalUnit as OU
25
from authentic2.a2_rbac.models import Role
24 26
from authentic2.custom_user.models import User
25
from . import views, app_settings, utils
26
from .utils.views import csrf_token_check
27
from .utils.service import get_service_from_request
27

  
28
from . import app_settings, utils, views
28 29
from .forms import authentication as authentication_forms
29 30
from .utils.evaluate import evaluate_condition
31
from .utils.service import get_service_from_request
32
from .utils.views import csrf_token_check
30 33

  
31 34
logger = logging.getLogger(__name__)
32 35

  
src/authentic2/backends/__init__.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.contrib.auth import get_user_model
18

  
18 19
from authentic2 import app_settings
19 20

  
20 21

  
src/authentic2/backends/ldap_backend.py
20 20
    import ldap
21 21
    import ldap.modlist
22 22
    import ldap.sasl
23
    from ldap.filter import filter_format
23
    from ldap.controls import DecodeControlTuples, SimplePagedResultsControl, ppolicy
24 24
    from ldap.dn import escape_dn_chars
25
    from ldap.filter import filter_format
25 26
    from ldap.ldapobject import ReconnectLDAPObject as NativeLDAPObject
26
    from ldap.controls import SimplePagedResultsControl, DecodeControlTuples
27
    from ldap.controls import ppolicy
28 27
    from pyasn1.codec.der import decoder
29 28

  
30 29
    PYTHON_LDAP3 = [int(x) for x in ldap.__version__.split('.')] >= [3]
......
32 31
except ImportError:
33 32
    ldap = None
34 33
    PYTHON_LDAP3 = None
35
import logging
36
import random
37 34
import base64
38
import os
39 35
import json
36
import logging
37
import os
38
import random
40 39
import time
41 40

  
42
# code originaly copied from by now merely inspired by
43
# http://www.amherst.k12.oh.us/django-ldap.html
44

  
45
from django.core.cache import cache
46
from django.core.exceptions import ImproperlyConfigured
47 41
from django.conf import settings
48 42
from django.contrib import messages
49 43
from django.contrib.auth import get_user_model
50 44
from django.contrib.auth.models import Group
51
from django.utils.encoding import force_bytes, force_text
45
from django.core.cache import cache
46
from django.core.exceptions import ImproperlyConfigured
52 47
from django.utils import six
48
from django.utils.encoding import force_bytes, force_text
53 49
from django.utils.six.moves.urllib import parse as urlparse
54
from django.utils.translation import ugettext as _, ngettext
50
from django.utils.translation import ngettext
51
from django.utils.translation import ugettext as _
55 52

  
53
from authentic2 import app_settings, crypto
56 54
from authentic2.a2_rbac.models import Role
57

  
55
from authentic2.a2_rbac.utils import get_default_ou
56
from authentic2.backends import is_user_authenticable
58 57
from authentic2.compat_lasso import lasso
59

  
60
from authentic2 import crypto, app_settings
61
from authentic2.models import UserExternalId
58
from authentic2.ldap_utils import FilterFormatter
62 59
from authentic2.middleware import StoreRequestMiddleware
60
from authentic2.models import UserExternalId
63 61
from authentic2.user_login_failure import user_login_failure, user_login_success
64
from django_rbac.utils import get_ou_model
65
from authentic2.a2_rbac.utils import get_default_ou
66
from authentic2.ldap_utils import FilterFormatter
67 62
from authentic2.utils import to_list
63
from django_rbac.utils import get_ou_model
64

  
65
# code originaly copied from by now merely inspired by
66
# http://www.amherst.k12.oh.us/django-ldap.html
68 67

  
69
from authentic2.backends import is_user_authenticable
70 68

  
71 69
log = logging.getLogger(__name__)
72 70

  
src/authentic2/backends/models_backend.py
16 16

  
17 17
from __future__ import unicode_literals
18 18

  
19
from django.db import models
20 19
from django.contrib.auth import get_user_model
21 20
from django.contrib.auth.backends import ModelBackend
21
from django.db import models
22 22
from django.utils import six
23 23

  
24
from .. import app_settings
25
from authentic2.user_login_failure import user_login_success, user_login_failure
26

  
27 24
from authentic2.backends import get_user_queryset
25
from authentic2.user_login_failure import user_login_failure, user_login_success
26

  
27
from .. import app_settings
28 28

  
29 29

  
30 30
def upn(username, realm):
src/authentic2/cbv.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt
18

  
19
from django.utils.decorators import method_decorator
20
from django.forms import Form
21
from django.contrib.auth import REDIRECT_FIELD_NAME
22 17
from django.conf import settings
18
from django.contrib.auth import REDIRECT_FIELD_NAME
19
from django.forms import Form
20
from django.utils.decorators import method_decorator
21
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
23 22

  
24
from . import utils, hooks
23
from . import hooks, utils
25 24
from .utils.views import csrf_token_check
26 25

  
27 26

  
src/authentic2/compat/drf.py
18 18
try:
19 19
    from rest_framework.decorators import action
20 20
except ImportError:
21
    from rest_framework.decorators import list_route, detail_route
21
    from rest_framework.decorators import detail_route, list_route
22 22

  
23 23
    def action(**kwargs):
24 24
        kwargs.pop('name', None)
src/authentic2/compat/misc.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from datetime import datetime
18 17
import inspect
18
from datetime import datetime
19 19

  
20 20
from django.conf import settings
21 21
from django.utils import six
src/authentic2/context_processors.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from pkg_resources import get_distribution
18 17
from django.conf import settings
18
from pkg_resources import get_distribution
19 19

  
20
from . import utils, app_settings, constants
20
from . import app_settings, constants, utils
21 21
from .models import Service
22 22

  
23 23

  
src/authentic2/cors.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import itertools
18
from .decorators import SessionCache
19 18

  
20 19
from django.apps import apps
21 20
from django.conf import settings
22 21
from django.utils.six.moves.urllib import parse as urlparse
23 22

  
24
from . import plugins, app_settings
23
from . import app_settings, plugins
24
from .decorators import SessionCache
25 25

  
26 26

  
27 27
def make_origin(url):
src/authentic2/crypto.py
19 19
import hmac
20 20
import struct
21 21

  
22
from Cryptodome import Random
22 23
from Cryptodome.Cipher import AES
24
from Cryptodome.Hash import HMAC, SHA256
23 25
from Cryptodome.Protocol.KDF import PBKDF2
24
from Cryptodome.Hash import SHA256
25
from Cryptodome.Hash import HMAC
26
from Cryptodome import Random
27

  
28 26
from django.utils.crypto import constant_time_compare
29 27
from django.utils.encoding import force_bytes
30 28
from django.utils.six import text_type
src/authentic2/csv_import.py
19 19
import csv
20 20
import io
21 21

  
22
from chardet.universaldetector import UniversalDetector
23 22
import attr
24

  
23
from chardet.universaldetector import UniversalDetector
25 24
from django import forms
26 25
from django.contrib.auth.hashers import identify_hasher
27 26
from django.core.exceptions import FieldDoesNotExist, ValidationError
......
29 28
from django.db import IntegrityError, models
30 29
from django.db.transaction import atomic
31 30
from django.utils import six
32
from django.utils.encoding import force_bytes
33
from django.utils.encoding import force_text
31
from django.utils.encoding import force_bytes, force_text
34 32
from django.utils.translation import ugettext as _
35 33

  
36
from django_rbac.utils import get_role_model
37

  
38 34
from authentic2 import app_settings
39 35
from authentic2.a2_rbac.utils import get_default_ou
40 36
from authentic2.custom_user.models import User
41
from authentic2.forms.profile import modelform_factory, BaseUserForm
37
from authentic2.forms.profile import BaseUserForm, modelform_factory
42 38
from authentic2.models import Attribute, AttributeValue, UserExternalId
43 39
from authentic2.utils import send_password_reset_mail
40
from django_rbac.utils import get_role_model
44 41

  
45 42
Role = get_role_model()
46 43

  
src/authentic2/custom_user/apps.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.db import DEFAULT_DB_ALIAS, router
18 17
from django.apps import AppConfig
18
from django.db import DEFAULT_DB_ALIAS, router
19 19

  
20 20

  
21 21
class CustomUserConfig(AppConfig):
......
30 30
    def create_first_name_last_name_attributes(
31 31
        self, app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs
32 32
    ):
33
        from django.conf import settings
34
        from django.contrib.auth import get_user_model
35
        from django.contrib.contenttypes.models import ContentType
33 36
        from django.utils import translation
34 37
        from django.utils.translation import ugettext_lazy as _
35
        from django.conf import settings
38

  
36 39
        from authentic2.attribute_kinds import get_kind
37 40
        from authentic2.models import Attribute, AttributeValue
38
        from django.contrib.auth import get_user_model
39
        from django.contrib.contenttypes.models import ContentType
40 41

  
41 42
        if not router.allow_migrate(using, Attribute):
42 43
            return
src/authentic2/custom_user/management/commands/changepassword.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from __future__ import unicode_literals, print_function
17
from __future__ import print_function, unicode_literals
18 18

  
19 19
import getpass
20 20

  
21 21
from django.contrib.auth import get_user_model
22
from django.core.exceptions import MultipleObjectsReturned
22 23
from django.core.management.base import BaseCommand, CommandError
23 24
from django.db import DEFAULT_DB_ALIAS
24
from django.utils.encoding import force_str
25 25
from django.db.models.query import Q
26
from django.core.exceptions import MultipleObjectsReturned
26
from django.utils.encoding import force_str
27 27

  
28 28

  
29 29
class Command(BaseCommand):
src/authentic2/custom_user/management/commands/fix-attributes.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from __future__ import unicode_literals, print_function
17
from __future__ import print_function, unicode_literals
18 18

  
19 19
from django.core.management.base import BaseCommand
20 20

  
src/authentic2/custom_user/managers.py
17 17
import unicodedata
18 18
import uuid
19 19

  
20
from django.contrib.auth.models import BaseUserManager
20 21
from django.contrib.contenttypes.models import ContentType
21
from django.contrib.postgres.search import TrigramDistance
22
from django.contrib.postgres.search import SearchQuery, TrigramDistance
22 23
from django.core.exceptions import ValidationError
23
from django.db import models, connection
24
from django.db.models import F, Value, FloatField, Subquery, OuterRef, Q
25
from django.db.models.functions import Lower, Coalesce
24
from django.db import connection, models
25
from django.db.models import F, FloatField, OuterRef, Q, Subquery, Value
26
from django.db.models.functions import Coalesce, Lower
26 27
from django.utils import timezone
27
from django.contrib.auth.models import BaseUserManager
28
from django.contrib.postgres.search import SearchQuery
29 28

  
30 29
from authentic2 import app_settings
30
from authentic2.attribute_kinds import clean_number
31 31
from authentic2.models import AttributeValue
32
from authentic2.utils.lookups import Unaccent, ImmutableConcat
33 32
from authentic2.utils.date import parse_date
34
from authentic2.attribute_kinds import clean_number
33
from authentic2.utils.lookups import ImmutableConcat, Unaccent
35 34

  
36 35

  
37 36
class UserQuerySet(models.QuerySet):
src/authentic2/custom_user/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
import django.utils.timezone
5
from django.db import migrations, models
6

  
6 7
import authentic2.utils
7 8
import authentic2.validators
8 9

  
src/authentic2/custom_user/migrations/0002_auto_20150410_1823.py
2 2
from __future__ import unicode_literals
3 3

  
4 4
from django.conf import settings
5
from django.db import models, migrations
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class ThirdPartyAlterField(migrations.AlterField):
src/authentic2/custom_user/migrations/0003_auto_20150504_1410.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/custom_user/migrations/0004_user_ou.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/custom_user/migrations/0005_auto_20150522_1527.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/custom_user/migrations/0006_auto_20150527_1212.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def noop(apps, schema_editor):
src/authentic2/custom_user/migrations/0007_auto_20150610_1527.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def noop(apps, schema_editor):
src/authentic2/custom_user/migrations/0008_auto_20150617_1606.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
import django.utils.timezone
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/custom_user/migrations/0009_auto_20150810_1953.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/custom_user/migrations/0010_auto_20160307_1418.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/custom_user/migrations/0012_user_modified.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import migrations, models
5 4
import datetime
5

  
6
from django.db import migrations, models
6 7
from django.utils.timezone import utc
7 8

  
8 9

  
src/authentic2/custom_user/migrations/0021_set_unusable_password.py
2 2
# Generated by Django 1.11.29 on 2020-11-02 21:52
3 3
from __future__ import unicode_literals
4 4

  
5

  
6
from django.db import migrations
7 5
from django.contrib.auth.models import AbstractUser
6
from django.db import migrations
8 7

  
9 8

  
10 9
def noop(apps, schema_editor):
src/authentic2/custom_user/migrations/0026_remove_user_deleted.py
1 1
# Generated by Django 2.2.19 on 2021-02-26 10:02
2 2

  
3 3
from django.db import migrations
4

  
4 5
from authentic2 import app_settings
5 6

  
6 7

  
src/authentic2/custom_user/models.py
22 22
import os
23 23
import random
24 24

  
25
from django.db import models, transaction
26
from django.utils import timezone
25
from django.core.exceptions import MultipleObjectsReturned, ValidationError
27 26
from django.core.mail import send_mail
28
from django.utils import six
27
from django.db import models, transaction
28
from django.utils import six, timezone
29 29
from django.utils.translation import ugettext_lazy as _
30
from django.core.exceptions import ValidationError, MultipleObjectsReturned
31 30

  
32 31
try:
33 32
    from django.contrib.contenttypes.fields import GenericRelation
34 33
except ImportError:
35 34
    from django.contrib.contenttypes.generic import GenericRelation
35

  
36 36
from django.contrib.auth.models import AbstractBaseUser
37 37
from django.contrib.postgres.fields import JSONField
38 38

  
39
from authentic2 import app_settings, utils
40
from authentic2.decorators import RequestCache, errorcollector
41
from authentic2.models import Attribute, AttributeValue, Service, UserExternalId
42
from authentic2.validators import email_validator
39 43
from django_rbac.models import PermissionMixin
40 44
from django_rbac.utils import get_role_parenting_model
41 45

  
42
from authentic2 import utils, app_settings
43
from authentic2.decorators import errorcollector, RequestCache
44
from authentic2.models import Service, AttributeValue, Attribute, UserExternalId
45
from authentic2.validators import email_validator
46

  
47 46
from .managers import UserManager, UserQuerySet
48 47

  
49 48

  
src/authentic2/data_transfer.py
18 18

  
19 19
from functools import wraps
20 20

  
21
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
22 21
from django.contrib.contenttypes.models import ContentType
23
from django.utils.translation import ugettext_lazy as _
22
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
24 23
from django.utils.text import format_lazy
24
from django.utils.translation import ugettext_lazy as _
25 25

  
26
from django_rbac.models import Operation
27
from django_rbac.utils import get_ou_model, get_role_model, get_role_parenting_model, get_permission_model
28

  
29
from authentic2.decorators import errorcollector
30 26
from authentic2.a2_rbac.models import RoleAttribute
27
from authentic2.decorators import errorcollector
31 28
from authentic2.utils.lazy import lazy_join
29
from django_rbac.models import Operation
30
from django_rbac.utils import (
31
    get_ou_model,
32
    get_permission_model,
33
    get_role_model,
34
    get_role_parenting_model,
35
)
32 36

  
33 37

  
34 38
def update_model(obj, d):
src/authentic2/decorators.py
17 17
import base64
18 18
import pickle
19 19
import re
20
from json import dumps as json_dumps
21
from contextlib import contextmanager
22 20
import time
21
from contextlib import contextmanager
23 22
from functools import wraps
23
from json import dumps as json_dumps
24 24

  
25
from django.views.debug import technical_404_response
26
from django.http import Http404, HttpResponseForbidden, HttpResponse, HttpResponseBadRequest
27 25
from django.core.cache import cache as django_cache
28 26
from django.core.exceptions import ValidationError
27
from django.http import (
28
    Http404,
29
    HttpResponse,
30
    HttpResponseBadRequest,
31
    HttpResponseForbidden,
32
)
29 33
from django.utils import six
34
from django.views.debug import technical_404_response
30 35

  
31 36
from . import app_settings, middleware
32 37

  
33 38
# XXX: import to_list for retrocompaibility
34
from .utils import to_list, to_iter  # noqa: F401
39
from .utils import to_iter, to_list  # noqa: F401
35 40

  
36 41

  
37 42
class CacheUnusable(RuntimeError):
src/authentic2/disco_service/disco_responder.py
23 23

  
24 24

  
25 25
import logging
26

  
27 26
from xml.dom.minidom import parseString
28 27

  
29
from django.http import HttpResponseRedirect
30 28
from django.conf.urls import url
31
from django.utils.translation import ugettext as _
29
from django.http import HttpResponseRedirect
30
from django.urls import reverse
32 31
from django.utils.http import urlquote
33 32
from django.utils.six.moves.urllib import parse as urlparse
34
from django.urls import reverse
33
from django.utils.translation import ugettext as _
35 34

  
36 35
from authentic2 import settings
37 36
from authentic2.saml.common import error_page as base_error_page
src/authentic2/exponential_retry_timeout.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import time
18
import logging
19 17
import hashlib
18
import logging
19
import time
20 20

  
21
from django.utils import six
22 21
from django.core.cache import cache
22
from django.utils import six
23 23

  
24 24

  
25 25
class ExponentialRetryTimeout(object):
src/authentic2/forms/authentication.py
19 19

  
20 20
from django import forms
21 21
from django.conf import settings
22
from django.forms.widgets import Media
23
from django.utils.translation import ugettext_lazy as _, ugettext
24 22
from django.contrib.auth import forms as auth_forms
23
from django.forms.widgets import Media
25 24
from django.utils import html
26 25
from django.utils.encoding import force_text
26
from django.utils.translation import ugettext
27
from django.utils.translation import ugettext_lazy as _
27 28

  
28 29
from authentic2.forms.fields import PasswordField
29 30
from authentic2.utils.lazy import lazy_label
30 31

  
31
from ..a2_rbac.models import OrganizationalUnit as OU
32 32
from .. import app_settings, utils
33
from ..a2_rbac.models import OrganizationalUnit as OU
33 34
from ..exponential_retry_timeout import ExponentialRetryTimeout
34 35

  
35 36

  
src/authentic2/forms/fields.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import warnings
18 17
import io
18
import warnings
19 19

  
20
from django.forms import CharField, FileField, ValidationError, EmailField
20
import PIL.Image
21
from django.core.files import File
22
from django.forms import CharField, EmailField, FileField, ValidationError
21 23
from django.forms.fields import FILE_INPUT_CONTRADICTION
22 24
from django.utils.translation import ugettext_lazy as _
23
from django.core.files import File
24 25

  
25 26
from authentic2 import app_settings
26
from authentic2.passwords import password_help_text, validate_password
27 27
from authentic2.forms.widgets import (
28
    PasswordInput,
29
    NewPasswordInput,
30 28
    CheckPasswordInput,
31
    ProfileImageInput,
32 29
    EmailInput,
30
    NewPasswordInput,
31
    PasswordInput,
32
    ProfileImageInput,
33 33
)
34
from authentic2.passwords import password_help_text, validate_password
34 35
from authentic2.validators import email_validator
35 36

  
36
import PIL.Image
37

  
38 37

  
39 38
class PasswordField(CharField):
40 39
    widget = PasswordInput
src/authentic2/forms/honeypot.py
16 16

  
17 17

  
18 18
from django.core.exceptions import ValidationError
19
from django.forms import Form, CheckboxInput, BooleanField
19
from django.forms import BooleanField, CheckboxInput, Form
20 20
from django.utils.html import mark_safe
21 21
from django.utils.translation import gettext as _
22 22

  
src/authentic2/forms/passwords.py
17 17
import logging
18 18
from collections import OrderedDict
19 19

  
20
from django import forms
20 21
from django.contrib.auth import forms as auth_forms
21 22
from django.core.exceptions import ValidationError
22 23
from django.db.models import Q
23 24
from django.forms import Form
24
from django import forms
25 25
from django.urls import reverse
26 26
from django.utils.translation import ugettext_lazy as _
27 27

  
28
from .. import models, hooks, app_settings, utils
28
from .. import app_settings, hooks, models, utils
29 29
from ..backends import get_user_queryset
30
from .fields import PasswordField, NewPasswordField, CheckPasswordField, ValidatedEmailField
30
from .fields import (
31
    CheckPasswordField,
32
    NewPasswordField,
33
    PasswordField,
34
    ValidatedEmailField,
35
)
31 36
from .utils import NextUrlFormMixin
32 37

  
33

  
34 38
logger = logging.getLogger(__name__)
35 39

  
36 40

  
src/authentic2/forms/profile.py
16 16

  
17 17
from collections import OrderedDict
18 18

  
19
from django.forms.models import modelform_factory as dj_modelform_factory
20 19
from django import forms
21
from django.utils.translation import ugettext_lazy as _, ugettext
20
from django.forms.models import modelform_factory as dj_modelform_factory
21
from django.utils.translation import ugettext
22
from django.utils.translation import ugettext_lazy as _
22 23

  
23 24
from authentic2 import app_settings, models
24 25
from authentic2.custom_user.models import User
25
from .utils import NextUrlFormMixin
26
from .mixins import LockedFieldFormMixin
26

  
27 27
from .fields import ValidatedEmailField
28
from .mixins import LockedFieldFormMixin
29
from .utils import NextUrlFormMixin
28 30

  
29 31

  
30 32
class DeleteAccountForm(forms.Form):
src/authentic2/forms/registration.py
17 17
import re
18 18

  
19 19
from django.contrib.auth import get_user_model
20
from django.contrib.auth.models import BaseUserManager, Group
20 21
from django.core.exceptions import ValidationError
21 22
from django.core.validators import RegexValidator
22
from django.utils.translation import ugettext_lazy as _, ugettext
23

  
24
from django.contrib.auth.models import BaseUserManager, Group
23
from django.utils.translation import ugettext
24
from django.utils.translation import ugettext_lazy as _
25 25

  
26
from authentic2.forms.fields import NewPasswordField, CheckPasswordField
27 26
from authentic2.a2_rbac.models import OrganizationalUnit
27
from authentic2.forms.fields import CheckPasswordField, NewPasswordField
28 28

  
29 29
from .. import app_settings, models
30 30
from . import profile as profile_forms
31
from .honeypot import HoneypotForm
32 31
from .fields import ValidatedEmailField
32
from .honeypot import HoneypotForm
33 33

  
34 34
User = get_user_model()
35 35

  
src/authentic2/forms/widgets.py
23 23
# License: BSD
24 24
# Initial Author: Alfredo Saglimbeni
25 25

  
26
import datetime
26 27
import json
27 28
import re
28 29
import uuid
29
import datetime
30 30

  
31 31
import django
32 32
from django import forms
33
from django.forms.widgets import DateTimeInput, DateInput, TimeInput, ClearableFileInput
33
from django.forms.widgets import ClearableFileInput, DateInput, DateTimeInput
34
from django.forms.widgets import EmailInput as BaseEmailInput
34 35
from django.forms.widgets import PasswordInput as BasePasswordInput
35
from django.forms.widgets import TextInput, EmailInput as BaseEmailInput
36
from django.utils.formats import get_language, get_format
36
from django.forms.widgets import TextInput, TimeInput
37
from django.utils.encoding import force_text
38
from django.utils.formats import get_format, get_language
37 39
from django.utils.safestring import mark_safe
38 40
from django.utils.translation import ugettext_lazy as _
39
from django.utils.encoding import force_text
40

  
41 41
from gadjo.templatetags.gadjo import xstatic
42 42

  
43 43
from authentic2 import app_settings
src/authentic2/hashers.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import base64
17 18
import hashlib
18 19
import math
19
import base64
20 20
from binascii import hexlify, unhexlify
21 21
from collections import OrderedDict
22 22

  
23 23
from django.contrib.auth import hashers
24
from django.contrib.auth.hashers import make_password
24 25
from django.utils.crypto import constant_time_compare
25
from django.utils.translation import ugettext_noop as _
26 26
from django.utils.encoding import force_bytes, force_text
27
from django.contrib.auth.hashers import make_password
27
from django.utils.translation import ugettext_noop as _
28 28

  
29 29

  
30 30
class Drupal7PasswordHasher(hashers.BasePasswordHasher):
src/authentic2/idp/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/idp/migrations/0002_auto_20150526_2239.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/idp/migrations/0003_auto_20150915_2041.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/idp/saml/__init__.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.conf import settings
18
from django.core.checks import register, Warning, Tags
19 17
from django.apps import AppConfig
18
from django.conf import settings
19
from django.core.checks import Tags, Warning, register
20 20

  
21 21

  
22 22
class Plugin(object):
src/authentic2/idp/saml/backend.py
18 18
import operator
19 19
import random
20 20

  
21
from django.utils.translation import ugettext as _
22
from django.template.loader import render_to_string
23 21
from django.db.models import Q
22
from django.template.loader import render_to_string
23
from django.urls import reverse
24 24
from django.utils import six
25 25
from django.utils.six.moves.urllib.parse import quote
26
from django.urls import reverse
26
from django.utils.translation import ugettext as _
27 27

  
28
import authentic2.saml.models as models
29 28
import authentic2.idp.saml.saml2_endpoints as saml2_endpoints
30 29
import authentic2.saml.common as common
31

  
30
import authentic2.saml.models as models
32 31
from authentic2.decorators import to_list
33 32
from authentic2.utils import Service
34 33

  
src/authentic2/idp/saml/common.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import logging
18

  
19
from django.contrib.auth import REDIRECT_FIELD_NAME
20
from django.utils.http import urlencode
21 18
from importlib import import_module
19

  
22 20
from django.conf import settings
21
from django.contrib.auth import REDIRECT_FIELD_NAME
23 22
from django.http import HttpResponseRedirect
23
from django.utils.http import urlencode
24 24

  
25 25

  
26 26
def redirect_to_login(next_url, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME, other_keys={}):
src/authentic2/idp/saml/saml2_endpoints.py
35 35
from __future__ import unicode_literals
36 36

  
37 37
import datetime
38
import logging
39
import xml.etree.cElementTree as ctree
40 38
import hashlib
39
import logging
41 40
import random
42 41
import string
42
import xml.etree.cElementTree as ctree
43 43
from functools import wraps
44 44

  
45
from authentic2.compat_lasso import lasso
46
from django.contrib.auth import get_user_model
45
from django.conf import settings
46
from django.contrib import messages
47
from django.contrib.auth import (
48
    BACKEND_SESSION_KEY,
49
    REDIRECT_FIELD_NAME,
50
    get_user_model,
51
    load_backend,
52
)
47 53
from django.contrib.auth.decorators import login_required
48 54
from django.core.exceptions import ObjectDoesNotExist
49
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, HttpResponseBadRequest
55
from django.http import (
56
    HttpResponse,
57
    HttpResponseBadRequest,
58
    HttpResponseForbidden,
59
    HttpResponseRedirect,
60
)
61
from django.shortcuts import redirect, render
62
from django.urls import reverse
50 63
from django.utils import six
51
from django.utils.translation import ugettext as _, ugettext_noop as N_
52
from django.views.decorators.csrf import csrf_exempt
64
from django.utils.encoding import force_bytes, force_str, force_text
65
from django.utils.six.moves.urllib.parse import quote, urlencode
66
from django.utils.translation import ugettext as _
67
from django.utils.translation import ugettext_noop as N_
53 68
from django.views.decorators.cache import never_cache
69
from django.views.decorators.csrf import csrf_exempt
54 70
from django.views.decorators.http import require_POST
55
from django.contrib.auth import BACKEND_SESSION_KEY, REDIRECT_FIELD_NAME
56
from django.conf import settings
57
from django.utils.encoding import force_str, force_bytes, force_text
58
from django.utils.six.moves.urllib.parse import quote, urlencode
59
from django.urls import reverse
60
from django.contrib.auth import load_backend
61
from django.shortcuts import render, redirect
62
from django.contrib import messages
63

  
64 71

  
72
import authentic2.saml.saml2utils as saml2utils
65 73
import authentic2.views as a2_views
66
from authentic2.saml.models import (
67
    LibertyArtifact,
68
    LibertySession,
69
    LibertyFederation,
70
    nameid2kwargs,
71
    saml2_urn_to_nidformat,
72
    nidformat_to_saml2_urn,
73
    save_key_values,
74
    get_and_delete_key_values,
75
    LibertyProvider,
76
    LibertyServiceProvider,
77
    SAMLAttribute,
78
    NAME_ID_FORMATS,
79
)
74
from authentic2 import hooks, utils
75
from authentic2.attributes_ng.engine import get_attributes
76
from authentic2.compat_lasso import lasso
77
from authentic2.constants import NONCE_FIELD_NAME
78
from authentic2.idp import signals as idp_signals
79
from authentic2.idp.saml.common import kill_django_sessions
80 80
from authentic2.saml.common import (
81
    redirect_next,
82
    asynchronous_bindings,
83
    soap_bindings,
84
    load_provider,
85
    get_saml2_request_message,
86
    error_page,
87
    set_saml2_response_responder_status_code,
81
    AUTHENTIC_SAME_ID_SENTINEL,
82
    AUTHENTIC_STATUS_CODE_INTERNAL_SERVER_ERROR,
88 83
    AUTHENTIC_STATUS_CODE_MISSING_DESTINATION,
89
    load_federation,
90
    return_saml2_response,
91
    get_soap_message,
92
    soap_fault,
93
    return_saml_soap_response,
94
    AUTHENTIC_STATUS_CODE_UNKNOWN_PROVIDER,
95 84
    AUTHENTIC_STATUS_CODE_MISSING_NAMEID,
96 85
    AUTHENTIC_STATUS_CODE_MISSING_SESSION_INDEX,
97
    AUTHENTIC_STATUS_CODE_UNKNOWN_SESSION,
98
    AUTHENTIC_STATUS_CODE_INTERNAL_SERVER_ERROR,
99 86
    AUTHENTIC_STATUS_CODE_UNAUTHORIZED,
100
    send_soap_request,
101
    get_saml2_query_request,
102
    get_saml2_request_message_async_binding,
87
    AUTHENTIC_STATUS_CODE_UNKNOWN_PROVIDER,
88
    AUTHENTIC_STATUS_CODE_UNKNOWN_SESSION,
89
    asynchronous_bindings,
103 90
    create_saml2_server,
91
    error_page,
92
    get_entity_id,
104 93
    get_saml2_metadata,
94
    get_saml2_query_request,
95
    get_saml2_request_message,
96
    get_saml2_request_message_async_binding,
97
    get_soap_message,
105 98
    get_sp_options_policy,
106
    get_entity_id,
107
    AUTHENTIC_SAME_ID_SENTINEL,
99
    load_federation,
100
    load_provider,
101
    redirect_next,
102
    return_saml2_response,
103
    return_saml_soap_response,
104
    send_soap_request,
105
    set_saml2_response_responder_status_code,
106
    soap_bindings,
107
    soap_fault,
108 108
)
109
import authentic2.saml.saml2utils as saml2utils
110
from authentic2.idp.saml.common import kill_django_sessions
111
from authentic2.constants import NONCE_FIELD_NAME
112

  
113
from authentic2.idp import signals as idp_signals
114

  
115
from authentic2.utils import (
116
    make_url,
117
    get_backends as get_idp_backends,
118
    login_require,
119
    find_authentication_event,
120
    datetime_to_xs_datetime,
109
from authentic2.saml.models import (
110
    NAME_ID_FORMATS,
111
    LibertyArtifact,
112
    LibertyFederation,
113
    LibertyProvider,
114
    LibertyServiceProvider,
115
    LibertySession,
116
    SAMLAttribute,
117
    get_and_delete_key_values,
118
    nameid2kwargs,
119
    nidformat_to_saml2_urn,
120
    saml2_urn_to_nidformat,
121
    save_key_values,
121 122
)
122
from authentic2 import utils
123
from authentic2.attributes_ng.engine import get_attributes
124
from authentic2 import hooks
123
from authentic2.utils import datetime_to_xs_datetime, find_authentication_event
124
from authentic2.utils import get_backends as get_idp_backends
125
from authentic2.utils import login_require, make_url
125 126

  
126 127
from . import app_settings
127 128

  
128

  
129 129
User = get_user_model()
130 130

  
131 131
logger = logging.getLogger(__name__)
src/authentic2/idp/saml/urls.py
16 16

  
17 17
from django.conf.urls import url
18 18

  
19
from . import views
20 19
from authentic2.idp.saml.saml2_endpoints import (
21
    metadata,
22
    sso,
20
    artifact,
23 21
    continue_sso,
24
    slo,
25
    slo_soap,
26
    idp_slo,
27
    slo_return,
28 22
    finish_slo,
29
    artifact,
23
    idp_slo,
30 24
    idp_sso,
25
    metadata,
26
    slo,
27
    slo_return,
28
    slo_soap,
29
    sso,
31 30
)
32 31

  
32
from . import views
33

  
33 34
urlpatterns = [
34 35
    url(r'^metadata$', metadata, name='a2-idp-saml-metadata'),
35 36
    url(r'^sso$', sso, name='a2-idp-saml-sso'),
src/authentic2/idp/saml/views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.utils.translation import ugettext as _
18
from django.views.generic import DeleteView, View
17
from django.contrib import messages
18
from django.contrib.auth import REDIRECT_FIELD_NAME
19 19
from django.http import HttpResponseRedirect
20 20
from django.urls import reverse
21

  
22
from django.contrib.auth import REDIRECT_FIELD_NAME
23
from django.contrib import messages
21
from django.utils.translation import ugettext as _
22
from django.views.generic import DeleteView, View
24 23

  
25 24
from authentic2.saml.models import LibertyFederation
26 25

  
src/authentic2/idp/urls.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.conf.urls import url
18

  
18 19
from authentic2.idp.interactions import consent_federation
19 20

  
20 21
urlpatterns = [
src/authentic2/journal.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from authentic2.utils.service import get_service_from_request
18

  
19 17
from authentic2.apps.journal.journal import Journal
18
from authentic2.utils.service import get_service_from_request
20 19

  
21 20

  
22 21
class Journal(Journal):
src/authentic2/journal_event_types.py
17 17
from django.contrib.contenttypes.models import ContentType
18 18
from django.utils.translation import ugettext_lazy as _
19 19

  
20
from authentic2.custom_user.models import get_attributes_map
21 20
from authentic2.apps.journal.models import EventTypeDefinition, n_2_pairing_rev
22
from authentic2.apps.journal.utils import form_to_old_new, Statistics
23
from authentic2.custom_user.models import User
21
from authentic2.apps.journal.utils import Statistics, form_to_old_new
22
from authentic2.custom_user.models import User, get_attributes_map
24 23

  
25 24
from .models import Service
26 25

  
src/authentic2/ldap_utils.py
19 19

  
20 20
import ldap.dn
21 21
import ldap.filter
22

  
23 22
from django.utils.encoding import force_text
24 23

  
25 24

  
src/authentic2/log_filters.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import logging
18

  
18 19
from django.utils import six
19 20

  
20 21

  
src/authentic2/management/commands/check-and-repair.py
30 30
from django.utils.six.moves import input
31 31
from django.utils.timezone import localtime
32 32

  
33
from authentic2 import app_settings
34
from authentic2.a2_rbac.models import OrganizationalUnit as OU
35
from authentic2.a2_rbac.models import Permission, Role
33 36
from django_rbac.models import ADMIN_OP
34 37
from django_rbac.utils import get_operation
35 38

  
36
from authentic2 import app_settings
37
from authentic2.a2_rbac.models import OrganizationalUnit as OU, Role, Permission
38

  
39 39
try:
40 40
    from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP
41 41
except ImportError:
......
44 44

  
45 45
MULTITENANT = 'hobo.multitenant' in settings.INSTALLED_APPS
46 46
if MULTITENANT:
47
    from tenant_schemas.utils import tenant_context
48 47
    from hobo.multitenant.middleware import TenantMiddleware
48
    from tenant_schemas.utils import tenant_context
49 49

  
50 50

  
51 51
class FakeState(object):
src/authentic2/management/commands/clean-unused-accounts.py
17 17
from __future__ import print_function
18 18

  
19 19
import logging
20

  
21 20
from datetime import timedelta
21

  
22
from django.conf import settings
22 23
from django.contrib.auth import get_user_model
23 24
from django.core.management.base import BaseCommand
24 25
from django.db import transaction
25 26
from django.db.models import F
26 27
from django.utils import timezone, translation
27 28
from django.utils.six.moves.urllib import parse as urlparse
28
from django_rbac.utils import get_ou_model
29 29

  
30 30
from authentic2.backends.ldap_backend import LDAPBackend
31 31
from authentic2.utils import send_templated_mail
32

  
33
from django.conf import settings
32
from django_rbac.utils import get_ou_model
34 33

  
35 34
logger = logging.getLogger(__name__)
36 35

  
src/authentic2/management/commands/import_site.py
23 23
from django.db import transaction
24 24
from django.utils import translation
25 25

  
26
from authentic2.data_transfer import import_site, ImportContext
26
from authentic2.data_transfer import ImportContext, import_site
27 27

  
28 28

  
29 29
class DryRunException(Exception):
src/authentic2/management/commands/load-ldif.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import argparse
18
import logging
19 18
import json
19
import logging
20 20

  
21

  
22
from django.core.management.base import BaseCommand
21
import ldif
23 22
from django.contrib.auth import get_user_model
23
from django.core.management.base import BaseCommand
24 24
from django.db.transaction import atomic
25 25

  
26

  
27 26
from authentic2.hashers import olap_password_to_dj
28 27
from authentic2.models import Attribute
29 28

  
30 29

  
31
import ldif
32

  
33

  
34 30
class DjangoUserLDIFParser(ldif.LDIFParser):
35 31
    def __init__(self, *args, **kwargs):
36 32
        self.options = kwargs.pop('options')
src/authentic2/management/commands/resetpassword.py
20 20
from django.core.management.base import BaseCommand, CommandError
21 21
from django.db import DEFAULT_DB_ALIAS
22 22

  
23
from authentic2.utils import generate_password
24 23
from authentic2.models import PasswordReset
25

  
24
from authentic2.utils import generate_password
26 25

  
27 26
User = get_user_model()
28 27

  
src/authentic2/management/commands/slapd-shell.py
17 17
from __future__ import print_function
18 18

  
19 19
import logging
20
import sys
21 20
import re
22

  
23
from ldap.dn import escape_dn_chars
24
from ldif import LDIFWriter
25

  
21
import sys
26 22

  
27 23
from django.contrib.auth import get_user_model
28 24
from django.core.management.base import BaseCommand
29 25
from django.utils import six
26
from ldap.dn import escape_dn_chars
27
from ldif import LDIFWriter
30 28

  
31 29
COMMAND = 1
32 30
ATTR = 2
src/authentic2/manager/apps.py
23 23

  
24 24
    def ready(self):
25 25
        from django.db.models.signals import post_save
26

  
26 27
        from django_rbac.utils import get_ou_model
27 28

  
28 29
        post_save.connect(self.post_save_ou, sender=get_ou_model())
src/authentic2/manager/forms.py
16 16

  
17 17
import hashlib
18 18
import json
19
import smtplib
20 19
import logging
20
import smtplib
21 21

  
22
from django.utils.translation import ugettext_lazy as _, pgettext, ugettext
23 22
from django import forms
24
from django.contrib.contenttypes.models import ContentType
25 23
from django.contrib.auth import get_user_model
24
from django.contrib.contenttypes.models import ContentType
25
from django.core.exceptions import ValidationError
26 26
from django.db.models.query import Q
27 27
from django.utils import six
28 28
from django.utils.text import slugify
29
from django.core.exceptions import ValidationError
30

  
31
from authentic2.passwords import generate_password
32
from authentic2.utils import send_templated_mail
33
from authentic2.forms.fields import NewPasswordField, CheckPasswordField, ValidatedEmailField
34

  
35
from django_rbac.models import Operation
36
from django_rbac.utils import get_ou_model, get_role_model, get_permission_model
37
from django_rbac.backends import DjangoRBACBackend
29
from django.utils.translation import pgettext, ugettext
30
from django.utils.translation import ugettext_lazy as _
38 31

  
32
from authentic2 import app_settings as a2_app_settings
33
from authentic2.a2_rbac.utils import get_default_ou
34
from authentic2.forms.fields import (
35
    CheckPasswordField,
36
    NewPasswordField,
37
    ValidatedEmailField,
38
)
39 39
from authentic2.forms.profile import BaseUserForm
40 40
from authentic2.models import PasswordReset
41
from authentic2.utils import import_module_or_class
42
from authentic2.a2_rbac.utils import get_default_ou
43
from authentic2.utils import send_password_reset_mail, send_email_change_email
44
from authentic2 import app_settings as a2_app_settings
41
from authentic2.passwords import generate_password
42
from authentic2.utils import (
43
    import_module_or_class,
44
    send_email_change_email,
45
    send_password_reset_mail,
46
    send_templated_mail,
47
)
48
from django_rbac.backends import DjangoRBACBackend
49
from django_rbac.models import Operation
50
from django_rbac.utils import get_ou_model, get_permission_model, get_role_model
45 51

  
46
from . import fields, app_settings, utils
52
from . import app_settings, fields, utils
47 53

  
48 54
User = get_user_model()
49 55
OU = get_ou_model()
src/authentic2/manager/journal_event_types.py
17 17
from django.contrib.auth import get_user_model
18 18
from django.utils.translation import ugettext_lazy as _
19 19

  
20
from authentic2.journal_event_types import get_attributes_label, EventTypeWithService
21 20
from authentic2.apps.journal.models import EventTypeDefinition
22 21
from authentic2.apps.journal.utils import form_to_old_new
23

  
24

  
22
from authentic2.journal_event_types import EventTypeWithService, get_attributes_label
25 23
from django_rbac.utils import get_role_model
26 24

  
27 25
User = get_user_model()
src/authentic2/manager/ou_views.py
16 16

  
17 17
import json
18 18

  
19
from django_rbac.utils import get_ou_model
20
from django.http import HttpResponseRedirect
21 19
from django.contrib import messages
22 20
from django.core.exceptions import PermissionDenied, ValidationError
23 21
from django.db import transaction
22
from django.http import HttpResponseRedirect
24 23
from django.urls import reverse
25 24
from django.utils import six
26 25
from django.utils.translation import ugettext as _
27 26
from django.views.generic import FormView
28 27

  
29 28
from authentic2 import data_transfer
29
from django_rbac.utils import get_ou_model
30 30

  
31
from . import tables, views, forms
31
from . import forms, tables, views
32 32

  
33 33

  
34 34
class OrganizationalUnitView(views.BaseTableView):
src/authentic2/manager/resources.py
16 16

  
17 17
from django.contrib.auth import get_user_model
18 18
from django.utils import six
19

  
20
from import_export.resources import ModelResource
21 19
from import_export.fields import Field
20
from import_export.resources import ModelResource
22 21
from import_export.widgets import Widget
23 22

  
24 23
from authentic2.a2_rbac.models import Role
src/authentic2/manager/role_views.py
16 16

  
17 17
import json
18 18

  
19
from django.core.exceptions import PermissionDenied, ValidationError
20
from django.utils.functional import cached_property
21
from django.utils.translation import ugettext_lazy as _
22
from django.urls import reverse
23
from django.views.generic import FormView, TemplateView
24
from django.views.generic.detail import SingleObjectMixin
25 19
from django.contrib import messages
20
from django.contrib.auth import get_user_model
26 21
from django.contrib.contenttypes.models import ContentType
22
from django.core.exceptions import PermissionDenied, ValidationError
27 23
from django.db import transaction
28
from django.db.models.query import Q, Prefetch
29 24
from django.db.models import Count, F
30
from django.contrib.auth import get_user_model
25
from django.db.models.query import Prefetch, Q
31 26
from django.shortcuts import get_object_or_404
27
from django.urls import reverse
28
from django.utils.functional import cached_property
29
from django.utils.translation import ugettext_lazy as _
30
from django.views.generic import FormView, TemplateView
31
from django.views.generic.detail import SingleObjectMixin
32 32

  
33
from django_rbac.utils import get_role_model, get_permission_model, get_ou_model
34

  
33
from authentic2 import data_transfer, hooks
34
from authentic2.apps.journal.views import JournalViewWithContext
35 35
from authentic2.forms.profile import modelform_factory
36 36
from authentic2.utils import redirect
37
from authentic2 import hooks, data_transfer
38
from authentic2.apps.journal.views import JournalViewWithContext
37
from django_rbac.utils import get_ou_model, get_permission_model, get_role_model
39 38

  
40
from . import tables, views, resources, forms, app_settings
41
from .utils import has_show_username
39
from . import app_settings, forms, resources, tables, views
42 40
from .journal_views import BaseJournalView
41
from .utils import has_show_username
43 42

  
44 43
OU = get_ou_model()
45 44

  
src/authentic2/manager/service_views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.contrib import messages
17 18
from django.utils import six
18 19
from django.utils.translation import ugettext as _
19
from django.contrib import messages
20 20

  
21 21
from authentic2.models import Service
22 22

  
23
from . import tables, views, forms, role_views
23
from . import forms, role_views, tables, views
24 24

  
25 25

  
26 26
class ServicesView(views.HideOUColumnMixin, views.BaseTableView):
src/authentic2/manager/tables.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import django_tables2 as tables
17 18
from django.contrib.auth import get_user_model
18 19
from django.utils import html
19 20
from django.utils.safestring import SafeText
20 21
from django.utils.translation import ugettext_lazy as _
21 22
from django.utils.translation import ugettext_noop
22

  
23
import django_tables2 as tables
24 23
from django_tables2.utils import A
25 24

  
26
from django_rbac.utils import get_role_model, get_permission_model, get_ou_model
27

  
28
from authentic2.models import Service
29 25
from authentic2.middleware import StoreRequestMiddleware
26
from authentic2.models import Service
30 27
from authentic2_idp_oidc.models import OIDCAuthorization
28
from django_rbac.utils import get_ou_model, get_permission_model, get_role_model
31 29

  
32 30
User = get_user_model()
33 31

  
src/authentic2/manager/urls.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.conf.urls import url
18

  
19
from django.views.i18n import JavaScriptCatalog
20 18
from django.contrib.auth.decorators import login_required
21 19
from django.utils.functional import lazy
22
from . import views, role_views, ou_views, user_views, service_views, journal_views
23
from ..decorators import required
20
from django.views.i18n import JavaScriptCatalog
21

  
24 22
from authentic2 import utils
25 23

  
24
from ..decorators import required
25
from . import journal_views, ou_views, role_views, service_views, user_views, views
26

  
26 27

  
27 28
def manager_login_required(func):
28 29
    return login_required(func, login_url=lazy(utils.get_manager_login_url, str)())
src/authentic2/manager/user_import.py
23 23
import os
24 24
import pickle
25 25
import shutil
26
import uuid
27 26
import threading
28

  
27
import uuid
29 28

  
30 29
from atomicwrites import AtomicWriter
31

  
30
from django.conf import settings
32 31
from django.core.files.storage import default_storage
33 32
from django.db import connection
34
from django.conf import settings
35 33
from django.utils import six
36 34
from django.utils.encoding import force_text
37 35
from django.utils.functional import cached_property
src/authentic2/manager/user_views.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import base64
18
import datetime
19 18
import collections
19
import datetime
20 20
import operator
21 21

  
22
from django.db import models, transaction
23
from django.utils.functional import cached_property
24
from django.utils.translation import ugettext_lazy as _, pgettext_lazy, ugettext
25
from django.utils.html import format_html
26
from django.urls import reverse, reverse_lazy
22
import tablib
23
from django.contrib import messages
24
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
25
from django.contrib.contenttypes.models import ContentType
27 26
from django.core.exceptions import PermissionDenied
28 27
from django.core.mail import EmailMultiAlternatives
28
from django.db import models, transaction
29
from django.http import FileResponse, Http404, HttpResponseRedirect
30
from django.shortcuts import get_object_or_404
29 31
from django.template import loader
30
from django.contrib.auth import get_user_model, REDIRECT_FIELD_NAME
31
from django.contrib.contenttypes.models import ContentType
32
from django.contrib import messages
33
from django.views.generic import FormView, TemplateView, DetailView
34
from django.views.generic.edit import BaseFormView
32
from django.urls import reverse, reverse_lazy
33
from django.utils.functional import cached_property
34
from django.utils.html import format_html
35
from django.utils.translation import pgettext_lazy, ugettext
36
from django.utils.translation import ugettext_lazy as _
37
from django.views.generic import DetailView, FormView, TemplateView
35 38
from django.views.generic.detail import SingleObjectMixin
36
from django.http import Http404, FileResponse, HttpResponseRedirect
37
from django.shortcuts import get_object_or_404
38

  
39
import tablib
39
from django.views.generic.edit import BaseFormView
40 40

  
41
from authentic2.models import Attribute, AttributeValue, PasswordReset
42
from authentic2.utils import send_password_reset_mail, redirect, select_next_url, make_url, switch_user
43
from authentic2.a2_rbac.utils import get_default_ou
44 41
from authentic2 import hooks
45
from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient
42
from authentic2.a2_rbac.utils import get_default_ou
46 43
from authentic2.apps.journal.views import JournalViewWithContext
47

  
48
from django_rbac.utils import get_role_model, get_role_parenting_model, get_ou_model
49

  
50
from .views import (
51
    BaseTableView,
52
    BaseAddView,
53
    BaseEditView,
54
    ActionMixin,
55
    OtherActionsMixin,
56
    Action,
57
    ExportMixin,
58
    BaseSubTableView,
59
    HideOUColumnMixin,
60
    BaseDeleteView,
61
    BaseDetailView,
62
    TitleMixin,
63
    PermissionMixin,
64
    MediaMixin,
65
    FormNeedsRequest,
44
from authentic2.models import Attribute, AttributeValue, PasswordReset
45
from authentic2.utils import (
46
    make_url,
47
    redirect,
48
    select_next_url,
49
    send_password_reset_mail,
50
    switch_user,
66 51
)
67
from .tables import UserTable, UserRolesTable, OuUserRolesTable, UserAuthorizationsTable
52
from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient
53
from django_rbac.utils import get_ou_model, get_role_model, get_role_parenting_model
54

  
55
from . import app_settings
68 56
from .forms import (
69
    UserSearchForm,
70
    UserAddForm,
71
    UserEditForm,
72
    UserChangePasswordForm,
57
    ChooseUserAuthorizationsForm,
73 58
    ChooseUserRoleForm,
74
    UserRoleSearchForm,
59
    UserAddChooseOUForm,
60
    UserAddForm,
75 61
    UserChangeEmailForm,
76
    UserNewImportForm,
62
    UserChangePasswordForm,
63
    UserEditForm,
77 64
    UserEditImportForm,
78
    ChooseUserAuthorizationsForm,
79
    UserAddChooseOUForm,
65
    UserNewImportForm,
66
    UserRoleSearchForm,
67
    UserSearchForm,
80 68
)
69
from .journal_views import BaseJournalView
81 70
from .resources import UserResource
71
from .tables import OuUserRolesTable, UserAuthorizationsTable, UserRolesTable, UserTable
82 72
from .utils import get_ou_count, has_show_username
83
from .journal_views import BaseJournalView
84
from . import app_settings
73
from .views import (
74
    Action,
75
    ActionMixin,
76
    BaseAddView,
77
    BaseDeleteView,
78
    BaseDetailView,
79
    BaseEditView,
80
    BaseSubTableView,
81
    BaseTableView,
82
    ExportMixin,
83
    FormNeedsRequest,
84
    HideOUColumnMixin,
85
    MediaMixin,
86
    OtherActionsMixin,
87
    PermissionMixin,
88
    TitleMixin,
89
)
85 90

  
86 91
User = get_user_model()
87 92
OU = get_ou_model()
src/authentic2/manager/utils.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django_rbac.utils import get_ou_model
18

  
19 17
from authentic2.decorators import GlobalCache
18
from django_rbac.utils import get_ou_model
20 19

  
21 20
OU = get_ou_model()
22 21

  
src/authentic2/manager/views.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import base64
18
import json
19 18
import itertools
19
import json
20 20
import pickle
21 21

  
22
from django.contrib.messages.views import SuccessMessageMixin
22 23
from django.core import signing
23 24
from django.core.exceptions import PermissionDenied, ValidationError
24 25
from django.db import transaction
25
from django.views.generic.base import ContextMixin
26
from django.views.generic import FormView, UpdateView, CreateView, DeleteView, TemplateView, DetailView, View
27
from django.views.generic.detail import SingleObjectMixin
28
from django.views.generic.edit import FormMixin
29
from django.http import HttpResponse, Http404
30
from django.utils.encoding import force_text
26
from django.forms import MediaDefiningClass
27
from django.http import Http404, HttpResponse
28
from django.urls import reverse, reverse_lazy
31 29
from django.utils import six
30
from django.utils.encoding import force_text
32 31
from django.utils.functional import cached_property
33
from django.utils.translation import ugettext_lazy as _
34 32
from django.utils.timezone import now
35
from django.urls import reverse
36
from django.urls import reverse_lazy
37
from django.contrib.messages.views import SuccessMessageMixin
38
from django.forms import MediaDefiningClass
39

  
40
from django_tables2 import SingleTableView, SingleTableMixin
41

  
33
from django.utils.translation import ugettext_lazy as _
34
from django.views.generic import (
35
    CreateView,
36
    DeleteView,
37
    DetailView,
38
    FormView,
39
    TemplateView,
40
    UpdateView,
41
    View,
42
)
43
from django.views.generic.base import ContextMixin
44
from django.views.generic.detail import SingleObjectMixin
45
from django.views.generic.edit import FormMixin
42 46
from django_select2.views import AutoResponseView
43

  
47
from django_tables2 import SingleTableMixin, SingleTableView
44 48
from gadjo.templatetags.gadjo import xstatic
45 49

  
46
from django_rbac.utils import get_ou_model
47

  
50
from authentic2 import hooks
48 51
from authentic2.a2_rbac.models import OrganizationalUnit as OU
49
from authentic2.data_transfer import export_site, import_site, ImportContext
50
from authentic2.forms.profile import modelform_factory
51
from authentic2.utils import redirect, batch_queryset
52
from authentic2.data_transfer import ImportContext, export_site, import_site
52 53
from authentic2.decorators import json as json_view
53
from authentic2 import hooks
54
from authentic2.forms.profile import modelform_factory
55
from authentic2.utils import batch_queryset, redirect
56
from django_rbac.utils import get_ou_model
54 57

  
55
from . import app_settings, utils, forms, widgets
58
from . import app_settings, forms, utils, widgets
56 59

  
57 60

  
58 61
class MediaMixinBase(MediaDefiningClass, FormMixin):
src/authentic2/manager/widgets.py
18 18
import operator
19 19
import pickle
20 20

  
21
from django_select2.forms import ModelSelect2Widget, ModelSelect2MultipleWidget
22

  
23 21
from django.contrib.auth import get_user_model
24 22
from django.core import signing
25 23
from django.utils import six
26 24
from django.utils.encoding import force_text
27

  
28
from django_rbac.utils import get_role_model, get_ou_model
25
from django_select2.forms import ModelSelect2MultipleWidget, ModelSelect2Widget
29 26

  
30 27
from authentic2.models import Service
31 28
from authentic2_idp_oidc.models import OIDCAuthorization
29
from django_rbac.utils import get_ou_model, get_role_model
32 30

  
33 31
from . import utils
34 32

  
src/authentic2/managers.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from datetime import timedelta
18 17
import logging
18
from datetime import timedelta
19 19

  
20

  
21
from django.db import models
22
from django.db.models.query import QuerySet
23
from django.utils.timezone import now
24 20
from django.conf import settings
25 21
from django.contrib.contenttypes.models import ContentType
26 22
from django.contrib.postgres.search import SearchVector
23
from django.db import models
24
from django.db.models.query import QuerySet
25
from django.utils.timezone import now
26
from model_utils import managers
27 27

  
28 28
from django_rbac.utils import get_ou_model
29
from model_utils import managers
30 29

  
31 30
logger = logging.getLogger(__name__)
32 31

  
src/authentic2/middleware.py
21 21
except ImportError:
22 22
    threading = None
23 23

  
24
from django import http
24 25
from django.conf import settings
25 26
from django.contrib import messages
26 27
from django.utils.deprecation import MiddlewareMixin
27 28
from django.utils.functional import SimpleLazyObject
28
from django.utils.translation import ugettext as _
29 29
from django.utils.six.moves.urllib import parse as urlparse
30
from django import http
30
from django.utils.translation import ugettext as _
31 31

  
32
from . import app_settings, utils, plugins
32
from . import app_settings, plugins, utils
33 33
from .utils.service import get_service_from_request, get_service_from_session
34 34

  
35 35

  
......
107 107
    def check_view_restrictions(self, request):
108 108
        '''Check if a restriction on accessible views must be applied'''
109 109
        from django.db.models import Model
110

  
110 111
        from .models import PasswordReset
111 112

  
112 113
        user = request.user
src/authentic2/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/migrations/0002_auto_20150320_1418.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/migrations/0003_auto_20150409_1840.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0004_service.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/migrations/0005_service_ou.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0006_conditional_slug_index.py
2 2
from __future__ import unicode_literals
3 3

  
4 4
from django.db import migrations
5

  
5 6
from authentic2.migrations import CreatePartialIndexes
6 7

  
7 8

  
src/authentic2/migrations/0007_auto_20150523_0028.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0008_auto_20160204_1415.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0009_auto_20160211_2247.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def deduplicate_attribute_values(apps, schema_editor):
src/authentic2/migrations/0010_attributevalue_multiple.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/migrations/0011_auto_20160211_2253.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def fill_attribute_value_multiple(apps, schema_editor):
src/authentic2/migrations/0012_auto_20160211_2255.py
2 2
from __future__ import unicode_literals
3 3

  
4 4
import django
5
from django.db import models, migrations
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0013_auto_20160211_2258.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6
from authentic2.migrations import CreatePartialIndexes
7 7

  
src/authentic2/migrations/0015_auto_20160621_1711.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import migrations, models
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0018_auto_20170524_0842.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import migrations, models
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0021_attribute_order.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import migrations, models
5 4
import django.db.models.manager
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2/migrations/0025_auto_20191009_1047.py
2 2
# Generated by Django 1.11.20 on 2019-10-09 08:47
3 3
from __future__ import unicode_literals
4 4

  
5
import django.db.models.deletion
5 6
from django.conf import settings
6 7
from django.db import migrations, models
7
import django.db.models.deletion
8 8

  
9 9

  
10 10
class Migration(migrations.Migration):
src/authentic2/migrations/0026_token.py
2 2
# Generated by Django 1.11.20 on 2020-02-11 10:27
3 3
from __future__ import unicode_literals
4 4

  
5
import uuid
6

  
5 7
import django.contrib.postgres.fields.jsonb
6 8
from django.db import migrations, models
7
import uuid
8 9

  
9 10

  
10 11
class Migration(migrations.Migration):
src/authentic2/migrations/0030_clean_admin_tools_tables.py
1
from django.db import migrations
2 1
import logging
3 2

  
3
from django.db import migrations
4

  
4 5

  
5 6
def noop(apps, schema_editor):
6 7
    pass
src/authentic2/models.py
19 19
import uuid
20 20

  
21 21
import django
22
from django.utils.http import urlquote
23 22
from django.conf import settings
23
from django.contrib.contenttypes.models import ContentType
24
from django.contrib.postgres.fields import jsonb
25
from django.contrib.postgres.indexes import GinIndex
26
from django.contrib.postgres.search import SearchVectorField
27
from django.core.exceptions import ValidationError
24 28
from django.db import models, transaction
25 29
from django.db.models.query import Q
26 30
from django.utils import six, timezone
27
from django.utils.translation import ugettext_lazy as _
31
from django.utils.http import urlquote
28 32
from django.utils.six.moves.urllib import parse as urlparse
29
from django.core.exceptions import ValidationError
30
from django.contrib.contenttypes.models import ContentType
31
from django.contrib.postgres.fields import jsonb
32
from django.contrib.postgres.search import SearchVectorField
33
from django.contrib.postgres.indexes import GinIndex
34

  
33
from django.utils.translation import ugettext_lazy as _
35 34
from model_utils.managers import QueryManager
36 35

  
37 36
from authentic2.a2_rbac.models import Role
38
from authentic2.crypto import base64url_encode, base64url_decode
37
from authentic2.crypto import base64url_decode, base64url_encode
39 38
from django_rbac.utils import get_role_model_name
40 39

  
41 40
try:
......
43 42
except ImportError:
44 43
    from django.contrib.contenttypes.generic import GenericForeignKey
45 44

  
46
from . import managers
47

  
48 45
# install our natural_key implementation
46
from . import managers
49 47
from . import natural_key as unused_natural_key  # noqa: F401
50 48
from .utils import ServiceAccessDenied
51 49

  
......
180 178

  
181 179
    def get_drf_field(self, **kwargs):
182 180
        from rest_framework import serializers
181

  
183 182
        from authentic2.attribute_kinds import DateRestField
184 183

  
185 184
        kind = self.get_kind()
src/authentic2/natural_key.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.db import models
18

  
19
from django.contrib.contenttypes.models import ContentType
20 17
from django.contrib.contenttypes.fields import GenericForeignKey
18
from django.contrib.contenttypes.models import ContentType
19
from django.db import models
21 20

  
22 21

  
23 22
def get_natural_keys(model):
src/authentic2/nonce/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/nonce/utils.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import os.path
18 17
import datetime as dt
19
from calendar import timegm
20
import tempfile
21
import glob
22 18
import errno
19
import glob
20
import os.path
21
import tempfile
22
from calendar import timegm
23 23

  
24 24
from django.conf import settings
25 25

  
src/authentic2/passwords.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import string
17
import abc
18 18
import random
19 19
import re
20
import abc
20
import string
21 21

  
22
from django.utils.translation import ugettext as _
23
from django.utils.module_loading import import_string
24
from django.utils.functional import lazy
25
from django.utils import six
26 22
from django.core.exceptions import ValidationError
27

  
23
from django.utils import six
24
from django.utils.functional import lazy
25
from django.utils.module_loading import import_string
26
from django.utils.translation import ugettext as _
28 27

  
29 28
from . import app_settings
30 29

  
src/authentic2/plugins.py
19 19

  
20 20
    Propose helper methods to load urls from plugins or modify INSTALLED_APPS
21 21
"""
22
import pkg_resources
23 22
import logging
24 23

  
24
import pkg_resources
25 25
from django.apps import apps
26 26
from django.conf.urls import include, url
27 27

  
28

  
29 28
logger = logging.getLogger(__name__)
30 29

  
31 30

  
src/authentic2/saml/admin.py
16 16

  
17 17
import logging
18 18

  
19
from django.contrib import admin
20
from django.utils import six
21
from django.utils.translation import ugettext as _
22
from django.conf.urls import url
23
from django.conf import settings
24
from django.forms import ModelForm
25 19
from django import forms
26
from django.contrib import messages
20
from django.conf import settings
21
from django.conf.urls import url
22
from django.contrib import admin, messages
27 23
from django.core.exceptions import ValidationError
24
from django.forms import ModelForm
25
from django.utils import six
26
from django.utils.translation import ugettext as _
28 27

  
29 28
try:
30 29
    from django.contrib.contenttypes.admin import GenericTabularInline
31 30
except ImportError:
32 31
    from django.contrib.contenttypes.generic import GenericTabularInline
33 32

  
33
from authentic2.attributes_ng.engine import get_service_attributes
34 34
from authentic2.saml.models import (
35
    KeyValue,
36
    LibertyFederation,
35 37
    LibertyProvider,
36 38
    LibertyServiceProvider,
37
    SPOptionsIdPPolicy,
38
    LibertyFederation,
39
    KeyValue,
40 39
    LibertySession,
41 40
    SAMLAttribute,
41
    SPOptionsIdPPolicy,
42 42
)
43 43

  
44
from authentic2.attributes_ng.engine import get_service_attributes
45

  
46 44
from . import admin_views
47 45

  
48 46
logger = logging.getLogger(__name__)
src/authentic2/saml/admin_views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.views.generic import FormView
18 17
from django.urls import reverse
18
from django.views.generic import FormView
19 19

  
20 20
from .forms import AddLibertyProviderFromUrlForm
21 21

  
src/authentic2/saml/common.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import os.path
17
import datetime
18 18
import logging
19
import os.path
19 20
import re
20
import datetime
21 21

  
22 22
import requests
23

  
24
from authentic2.compat_lasso import lasso
25 23
from django.conf import settings
26
from django.http import HttpResponseRedirect, Http404, HttpResponse
24
from django.core.exceptions import ValidationError
25
from django.http import Http404, HttpResponse, HttpResponseRedirect
27 26
from django.shortcuts import render
27
from django.urls import reverse
28 28
from django.utils import six
29 29
from django.utils.encoding import force_text
30 30
from django.utils.six.moves.urllib import parse as urlparse
31
from django.core.exceptions import ValidationError
32
from django.urls import reverse
33 31

  
32
from authentic2.compat_lasso import lasso
33
from authentic2.decorators import RequestCache
34
from authentic2.http_utils import get_url
35
from authentic2.idp.saml import app_settings
36
from authentic2.saml import models, saml2utils
34 37
from authentic2.saml.models import (
35 38
    LibertyFederation,
36 39
    LibertyProvider,
37 40
    LibertyServiceProvider,
38 41
    SPOptionsIdPPolicy,
39 42
)
40
from authentic2.saml import models
41
from authentic2.saml import saml2utils
42 43

  
43
from authentic2.http_utils import get_url
44
from authentic2.decorators import RequestCache
45
from authentic2.idp.saml import app_settings
46 44
from .. import nonce
47 45

  
48 46
AUTHENTIC_STATUS_CODE_NS = "http://authentic.entrouvert.org/status_code/"
src/authentic2/saml/fields.py
23 23

  
24 24
import django
25 25
from django import forms
26
from django.db import models
26
from django.contrib.humanize.templatetags.humanize import apnumber
27 27
from django.core.exceptions import ValidationError
28
from django.db import models
29
from django.template.defaultfilters import pluralize
28 30
from django.utils import six
29
from django.utils.text import capfirst
30 31
from django.utils.encoding import force_bytes, force_text
31
from django.contrib.humanize.templatetags.humanize import apnumber
32
from django.template.defaultfilters import pluralize
32
from django.utils.text import capfirst
33 33

  
34 34

  
35 35
def loads(value):
src/authentic2/saml/forms.py
17 17
import xml.etree.ElementTree as ET
18 18

  
19 19
import requests
20

  
21
from authentic2.compat_lasso import lasso
22

  
23 20
from django import forms
24 21
from django.core.exceptions import ValidationError
25 22
from django.utils.translation import ugettext_lazy as _
26 23

  
27
from .models import LibertyProvider, LibertyServiceProvider
28

  
29 24
from authentic2.a2_rbac.utils import get_default_ou
30

  
25
from authentic2.compat_lasso import lasso
31 26
from django_rbac.utils import get_ou_model
32 27

  
28
from .models import LibertyProvider, LibertyServiceProvider
29

  
33 30

  
34 31
class AddLibertyProviderFromUrlForm(forms.Form):
35 32
    name = forms.CharField(max_length=140, label=_('Name'))
src/authentic2/saml/lasso_helper.py
16 16

  
17 17
import xml.etree.ElementTree as etree
18 18

  
19

  
20 19
LASSO_NS = 'http://www.entrouvert.org/namespaces/lasso/0.0'
21 20
SAML_ASSERTION_NS = 'urn:oasis:names:tc:SAML:2.0:assertion'
22 21

  
src/authentic2/saml/management/commands/sync-metadata.py
16 16

  
17 17
from __future__ import print_function
18 18

  
19
import sys
20
import xml.etree.ElementTree as etree
21 19
import os
22
import requests
20
import sys
23 21
import warnings
22
import xml.etree.ElementTree as etree
24 23

  
24
import requests
25
from django.contrib.contenttypes.models import ContentType
25 26
from django.core.management.base import BaseCommand, CommandError
26 27
from django.db.transaction import atomic
27 28
from django.template.defaultfilters import slugify
28 29
from django.utils import six
29 30
from django.utils.translation import gettext as _
30
from django.contrib.contenttypes.models import ContentType
31 31

  
32 32
from authentic2.compat_lasso import lasso
33
from authentic2.saml.models import (
34
    LibertyProvider,
35
    LibertyServiceProvider,
36
    SAMLAttribute,
37
    SPOptionsIdPPolicy,
38
)
33 39
from authentic2.saml.shibboleth.afp_parser import parse_attribute_filters_file
34
from authentic2.saml.models import LibertyProvider, SAMLAttribute, LibertyServiceProvider, SPOptionsIdPPolicy
35 40

  
36 41
from .mapping import (
42
    get_def_name_from_alias,
37 43
    get_def_name_from_oid,
44
    get_definition_from_alias,
38 45
    get_definition_from_oid,
39 46
    get_full_definition,
40
    get_definition_from_alias,
41
    get_def_name_from_alias,
42 47
)
43 48

  
44 49
SAML2_METADATA_UI_HREF = 'urn:oasis:names:tc:SAML:metadata:ui'
src/authentic2/saml/managers.py
17 17
import base64
18 18
import binascii
19 19
import datetime
20

  
20
from importlib import import_module
21 21

  
22 22
from django.conf import settings
23
from django.contrib.contenttypes.models import ContentType
23 24
from django.db import models
24 25
from django.db.models.query import QuerySet
25 26
from django.dispatch import Signal
26 27
from django.utils.timezone import now
27
from importlib import import_module
28
from django.contrib.contenttypes.models import ContentType
29

  
30 28

  
29
from ..managers import GenericManager, GetBySlugQuerySet
31 30
from . import lasso_helper
32
from ..managers import GetBySlugQuerySet, GenericManager
33 31

  
34 32
federation_delete = Signal()
35 33

  
src/authentic2/saml/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5
import authentic2.saml.models
6 4
import django.db.models.deletion
5
from django.db import migrations, models
6

  
7 7
import authentic2.saml.fields
8
import authentic2.saml.models
8 9

  
9 10

  
10 11
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0002_auto_20150320_1245.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0003_merge.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0004_auto_20150410_1438.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
import django.db.models.deletion
6 5
from django.conf import settings
6
from django.db import migrations, models
7 7

  
8 8

  
9 9
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0005_make_liberty_provider_inherit_from_service.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0006_restore_foreign_keys.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def create_services(apps, schema_editor):
src/authentic2/saml/migrations/0007_copy_service_ptr_id_to_old_id.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0008_alter_foreign_keys.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def alter_foreign_keys(apps, schema_editor):
src/authentic2/saml/migrations/0009_auto.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0010_auto.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def noop(apps, schema_editor):
src/authentic2/saml/migrations/0011_auto.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0012_auto_20150526_2239.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0013_auto_20150617_1004.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def noop(apps, schema_editor):
src/authentic2/saml/migrations/0014_auto_20150617_1216.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/migrations/0015_auto_20150915_2032.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5

  
5 6
import authentic2.saml.fields
6 7

  
7 8

  
src/authentic2/saml/migrations/0016_auto_20150915_2041.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2/saml/models.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import collections
18

  
19
import xml.etree.ElementTree as etree
20 18
import hashlib
19
import xml.etree.ElementTree as etree
21 20

  
22 21
import requests
23
from authentic2.compat_lasso import lasso
24
from authentic2.utils import normalize_attribute_values
25

  
22
from django.conf import settings
23
from django.contrib.contenttypes.models import ContentType
24
from django.core.exceptions import ObjectDoesNotExist, ValidationError
26 25
from django.db import models
27 26
from django.db.models import Q
28 27
from django.db.models.query import QuerySet
29
from django.conf import settings
30
from django.core.exceptions import ValidationError
31 28
from django.utils import six
32
from django.utils.encoding import force_str
33
from django.utils.encoding import force_text
29
from django.utils.encoding import force_str, force_text
34 30
from django.utils.translation import ugettext_lazy as _
35
from django.core.exceptions import ObjectDoesNotExist
36
from django.contrib.contenttypes.models import ContentType
31

  
32
from authentic2.compat_lasso import lasso
33
from authentic2.utils import normalize_attribute_values
37 34

  
38 35
try:
39 36
    from django.contrib.contenttypes.fields import GenericForeignKey
......
44 41
except ImportError:
45 42
    from django.contrib.contenttypes.generic import GenericRelation
46 43

  
47
from authentic2.saml.fields import PickledObjectField, MultiSelectField
44
from authentic2.saml.fields import MultiSelectField, PickledObjectField
48 45

  
49
from . import app_settings, managers
50 46
from .. import managers as a2_managers
51 47
from ..models import Service
48
from . import app_settings, managers
52 49

  
53 50

  
54 51
def metadata_validator(meta):
src/authentic2/saml/saml2utils.py
16 16

  
17 17
from __future__ import print_function
18 18

  
19
import xml.etree.ElementTree as etree
20
import collections
21
from authentic2.compat_lasso import lasso
22
from authentic2.saml import x509utils
23 19
import base64
24 20
import binascii
25
import re
21
import collections
26 22
import datetime
23
import re
27 24
import time
25
import xml.etree.ElementTree as etree
28 26

  
29 27
from django.utils import six
30 28
from django.utils.encoding import force_text
31 29

  
30
from authentic2.compat_lasso import lasso
31
from authentic2.saml import x509utils
32

  
32 33

  
33 34
def filter_attribute_private_key(message):
34 35
    if isinstance(message, six.string_types):
src/authentic2/saml/x509utils.py
16 16

  
17 17
import base64
18 18
import binascii
19
import tempfile
20 19
import os
21 20
import subprocess
21
import tempfile
22

  
22 23
import six
23 24

  
24 25
_openssl = 'openssl'
src/authentic2/serializers.py
17 17
import json
18 18
import sys
19 19

  
20
from django.utils import six
21
from django.core.serializers.json import Serializer as JSONSerializer
22
from django.core.serializers.python import _get_model
23
from django.core.serializers.base import DeserializationError
24 20
from django.contrib.contenttypes.fields import GenericForeignKey
25 21
from django.contrib.contenttypes.models import ContentType
22
from django.core.serializers.base import DeserializationError
23
from django.core.serializers.json import Serializer as JSONSerializer
24
from django.core.serializers.python import _get_model
26 25
from django.db import DEFAULT_DB_ALIAS
26
from django.utils import six
27 27

  
28 28

  
29 29
class Serializer(JSONSerializer):
src/authentic2/settings.py
16 16

  
17 17
import logging
18 18
import logging.config
19
import os
19 20

  
20 21
# Load default from Django
21 22
from django.conf import global_settings
22
import os
23

  
24

  
25 23
from gadjo.templatetags.gadjo import xstatic
26
from . import plugins, logger
24

  
25
from . import logger, plugins
27 26

  
28 27
# debian/debian_config.py::extract_settings_from_environ expects CACHES to be in its NAMESPACE
29 28
CACHES = global_settings.CACHES
src/authentic2/urls.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.conf.urls import url, include
18 17
from django.conf import settings
18
from django.conf.urls import include, url
19 19
from django.contrib import admin
20
from django.contrib.auth.decorators import login_required
21 20
from django.contrib.auth import views as dj_auth_views
21
from django.contrib.auth.decorators import login_required
22 22
from django.contrib.staticfiles.views import serve
23 23
from django.utils.translation import ugettext_lazy as _
24
from django.views.decorators.clickjacking import xframe_options_deny
24 25
from django.views.generic.base import TemplateView
25 26
from django.views.static import serve as media_serve
26
from django.views.decorators.clickjacking import xframe_options_deny
27 27

  
28
from . import plugins, views
29
from authentic2.decorators import setting_enabled, required, lasso_required
28
import authentic2.idp.saml.app_settings
30 29
import authentic2_auth_fc.urls
31 30
import authentic2_auth_oidc.urls
32 31
import authentic2_auth_saml.urls
33 32
import authentic2_idp_cas.app_settings
34 33
import authentic2_idp_oidc.urls
35
import authentic2.idp.saml.app_settings
34
from authentic2.decorators import lasso_required, required, setting_enabled
36 35

  
36
from . import plugins, views
37 37

  
38 38
admin.autodiscover()
39 39

  
src/authentic2/user_login_failure.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import logging
18 17
import hashlib
18
import logging
19 19

  
20 20
from django.core.cache import cache
21 21
from django.utils.encoding import smart_bytes
src/authentic2/utils/__init__.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import copy
18
import ctypes
19
import datetime
17 20
import inspect
21
import logging
18 22
import random
19 23
import time
20
import logging
21 24
import uuid
22
import datetime
23
import copy
24
import ctypes
25

  
26 25
from functools import wraps
27
from itertools import islice, chain, count
28

  
29 26
from importlib import import_module
27
from itertools import chain, count, islice
30 28

  
31 29
import django.apps
30
from django import forms
32 31
from django.conf import settings
33
from django.core.mail import EmailMessage
34
from django.http import HttpResponseRedirect, HttpResponse
32
from django.contrib.auth import REDIRECT_FIELD_NAME
33
from django.contrib.auth import authenticate as dj_authenticate
34
from django.contrib.auth import get_user_model
35
from django.contrib.auth import login as auth_login
36
from django.core import signing
37
from django.core.cache import cache
35 38
from django.core.exceptions import ImproperlyConfigured
36
from django.http.request import QueryDict
37
from django.contrib.auth import (
38
    REDIRECT_FIELD_NAME,
39
    login as auth_login,
40
    authenticate as dj_authenticate,
41
    get_user_model,
42
)
43
from django import forms
39
from django.core.mail import EmailMessage, send_mail
44 40
from django.forms.utils import ErrorList, to_current_timezone
45
from django.utils import timezone
46
from django.utils import html, six
47
from django.utils.translation import ugettext as _, ungettext
48
from django.utils.six.moves.urllib import parse as urlparse
49
from django.shortcuts import resolve_url
50
from django.template.loader import render_to_string, TemplateDoesNotExist, select_template
41
from django.http import HttpResponse, HttpResponseRedirect
42
from django.http.request import QueryDict
43
from django.shortcuts import render, resolve_url
51 44
from django.template.context import make_context
52
from django.core.mail import send_mail
53
from django.core import signing
54
from django.core.cache import cache
45
from django.template.loader import (
46
    TemplateDoesNotExist,
47
    render_to_string,
48
    select_template,
49
)
50
from django.urls import reverse
51
from django.utils import html, six, timezone
52
from django.utils.encoding import force_bytes, iri_to_uri, uri_to_iri
55 53
from django.utils.formats import localize
56 54
from django.utils.http import urlsafe_base64_encode
57
from django.utils.encoding import iri_to_uri, force_bytes, uri_to_iri
58
from django.urls import reverse
59
from django.shortcuts import render
55
from django.utils.six.moves.urllib import parse as urlparse
56
from django.utils.translation import ugettext as _
57
from django.utils.translation import ungettext
60 58

  
61 59
try:
62 60
    from django.core.exceptions import FieldDoesNotExist
......
64 62
    # Django < 1.8
65 63
    from django.db.models.fields import FieldDoesNotExist
66 64

  
67
from authentic2.saml.saml2utils import filter_attribute_private_key, filter_element_private_key
65
from authentic2.saml.saml2utils import (
66
    filter_attribute_private_key,
67
    filter_element_private_key,
68
)
68 69

  
69
from .. import plugins, app_settings, constants, crypto
70
from .. import app_settings, constants, crypto, plugins
70 71
from .service import set_service_ref
71 72

  
72 73

  
......
579 580
def check_session_key(session_key):
580 581
    '''Check that a session exists for a given session_key.'''
581 582
    from importlib import import_module
583

  
582 584
    from django.conf import settings
583 585

  
584 586
    SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
......
590 592
def get_user_from_session_key(session_key):
591 593
    '''Get the user logged in an active session'''
592 594
    from importlib import import_module
595

  
593 596
    from django.conf import settings
594
    from django.contrib.auth import load_backend, SESSION_KEY, BACKEND_SESSION_KEY
597
    from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, load_backend
595 598
    from django.contrib.auth.models import AnonymousUser
599

  
596 600
    from authentic2.compat.misc import signature_parameters
597 601

  
598 602
    SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
......
912 916
    sign_next_url=True,
913 917
    **kwargs,
914 918
):
915
    from .. import middleware
916 919
    from authentic2.journal import journal
917 920

  
921
    from .. import middleware
922

  
918 923
    if not user.email:
919 924
        raise ValueError('user must have an email')
920 925
    logger = logging.getLogger(__name__)
src/authentic2/utils/evaluate.py
22 22
    from functools import lru_cache
23 23
except ImportError:
24 24
    from django.utils.lru_cache import lru_cache
25
from django.utils.translation import ugettext as _
26
from django.utils import six
27

  
28 25

  
29 26
import ast
30 27

  
28
from django.utils import six
29
from django.utils.translation import ugettext as _
30

  
31 31

  
32 32
class HTTPHeaders:
33 33
    def __init__(self, request):
src/authentic2/utils/lazy.py
16 16

  
17 17
from __future__ import unicode_literals
18 18

  
19
from django.utils.encoding import force_text
20 19
from django.utils import six
21
from django.utils.text import format_lazy
22

  
20
from django.utils.encoding import force_text
23 21
from django.utils.functional import keep_lazy
22
from django.utils.text import format_lazy
24 23

  
25 24

  
26 25
def lazy_join(join, args):
src/authentic2/utils/lookups.py
1 1
from django.contrib.postgres.lookups import Unaccent as PGUnaccent
2 2
from django.db.models import Func
3
from django.db.models.functions import Concat, ConcatPair as DjConcatPair
3
from django.db.models.functions import Concat
4
from django.db.models.functions import ConcatPair as DjConcatPair
4 5

  
5 6

  
6 7
class Unaccent(PGUnaccent):
src/authentic2/utils/switch_user.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from authentic2.models import Token
18 17
from authentic2.custom_user.models import User
19

  
18
from authentic2.models import Token
20 19
from authentic2.utils import make_url
21 20

  
22 21

  
src/authentic2/utils/template.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.template import VariableDoesNotExist
18
from django.template import engines
19
from django.template import TemplateSyntaxError
17
from django.template import TemplateSyntaxError, VariableDoesNotExist, engines
20 18
from django.utils.encoding import force_str
21 19
from django.utils.translation import ugettext_lazy as _
22 20

  
src/authentic2/validators.py
19 19
import re
20 20
import smtplib
21 21

  
22
import dns.exception
23
import dns.resolver
24
from django.core.exceptions import ValidationError
25
from django.core.validators import EmailValidator as DjangoEmailValidator
26
from django.core.validators import RegexValidator
22 27
from django.utils.deconstruct import deconstructible
23 28
from django.utils.translation import ugettext_lazy as _
24
from django.core.exceptions import ValidationError
25
from django.core.validators import RegexValidator, EmailValidator as DjangoEmailValidator
26

  
27
import dns.resolver
28
import dns.exception
29 29

  
30 30
from . import app_settings
31 31

  
src/authentic2/views.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import collections
18
from email.utils import parseaddr
19 18
import logging
20 19
import re
20
from email.utils import parseaddr
21 21

  
22
from ratelimit.utils import is_ratelimited
23

  
24
from django.conf import settings
25
from django.shortcuts import render, get_object_or_404
26
from django.template.loader import render_to_string
27
from django.views.generic.edit import UpdateView, FormView
28
from django.views.generic import TemplateView
29
from django.views.generic.base import View
30 22
from django import shortcuts
31
from django.core import signing
32
from django.core.exceptions import ValidationError
23
from django.conf import settings
33 24
from django.contrib import messages
34
from django.utils import six, timezone
35
from django.utils.translation import ugettext as _
36
from django.urls import reverse
25
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
37 26
from django.contrib.auth import logout as auth_logout
38
from django.contrib.auth import REDIRECT_FIELD_NAME
39
from django.contrib.auth.views import PasswordChangeView as DjPasswordChangeView
40
from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse
41
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
42
from django.views.decorators.cache import never_cache
43 27
from django.contrib.auth.decorators import login_required
28
from django.contrib.auth.views import PasswordChangeView as DjPasswordChangeView
29
from django.core import signing
30
from django.core.exceptions import ValidationError
44 31
from django.db.models.fields import FieldDoesNotExist
45 32
from django.db.models.query import Q
46
from django.contrib.auth import get_user_model
47
from django.http import Http404
48
from django.utils.http import urlsafe_base64_decode
49
from django.views.generic.edit import CreateView
50 33
from django.forms import CharField
51
from django.http import HttpResponseBadRequest
34
from django.http import (
35
    Http404,
36
    HttpResponse,
37
    HttpResponseBadRequest,
38
    HttpResponseForbidden,
39
    HttpResponseRedirect,
40
)
41
from django.shortcuts import get_object_or_404, render
52 42
from django.template import loader
43
from django.template.loader import render_to_string
44
from django.urls import reverse
45
from django.utils import six, timezone
46
from django.utils.http import urlsafe_base64_decode
47
from django.utils.translation import ugettext as _
48
from django.views.decorators.cache import never_cache
49
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
50
from django.views.generic import TemplateView
51
from django.views.generic.base import View
52
from django.views.generic.edit import CreateView, FormView, UpdateView
53
from ratelimit.utils import is_ratelimited
53 54

  
54 55
from authentic2.custom_user.models import iter_attributes
55
from . import utils, app_settings, decorators, constants, models, cbv, hooks, validators, attribute_kinds
56
from .utils.service import get_service_from_request, get_service_from_token, set_service_ref
57
from .utils.evaluate import HTTPHeaders
58
from .utils import switch_user
59
from .a2_rbac.utils import get_default_ou
56

  
57
from . import (
58
    app_settings,
59
    attribute_kinds,
60
    cbv,
61
    constants,
62
    decorators,
63
    hooks,
64
    models,
65
    utils,
66
    validators,
67
)
60 68
from .a2_rbac.models import OrganizationalUnit as OU
61
from .forms import passwords as passwords_forms, registration as registration_forms, profile as profile_forms
69
from .a2_rbac.utils import get_default_ou
70
from .forms import passwords as passwords_forms
71
from .forms import profile as profile_forms
72
from .forms import registration as registration_forms
73
from .utils import switch_user
74
from .utils.evaluate import HTTPHeaders
75
from .utils.service import (
76
    get_service_from_request,
77
    get_service_from_token,
78
    set_service_ref,
79
)
62 80

  
63 81
User = get_user_model()
64 82

  
src/authentic2/wsgi.py
31 31
"""
32 32
import os
33 33

  
34
from django.core.wsgi import get_wsgi_application
35

  
34 36
# XXX: monkeypatch logging
35 37
from . import logger  # noqa: F401
36
from django.core.wsgi import get_wsgi_application
37 38

  
38 39
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "authentic2.settings")
39 40

  
src/authentic2_auth_fc/api_views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.shortcuts import get_object_or_404
18 17
from django.contrib.auth import get_user_model
19

  
20
from rest_framework.response import Response
18
from django.shortcuts import get_object_or_404
21 19
from rest_framework import status
22
from authentic2.compat.drf import action
20
from rest_framework.response import Response
23 21

  
24 22
from authentic2.api_views import DjangoPermission
23
from authentic2.compat.drf import action
25 24

  
26 25

  
27 26
@action(
src/authentic2_auth_fc/apps.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from . import app_settings
18

  
19

  
20 17
import django.apps
21 18
from django import template
22 19

  
20
from . import app_settings
21

  
23 22

  
24 23
class Plugin(object):
25 24
    def redirect_logout_list(self, request, **kwargs):
26 25
        from django.urls import reverse
26

  
27 27
        from . import utils
28 28

  
29 29
        url = utils.build_logout_url(request, next_url=reverse('auth_logout'))
......
48 48

  
49 49
    def a2_hook_api_modify_serializer(self, view, serializer):
50 50
        from rest_framework import serializers
51

  
51 52
        from authentic2.utils import make_url
53

  
52 54
        from . import app_settings
53 55

  
54 56
        if not app_settings.enable:
......
97 99
        return True
98 100

  
99 101
    def ready(self):
100
        from .api_views import fc_unlink
101 102
        from authentic2.api_views import UsersAPI
102 103

  
104
        from .api_views import fc_unlink
105

  
103 106
        UsersAPI.fc_unlink = fc_unlink
104 107

  
105 108
        from django.db.models.signals import pre_save
109

  
106 110
        from authentic2.custom_user.models import DeletedUser
107 111

  
108 112
        pre_save.connect(self.pre_save_deleted_user, sender=DeletedUser)
src/authentic2_auth_fc/authenticators.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.utils.translation import gettext_noop
18 17
from django.template.loader import render_to_string
19 18
from django.template.response import TemplateResponse
19
from django.utils.translation import gettext_noop
20 20

  
21
from authentic2 import app_settings as a2_app_settings, utils as a2_utils
21
from authentic2 import app_settings as a2_app_settings
22
from authentic2 import utils as a2_utils
22 23
from authentic2.authenticators import BaseAuthenticator
23 24
from authentic2.utils import redirect_to_login
24 25

  
src/authentic2_auth_fc/backends.py
19 19

  
20 20
from django.contrib.auth import get_user_model
21 21
from django.contrib.auth.backends import ModelBackend
22
from django.core.exceptions import PermissionDenied, MultipleObjectsReturned
22
from django.core.exceptions import MultipleObjectsReturned, PermissionDenied
23 23
from django.db import IntegrityError
24 24

  
25
from authentic2.a2_rbac.utils import get_default_ou
26 25
from authentic2 import hooks
26
from authentic2.a2_rbac.utils import get_default_ou
27 27

  
28
from . import models, app_settings, utils
28
from . import app_settings, models, utils
29 29

  
30 30
logger = logging.getLogger(__name__)
31 31

  
src/authentic2_auth_fc/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import migrations, models
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2_auth_fc/migrations/0002_auto_20200416_1439.py
2 2
# Generated by Django 1.11.29 on 2020-04-16 12:39
3 3
from __future__ import unicode_literals
4 4

  
5
from django.db import migrations, models
6 5
import django.utils.timezone
6
from django.db import migrations, models
7 7

  
8 8

  
9 9
class Migration(migrations.Migration):
src/authentic2_auth_fc/models.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import base64
18
import json
19
import hmac
20 18
import hashlib
19
import hmac
20
import json
21 21

  
22
from django.conf import settings
22 23
from django.db import models
23
from django.utils.encoding import force_bytes
24
from django.utils.encoding import force_text
24
from django.utils.encoding import force_bytes, force_text
25 25
from django.utils.six.moves.urllib import parse as urlparse
26
from django.utils.translation import ugettext_lazy as _
27 26
from django.utils.timezone import now
28
from django.conf import settings
27
from django.utils.translation import ugettext_lazy as _
29 28

  
30 29
from authentic2_auth_oidc.utils import parse_timestamp
31 30

  
src/authentic2_auth_fc/urls.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.conf.urls import url, include
17
from django.conf.urls import include, url
18 18

  
19 19
from . import views
20 20

  
src/authentic2_auth_fc/utils.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import datetime
18
import json
17 19
import logging
18 20
import os
19
import json
20
import datetime
21 21
import uuid
22 22

  
23 23
import requests
24
from requests.adapters import HTTPAdapter
25
from requests.packages.urllib3.util.retry import Retry
26

  
27 24
from django.conf import settings
28 25
from django.shortcuts import resolve_url
26
from django.urls import reverse
29 27
from django.utils.http import urlencode
30 28
from django.utils.translation import ugettext_lazy as _
31
from django.urls import reverse
29
from requests.adapters import HTTPAdapter
30
from requests.packages.urllib3.util.retry import Retry
32 31

  
33 32
from . import app_settings
34 33

  
src/authentic2_auth_fc/views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import uuid
18
import logging
19 17
import json
20
import requests
21

  
22
from requests_oauthlib import OAuth2Session
23

  
18
import logging
19
import uuid
24 20

  
25
from django.db import IntegrityError
26
from django.views.generic import View, FormView
27
from django.http import HttpResponseRedirect, Http404
28
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
29
from django.contrib import messages
30
from django.shortcuts import resolve_url, render
31
from django.urls import reverse
32
from django.utils.six.moves.urllib import parse as urlparse
33
from django.utils.translation import ugettext as _
34
from django.utils.http import is_safe_url, urlencode
21
import requests
35 22
from django.conf import settings
23
from django.contrib import messages
24
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
36 25
from django.core import signing
37 26
from django.core.cache import InvalidCacheBackendError, caches
38 27
from django.core.exceptions import PermissionDenied
28
from django.db import IntegrityError
39 29
from django.forms import Form
30
from django.http import Http404, HttpResponseRedirect
31
from django.shortcuts import render, resolve_url
32
from django.urls import reverse
33
from django.utils.http import is_safe_url, urlencode
34
from django.utils.six.moves.urllib import parse as urlparse
35
from django.utils.translation import ugettext as _
36
from django.views.generic import FormView, View
37
from requests_oauthlib import OAuth2Session
40 38

  
41 39
try:
42 40
    from django.contrib.auth.views import update_session_auth_hash
......
44 42
    update_session_auth_hash = None
45 43

  
46 44
from authentic2 import app_settings as a2_app_settings
47
from authentic2 import utils as a2_utils, hooks, constants
45
from authentic2 import constants, hooks
46
from authentic2 import utils as a2_utils
48 47
from authentic2.a2_rbac.utils import get_default_ou
49 48
from authentic2.forms.passwords import SetPasswordForm
50 49
from authentic2.utils import views as views_utils
src/authentic2_auth_oidc/admin.py
20 20
from django.contrib import admin
21 21
from django.utils.translation import ugettext as _
22 22

  
23
from authentic2.models import Attribute
24 23
from authentic2.custom_user.models import User
25 24
from authentic2.forms.widgets import DatalistTextInput
25
from authentic2.models import Attribute
26 26

  
27 27
from . import models
28 28

  
src/authentic2_auth_oidc/apps.py
20 20
class Plugin(object):
21 21
    def revoke_token(self, provider, access_token):
22 22
        import logging
23

  
23 24
        import requests
24 25

  
25 26
        logger = logging.getLogger(__name__)
......
50 51

  
51 52
    def redirect_logout_list(self, request, next=None):
52 53
        from django.urls import reverse
54

  
53 55
        from authentic2.utils import make_url
56

  
54 57
        from .models import OIDCProvider
55 58

  
56 59
        tokens = request.session.get('auth_oidc', {}).get('tokens', [])
......
80 83

  
81 84
    def ready(self):
82 85
        from django.db.models.signals import pre_save
86

  
83 87
        from authentic2.custom_user.models import DeletedUser
84 88

  
85 89
        pre_save.connect(self.pre_save_deleted_user, sender=DeletedUser)
src/authentic2_auth_oidc/authenticators.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.utils.translation import gettext_noop
18 17
from django.shortcuts import render
18
from django.utils.translation import gettext_noop
19

  
20
from authentic2.authenticators import BaseAuthenticator
21
from authentic2.utils import make_url, redirect_to_login
19 22

  
20 23
from . import app_settings, utils
21 24
from .models import OIDCProvider
22
from authentic2.utils import make_url
23
from authentic2.utils import redirect_to_login
24
from authentic2.authenticators import BaseAuthenticator
25 25

  
26 26

  
27 27
class OIDCAuthenticator(BaseAuthenticator):
src/authentic2_auth_oidc/backends.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import logging
18 17
import datetime
18
import logging
19 19

  
20 20
import requests
21

  
22
from jwcrypto.jwt import JWT
23
from jwcrypto.jwk import JWK
24

  
25
from django.utils import six
26
from django.utils.timezone import now
27 21
from django.contrib.auth import get_user_model
28 22
from django.contrib.auth.backends import ModelBackend
23
from django.utils import six
24
from django.utils.timezone import now
25
from jwcrypto.jwk import JWK
26
from jwcrypto.jwt import JWT
29 27

  
30
from django_rbac.utils import get_ou_model
31

  
32
from authentic2.crypto import base64url_encode
33 28
from authentic2 import app_settings, hooks
29
from authentic2.crypto import base64url_encode
34 30
from authentic2.utils.template import Template
31
from django_rbac.utils import get_ou_model
35 32

  
36 33
from . import models, utils
37 34

  
src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py
19 19
import json
20 20
import pprint
21 21

  
22

  
23
from django.core.management.base import BaseCommand, CommandError
24 22
from django.core.exceptions import ValidationError
23
from django.core.management.base import BaseCommand, CommandError
25 24
from django.db.transaction import atomic
26 25

  
27

  
28
from authentic2_auth_oidc.utils import register_issuer
29 26
from authentic2_auth_oidc.models import OIDCClaimMapping, OIDCProvider
27
from authentic2_auth_oidc.utils import register_issuer
30 28
from django_rbac.utils import get_ou_model
31 29

  
32 30

  
src/authentic2_auth_oidc/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
import uuid
5

  
6
import django.contrib.postgres.fields.jsonb
7
from django.conf import settings
4 8
from django.db import migrations, models
9

  
5 10
import authentic2.a2_rbac.utils
6 11
import authentic2_auth_oidc.models
7
import django.contrib.postgres.fields.jsonb
8
from django.conf import settings
9
import uuid
10 12

  
11 13

  
12 14
class Migration(migrations.Migration):
src/authentic2_auth_oidc/migrations/0008_auto_20201102_1142.py
1 1
# Generated by Django 2.2.17 on 2020-11-02 10:42
2 2

  
3
import django.db.models.deletion
3 4
from django.conf import settings
4 5
from django.db import migrations, models
5
import django.db.models.deletion
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2_auth_oidc/models.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import uuid
18 17
import json
18
import uuid
19 19

  
20
from django.db import models
21
from django.utils.translation import ugettext_lazy as _
22 20
from django.conf import settings
23
from django.core.exceptions import ValidationError
24

  
25 21
from django.contrib.postgres.fields import JSONField
26

  
27
from jwcrypto.jwk import JWKSet, InvalidJWKValue, JWK
22
from django.core.exceptions import ValidationError
23
from django.db import models
24
from django.utils.translation import ugettext_lazy as _
25
from jwcrypto.jwk import JWK, InvalidJWKValue, JWKSet
28 26

  
29 27
from django_rbac.utils import get_ou_model_name
30 28

  
src/authentic2_auth_oidc/urls.py
18 18

  
19 19
from . import views
20 20

  
21

  
22 21
urlpatterns = [
23 22
    url(r'^accounts/oidc/login/(?P<pk>\d+)/$', views.oidc_login, name='oidc-login'),
24 23
    url(r'^accounts/oidc/login/$', views.login_initiate, name='oidc-login-initiate'),
src/authentic2_auth_oidc/utils.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import datetime
18
import requests
19 18

  
19
import requests
20
from django.shortcuts import get_object_or_404
20 21
from django.utils import six
22
from django.utils.six.moves.urllib import parse as urlparse
21 23
from django.utils.timezone import utc
22
from django.shortcuts import get_object_or_404
23 24
from django.utils.translation import ugettext as _
24
from django.utils.six.moves.urllib import parse as urlparse
25
from jwcrypto.common import JWException, base64url_encode, json_decode
26
from jwcrypto.jwk import JWK
27
from jwcrypto.jwt import JWT
25 28

  
29
from authentic2.a2_rbac.utils import get_default_ou
26 30
from authentic2.decorators import GlobalCache
27 31
from authentic2.models import Attribute
28
from authentic2.a2_rbac.utils import get_default_ou
29

  
30
from jwcrypto.common import base64url_encode
31
from jwcrypto.common import JWException
32
from jwcrypto.common import json_decode
33
from jwcrypto.jwk import JWK
34
from jwcrypto.jwt import JWT
35 32

  
36 33
from . import models
37 34

  
src/authentic2_auth_oidc/views.py
19 19
import logging
20 20
import uuid
21 21

  
22
import requests
23

  
24 22
import django
23
import requests
25 24
from django.conf import settings
26
from django.core import signing
27
from django.urls import reverse
28
from django.utils.translation import get_language, ugettext as _
29 25
from django.contrib import messages
30 26
from django.contrib.auth import REDIRECT_FIELD_NAME
31
from django.conf import settings
32
from django.views.generic.base import View
27
from django.core import signing
33 28
from django.http import HttpResponseBadRequest
29
from django.urls import reverse
30
from django.utils.translation import get_language
31
from django.utils.translation import ugettext as _
32
from django.views.generic.base import View
34 33

  
35 34
import authentic2.compat.cookies  # F401
36 35
from authentic2.decorators import setting_enabled
37
from authentic2.utils import redirect, login, good_next_url, authenticate
36
from authentic2.utils import authenticate, good_next_url, login, redirect
38 37

  
39 38
from . import app_settings, models
40 39
from .utils import get_provider, get_provider_by_issuer
src/authentic2_auth_saml/adapters.py
18 18

  
19 19
import logging
20 20

  
21
from django.utils import six
22 21
from django.contrib import messages
23 22
from django.core.exceptions import MultipleObjectsReturned
24 23
from django.db.transaction import atomic
24
from django.utils import six
25 25
from django.utils.translation import ugettext as _
26

  
27 26
from mellon.adapters import DefaultAdapter, UserCreationError
28 27
from mellon.utils import get_setting
29 28

  
30 29
from authentic2 import utils
30
from authentic2.a2_rbac.models import OrganizationalUnit as OU
31
from authentic2.a2_rbac.models import Role
32
from authentic2.a2_rbac.utils import get_default_ou
31 33
from authentic2.backends import get_user_queryset
32 34
from authentic2.utils.evaluate import evaluate_condition
33
from authentic2.a2_rbac.models import Role, OrganizationalUnit as OU
34
from authentic2.a2_rbac.utils import get_default_ou
35

  
36 35

  
37 36
logger = logging.getLogger('authentic2.auth_saml')
38 37

  
src/authentic2_auth_saml/apps.py
23 23

  
24 24
    def ready(self):
25 25
        from django.db.models.signals import pre_save
26

  
26 27
        from authentic2.custom_user.models import DeletedUser
27 28

  
28 29
        pre_save.connect(self.pre_save_deleted_user, sender=DeletedUser)
src/authentic2_auth_saml/authenticators.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.utils.translation import gettext_noop
18
from django.template.loader import render_to_string
19 17
from django.shortcuts import render
18
from django.template.loader import render_to_string
19
from django.utils.translation import gettext_noop
20 20
from mellon.utils import get_idp, get_idps
21 21

  
22 22
from authentic2.authenticators import BaseAuthenticator
src/authentic2_auth_saml/urls.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.conf.urls import url, include
17
from django.conf.urls import include, url
18 18

  
19 19
urlpatterns = [
20 20
    url(r'^accounts/saml/', include('mellon.urls'), kwargs={'template_base': 'authentic/base.html'})
src/authentic2_idp_cas/admin.py
18 18
from django.contrib import admin
19 19
from django.utils.translation import ugettext as _
20 20

  
21
from authentic2.admin import CleanupAdminMixin
22

  
21 23
# Django < 1.7 compat
22 24
from authentic2.attributes_ng.engine import get_attribute_names
23 25
from authentic2.decorators import to_iter
24
from authentic2.admin import CleanupAdminMixin
25 26

  
26 27
from . import models
27 28

  
src/authentic2_idp_cas/managers.py
18 18

  
19 19
from django.db import models
20 20
from django.db.models import query
21
from django.utils.timezone import now
22 21
from django.utils.six.moves.urllib import parse as urlparse
22
from django.utils.timezone import now
23 23

  
24 24

  
25 25
class TicketQuerySet(query.QuerySet):
src/authentic2_idp_cas/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5

  
5 6
import authentic2_idp_cas.models
6 7

  
7 8

  
src/authentic2_idp_cas/migrations/0002_auto_20150410_1438.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/authentic2_idp_cas/migrations/0003_auto_20150415_2223.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2_idp_cas/migrations/0004_create_services.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def create_services(apps, schema_editor):
src/authentic2_idp_cas/migrations/0005_alter_field_service_ptr.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2_idp_cas/migrations/0006_copy_proxy_m2m.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def copy_proxy_m2m_to_service_proxy(apps, schema_editor):
src/authentic2_idp_cas/migrations/0007_alter_service.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2_idp_cas/migrations/0008_alter_foreign_keys.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def alter_foreign_keys(apps, schema_editor):
src/authentic2_idp_cas/migrations/0009_alter_related_models.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2_idp_cas/migrations/0010_copy_service_ptr_id_to_old_id.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def noop(apps, schema_editor):
src/authentic2_idp_cas/migrations/0011_remove_old_id_restore_proxy.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2_idp_cas/migrations/0012_copy_service_proxy_to_m2m.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
def copy_proxy_m2m_to_service_proxy(apps, schema_editor):
src/authentic2_idp_cas/migrations/0013_delete_model_service_proxy2.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2_idp_cas/migrations/0014_auto_20151204_1606.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
4
from django.db import migrations, models
5 5

  
6 6

  
7 7
class Migration(migrations.Migration):
src/authentic2_idp_cas/models.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.core.exceptions import ValidationError
18
from django.core.validators import URLValidator
17 19
from django.db import models
18
from django.utils.translation import ugettext_lazy as _
19 20
from django.utils.timezone import now
20
from django.core.validators import URLValidator
21
from django.core.exceptions import ValidationError
21
from django.utils.translation import ugettext_lazy as _
22 22

  
23 23
from authentic2.models import LogoutUrlAbstract, Service
24 24
from authentic2.utils import check_session_key
25 25

  
26
from . import managers, utils, constants
26
from . import constants, managers, utils
27 27

  
28 28
url_validator = URLValidator(
29 29
    schemes=['http', 'https', 'ftp', 'ftps', 'imap', 'imaps', 'sieve', 'smtp', 'smtps', 'ssh']
src/authentic2_idp_cas/views.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import logging
18
from collections import defaultdict
18 19
from datetime import timedelta
19 20
from xml.etree import ElementTree as ET
20
from collections import defaultdict
21 21

  
22 22
import requests
23

  
24
from django.http import HttpResponseBadRequest, HttpResponse
25
from django.views.generic.base import View
23
from django.http import HttpResponse, HttpResponseBadRequest
26 24
from django.utils import six
27 25
from django.utils.timezone import now
26
from django.views.generic.base import View
28 27

  
28
from authentic2 import hooks
29
from authentic2.attributes_ng.engine import get_attributes
30
from authentic2.constants import NONCE_FIELD_NAME
29 31
from authentic2.utils import (
32
    attribute_values_to_identifier,
33
    find_authentication_event,
30 34
    get_user_from_session_key,
31
    make_url,
32 35
    login_require,
33
    find_authentication_event,
34
    redirect,
36
    make_url,
35 37
    normalize_attribute_values,
36
    attribute_values_to_identifier,
38
    redirect,
37 39
)
38
from authentic2.attributes_ng.engine import get_attributes
39
from authentic2.constants import NONCE_FIELD_NAME
40 40
from authentic2.views import logout as logout_view
41
from authentic2 import hooks
42

  
43
from authentic2_idp_cas.models import Ticket, Service
44
from authentic2_idp_cas.utils import make_id
45 41
from authentic2_idp_cas.constants import (
46
    SERVICE_PARAM,
47
    RENEW_PARAM,
48
    GATEWAY_PARAM,
49
    TICKET_PARAM,
42
    ATTRIBUTES_ELT,
43
    AUTHENTICATION_SUCCESS_ELT,
44
    BAD_PGT_ERROR,
50 45
    CANCEL_PARAM,
51
    SERVICE_TICKET_PREFIX,
46
    CAS10_VALIDATION_FAILURE,
47
    CAS10_VALIDATION_SUCCESS,
48
    CAS20_PROXY_FAILURE,
49
    CAS20_VALIDATION_FAILURE,
50
    CAS_NAMESPACE,
51
    GATEWAY_PARAM,
52
    INTERNAL_ERROR,
52 53
    INVALID_REQUEST_ERROR,
53
    INVALID_TICKET_SPEC_ERROR,
54 54
    INVALID_SERVICE_ERROR,
55
    INVALID_TARGET_SERVICE_ERROR,
55 56
    INVALID_TICKET_ERROR,
56
    CAS10_VALIDATION_FAILURE,
57
    CAS20_VALIDATION_FAILURE,
58
    SERVICE_RESPONSE_ELT,
59
    AUTHENTICATION_SUCCESS_ELT,
60
    USER_ELT,
61
    PGT_URL_PARAM,
62
    PGT_IOU_PARAM,
63
    SESSION_CAS_LOGOUTS,
64
    CAS10_VALIDATION_SUCCESS,
57
    INVALID_TICKET_SPEC_ERROR,
65 58
    PGT_ELT,
66
    PROXIES_ELT,
67
    PROXY_ELT,
68
    PGT_PREFIX,
59
    PGT_ID_PARAM,
60
    PGT_IOU_PARAM,
69 61
    PGT_IOU_PREFIX,
70
    PT_PREFIX,
71
    TARGET_SERVICE_PARAM,
72
    BAD_PGT_ERROR,
73
    INVALID_TARGET_SERVICE_ERROR,
74
    PROXY_UNAUTHORIZED_ERROR,
75 62
    PGT_PARAM,
76
    PGT_ID_PARAM,
77
    CAS20_PROXY_FAILURE,
63
    PGT_PREFIX,
64
    PGT_URL_PARAM,
65
    PROXIES_ELT,
66
    PROXY_ELT,
78 67
    PROXY_SUCCESS_ELT,
79 68
    PROXY_TICKET_ELT,
80
    INTERNAL_ERROR,
81
    CAS_NAMESPACE,
82
    ATTRIBUTES_ELT,
69
    PROXY_UNAUTHORIZED_ERROR,
70
    PT_PREFIX,
71
    RENEW_PARAM,
72
    SERVICE_PARAM,
73
    SERVICE_RESPONSE_ELT,
74
    SERVICE_TICKET_PREFIX,
75
    SESSION_CAS_LOGOUTS,
76
    TARGET_SERVICE_PARAM,
77
    TICKET_PARAM,
78
    USER_ELT,
83 79
)
80
from authentic2_idp_cas.models import Service, Ticket
81
from authentic2_idp_cas.utils import make_id
82

  
84 83
from . import app_settings
85 84

  
86 85
try:
src/authentic2_idp_oidc/admin.py
21 21
from authentic2.attributes_ng.engine import get_service_attributes
22 22
from authentic2.forms.widgets import DatalistTextInput
23 23

  
24
from . import models, app_settings
24
from . import app_settings, models
25 25

  
26 26

  
27 27
class OIDCClaimInlineForm(forms.ModelForm):
......
80 80

  
81 81
    def get_search_results(self, request, queryset, search_term):
82 82
        from django.contrib.contenttypes.models import ContentType
83

  
83 84
        from authentic2.a2_rbac.models import OrganizationalUnit as OU
84 85

  
85 86
        queryset, use_distinct = super(OIDCAuthorizationAdmin, self).get_search_results(
src/authentic2_idp_oidc/apps.py
21 21

  
22 22
class Plugin(object):
23 23
    def logout_list(self, request):
24
        from .utils import get_oidc_sessions
25 24
        from . import app_settings
25
        from .utils import get_oidc_sessions
26 26

  
27 27
        fragments = []
28 28

  
......
49 49
    # implement translation of encrypted pairwise identifiers when and OIDC Client is using the
50 50
    # A2 API
51 51
    def a2_hook_api_modify_serializer(self, view, serializer):
52
        from . import utils
53 52
        from rest_framework import serializers
54 53

  
54
        from . import utils
55

  
55 56
        if hasattr(view.request.user, 'oidc_client'):
56 57
            client = view.request.user.oidc_client
57 58
            if client.identifier_policy == client.POLICY_PAIRWISE_REVERSIBLE:
......
72 73
    def a2_hook_api_modify_view_before_get_object(self, view):
73 74
        '''Decrypt sub used as pk argument in URL.'''
74 75
        import uuid
76

  
75 77
        from . import utils
76 78

  
77 79
        client = self.get_oidc_client(view)
......
90 92

  
91 93
    def a2_hook_api_modify_serializer_after_validation(self, view, serializer):
92 94
        import uuid
95

  
93 96
        from . import utils
94 97

  
95 98
        if view.__class__.__name__ != 'UsersAPI':
src/authentic2_idp_oidc/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import migrations, models
5 4
from django.conf import settings
5
from django.db import migrations, models
6

  
6 7
import authentic2_idp_oidc.models
7 8

  
8 9

  
src/authentic2_idp_oidc/migrations/0002_auto_20170121_2346.py
2 2
from __future__ import unicode_literals
3 3

  
4 4
from django.db import migrations, models
5

  
5 6
import authentic2_idp_oidc.models
6 7

  
7 8

  
src/authentic2_idp_oidc/migrations/0003_auto_20170329_1259.py
2 2
from __future__ import unicode_literals
3 3

  
4 4
from django.db import migrations, models
5

  
5 6
import authentic2_idp_oidc.models
6 7

  
7 8

  
src/authentic2_idp_oidc/migrations/0011_auto_20180808_1546.py
3 3

  
4 4
from django.db import migrations
5 5

  
6

  
7 6
OLD_DEFAULT_CLAIMS_MAPPING = {
8 7
    'email': 'django_user_email',
9 8
    'email_verified': 'django_user_email_verified',
src/authentic2_idp_oidc/models.py
17 17
import uuid
18 18
from importlib import import_module
19 19

  
20

  
21
from django.db import models
22
from django.core.validators import URLValidator
23
from django.core.exceptions import ValidationError, ImproperlyConfigured
24
from django.utils.translation import ugettext_lazy as _
25 20
from django.conf import settings
21
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
22
from django.core.exceptions import ImproperlyConfigured, ValidationError
23
from django.core.validators import URLValidator
24
from django.db import models
26 25
from django.utils import six
27 26
from django.utils.functional import cached_property
28
from django.utils.timezone import now
29 27
from django.utils.six.moves.urllib import parse as urlparse
30
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
28
from django.utils.timezone import now
29
from django.utils.translation import ugettext_lazy as _
31 30

  
32 31
from authentic2.a2_rbac.models import OrganizationalUnit
33 32
from authentic2.models import Service
34 33

  
35
from . import utils, managers, app_settings
34
from . import app_settings, managers, utils
36 35

  
37 36

  
38 37
def generate_uuid():
src/authentic2_idp_oidc/urls.py
18 18

  
19 19
from . import views
20 20

  
21

  
22 21
urlpatterns = [
23 22
    url(r'^.well-known/openid-configuration$', views.openid_configuration, name='oidc-openid-configuration'),
24 23
    url(r'^idp/oidc/certs/?$', views.certs, name='oidc-certs'),
src/authentic2_idp_oidc/utils.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import json
18
import hashlib
19 17
import base64
18
import hashlib
19
import json
20 20
import uuid
21 21

  
22
from jwcrypto.jwk import JWK, JWKSet, InvalidJWKValue
23
from jwcrypto.jwt import JWT
24

  
25
from django.core.exceptions import ImproperlyConfigured
26 22
from django.conf import settings
23
from django.core.exceptions import ImproperlyConfigured
27 24
from django.utils import six
28 25
from django.utils.encoding import force_bytes, force_text
29 26
from django.utils.six.moves.urllib import parse as urlparse
27
from jwcrypto.jwk import JWK, InvalidJWKValue, JWKSet
28
from jwcrypto.jwt import JWT
30 29

  
31
from authentic2 import hooks, crypto
30
from authentic2 import crypto, hooks
32 31
from authentic2.attributes_ng.engine import get_attributes
33
from authentic2.utils.template import Template
34 32
from authentic2.decorators import GlobalCache
33
from authentic2.utils.template import Template
35 34

  
36 35
from . import app_settings
37 36

  
......
266 265
@GlobalCache(timeout=60)
267 266
def good_next_url(next_url):
268 267
    from authentic2.utils import same_origin
268

  
269 269
    from .models import OIDCClient
270 270

  
271 271
    for oidc_client in OIDCClient.objects.all():
src/authentic2_idp_oidc/views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import base64
18
import datetime
17 19
import logging
18 20
import math
19
import datetime
20
import base64
21 21

  
22 22
try:
23 23
    from secrets import compare_digest
......
29 29

  
30 30
import time
31 31

  
32
from django.conf import settings
33
from django.contrib import messages
34
from django.contrib.auth import authenticate
32 35
from django.http import HttpResponse, HttpResponseNotAllowed, JsonResponse
36
from django.shortcuts import render
33 37
from django.urls import reverse
34 38
from django.utils import six
35 39
from django.utils.encoding import force_text
36
from django.utils.timezone import now, utc
37 40
from django.utils.http import urlencode
38
from django.shortcuts import render
39
from django.views.decorators.csrf import csrf_exempt
40
from django.contrib import messages
41
from django.contrib.auth import authenticate
42
from django.conf import settings
41
from django.utils.timezone import now, utc
43 42
from django.utils.translation import ugettext as _
43
from django.views.decorators.csrf import csrf_exempt
44 44
from ratelimit.utils import is_ratelimited
45 45

  
46 46
from authentic2 import app_settings as a2_app_settings
47
from authentic2 import hooks
47 48
from authentic2.compat.misc import Base64Error
48 49
from authentic2.decorators import setting_enabled
49 50
from authentic2.exponential_retry_timeout import ExponentialRetryTimeout
50
from authentic2.utils import login_require, redirect, last_authentication_event, make_url
51
from authentic2.utils import (
52
    last_authentication_event,
53
    login_require,
54
    make_url,
55
    redirect,
56
)
51 57
from authentic2.views import logout as a2_logout
52
from authentic2 import hooks
53 58
from django_rbac.utils import get_ou_model
54 59

  
55 60
from . import app_settings, models, utils
src/django_rbac/apps.py
6 6
    verbose_name = 'RBAC engine for Django'
7 7

  
8 8
    def ready(self):
9
        from django.db.models.signals import post_delete, post_migrate, post_save
10

  
9 11
        from . import signal_handlers, utils
10
        from django.db.models.signals import post_save, post_delete, post_migrate
11 12

  
12 13
        # update role parenting when new role parenting is created
13 14
        post_save.connect(signal_handlers.role_parenting_post_save, sender=utils.get_role_parenting_model())
src/django_rbac/managers.py
1 1
import contextlib
2 2
import threading
3 3

  
4
from django.contrib.auth import get_user_model
5
from django.contrib.contenttypes.models import ContentType
4 6
from django.db import models
5 7
from django.db.models import query
6
from django.contrib.contenttypes.models import ContentType
7
from django.db.models.query import Q, Prefetch
8
from django.contrib.auth import get_user_model
8
from django.db.models.query import Prefetch, Q
9 9
from django.utils import six
10 10

  
11 11
from . import utils
src/django_rbac/migrations/0001_initial.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6

  
6 7
import authentic2.utils
7 8

  
8 9

  
src/django_rbac/migrations/0002_organizationalunit_permission_role_roleparenting.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7
import django_rbac
8 8

  
src/django_rbac/migrations/0004_auto_20150708_1337.py
1 1
# -*- coding: utf-8 -*-
2 2
from __future__ import unicode_literals
3 3

  
4
from django.db import models, migrations
5 4
from django.conf import settings
5
from django.db import migrations, models
6 6

  
7 7

  
8 8
class Migration(migrations.Migration):
src/django_rbac/models.py
1
import operator
2 1
import hashlib
2
import operator
3 3

  
4
from django.conf import settings
5
from django.db import models
6
from django.db.models.query import Prefetch, Q
4 7
from django.utils import six
5 8
from django.utils.text import slugify
6 9
from django.utils.translation import ugettext_lazy as _
7
from django.db import models
8
from django.conf import settings
9
from django.db.models.query import Q, Prefetch
10 10

  
11 11
try:
12 12
    from django.contrib.contenttypes.fields import GenericForeignKey
13 13
except ImportError:
14 14
    # Django < 1.8
15 15
    from django.contrib.contenttypes.generic import GenericForeignKey
16
from django.contrib.contenttypes.models import ContentType
16

  
17
from django.contrib import auth
17 18
from django.contrib.auth import get_user_model
19
from django.contrib.auth.models import Group
20
from django.contrib.auth.models import Permission as AuthPermission
18 21
from django.contrib.auth.models import (
19
    Group,
20 22
    _user_get_all_permissions,
21
    _user_has_perm,
22 23
    _user_has_module_perms,
23
    Permission as AuthPermission,
24
    _user_has_perm,
24 25
)
25
from django.contrib import auth
26
from django.contrib.contenttypes.models import ContentType
26 27

  
27
from . import utils, constants, managers, backends
28
from . import backends, constants, managers, utils
28 29

  
29 30

  
30 31
class AbstractBase(models.Model):
src/django_rbac/utils.py
1 1
import uuid
2 2

  
3
from django.conf import settings
4 3
from django.apps import apps
4
from django.conf import settings
5 5
from django.utils import six
6 6

  
7 7
from . import constants
tests/auth_fc/conftest.py
21 21
import urllib.parse as urlparse
22 22
import uuid
23 23

  
24
from jwcrypto import jwk, jwt
25 24
import httmock
26 25
import pytest
27

  
28 26
from django.http import QueryDict
29 27
from django.urls import reverse
30 28
from django.utils.http import urlencode
31 29
from django.utils.timezone import now
32

  
30
from jwcrypto import jwk, jwt
33 31

  
34 32
from authentic2.models import Service
35 33
from authentic2.utils import make_url
tests/auth_fc/test_auth_fc.py
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18 18
import datetime
19
import mock
20 19

  
20
import mock
21 21
import requests
22

  
23 22
from django.contrib.auth import get_user_model
24 23
from django.urls import reverse
25 24
from django.utils.six.moves.urllib import parse as urlparse
26 25
from django.utils.timezone import now
27 26

  
28 27
from authentic2.custom_user.models import DeletedUser
29

  
30 28
from authentic2_auth_fc import models
31 29
from authentic2_auth_fc.utils import requests_retry_session
32 30

  
33
from ..utils import login, get_link_from_mail
34

  
31
from ..utils import get_link_from_mail, login
35 32

  
36 33
User = get_user_model()
37 34

  
tests/cache_urls.py
17 17
from django.conf.urls import url
18 18
from django.http import HttpResponse
19 19

  
20
from authentic2.decorators import SessionCache, DjangoCache
20
from authentic2.decorators import DjangoCache, SessionCache
21 21

  
22 22

  
23 23
@DjangoCache
tests/conftest.py
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18 18

  
19
import pytest
20
import mock
21

  
22
import django_webtest
23

  
24 19
import django
20
import django_webtest
21
import mock
22
import pytest
25 23
from django.contrib.auth import get_user_model
26 24
from django.core.cache import cache
27
from django_rbac.utils import get_ou_model, get_role_model
28
from django.utils.six.moves.urllib import parse as urlparse
29
from django.db.migrations.executor import MigrationExecutor
30
from django.db import connection
31 25
from django.core.management import call_command
32

  
26
from django.db import connection
27
from django.db.migrations.executor import MigrationExecutor
28
from django.utils.six.moves.urllib import parse as urlparse
33 29
from pytest_django.migrations import DisableMigrations
34 30

  
35 31
from authentic2 import hooks as a2_hooks
36
from authentic2.models import Service
37
from authentic2.utils.evaluate import BaseExpressionValidator
38 32
from authentic2.a2_rbac.utils import get_default_ou
33
from authentic2.authentication import OIDCUser
39 34
from authentic2.manager.utils import get_ou_count
40
from authentic2_auth_oidc.utils import get_providers
41
from authentic2_auth_oidc.utils import get_provider_by_issuer
42
from authentic2_auth_oidc.utils import has_providers
35
from authentic2.models import Service
36
from authentic2.utils.evaluate import BaseExpressionValidator
37
from authentic2_auth_oidc.utils import (
38
    get_provider_by_issuer,
39
    get_providers,
40
    has_providers,
41
)
43 42
from authentic2_idp_oidc.models import OIDCClient
44
from authentic2.authentication import OIDCUser
43
from django_rbac.utils import get_ou_model, get_role_model
45 44

  
46 45
from . import utils
47 46

  
tests/test_a2_rbac.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import pytest
18

  
18
from django.contrib.contenttypes.models import ContentType
19 19
from django.core.exceptions import ValidationError
20 20
from django.core.management import call_command
21 21

  
22
from django.contrib.contenttypes.models import ContentType
23

  
24
from django_rbac.utils import get_permission_model
25
from django_rbac.models import Operation, CHANGE_OP
22
from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP
23
from authentic2.a2_rbac.models import OrganizationalUnit as OU
24
from authentic2.a2_rbac.models import Permission, Role, RoleAttribute
25
from authentic2.a2_rbac.utils import get_default_ou, get_view_user_perm
26 26
from authentic2.custom_user.models import User
27 27
from authentic2.models import Service
28
from django.core.management import call_command
29

  
30
from authentic2.a2_rbac.utils import get_default_ou, get_view_user_perm
31
from authentic2.a2_rbac.models import (
32
    Role,
33
    Permission,
34
    OrganizationalUnit as OU,
35
    RoleAttribute,
36
    MANAGE_MEMBERS_OP,
37
)
38 28
from authentic2.utils import get_hex_uuid
39

  
29
from django_rbac.models import CHANGE_OP, Operation
30
from django_rbac.utils import get_permission_model
40 31

  
41 32
from .utils import login, request_select2
42 33

  
tests/test_admin.py
17 17

  
18 18
from __future__ import unicode_literals
19 19

  
20
from django.utils.six.moves.urllib.parse import urlparse
21

  
20 22
from authentic2.custom_user.models import User
21 23
from authentic2.models import Attribute
22
from django.utils.six.moves.urllib.parse import urlparse
23 24

  
24 25
from . import utils
25 26

  
tests/test_all.py
15 15
# You should have received a copy of the GNU Affero General Public License
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18
import json
19 18
import base64
19
import json
20 20

  
21 21
import pytest
22

  
22
from django.contrib.auth import get_user_model
23
from django.contrib.contenttypes.models import ContentType
24
from django.contrib.sessions.backends.cache import SessionStore
23 25
from django.core import mail
26
from django.core.serializers.json import DjangoJSONEncoder
24 27
from django.test import TestCase
25 28
from django.test.client import Client
26 29
from django.test.utils import override_settings
27
from django.core.serializers.json import DjangoJSONEncoder
28
from django.contrib.auth import get_user_model
29
from django.contrib.contenttypes.models import ContentType
30
from django.contrib.sessions.backends.cache import SessionStore
31 30
from django.urls import reverse
32 31
from django.utils.encoding import force_text
33
from django.utils.translation import ugettext as _
34 32
from django.utils.six import text_type
35 33
from django.utils.six.moves.urllib import parse as urlparse
34
from django.utils.translation import ugettext as _
35
from rest_framework import status, test
36 36

  
37
from rest_framework import test
38
from rest_framework import status
39

  
40
from django_rbac.utils import get_role_model, get_ou_model
41

  
42
from authentic2 import utils, models, attribute_kinds
37
from authentic2 import attribute_kinds, models, utils
38
from django_rbac.utils import get_ou_model, get_role_model
43 39

  
44
from .utils import Authentic2TestCase, get_response_form, get_link_from_mail, assert_event
40
from .utils import (
41
    Authentic2TestCase,
42
    assert_event,
43
    get_link_from_mail,
44
    get_response_form,
45
)
45 46

  
46 47

  
47 48
class SerializerTests(TestCase):
48 49
    def test_generic_foreign_key_natural_key(self):
49 50
        import json
50
        from authentic2.models import Attribute, AttributeValue
51

  
51 52
        from django.core import serializers
52 53

  
54
        from authentic2.models import Attribute, AttributeValue
55

  
53 56
        User = get_user_model()
54 57
        ucount = User.objects.count()
55 58
        acount = Attribute.objects.count()
......
154 157
        )
155 158

  
156 159
    def test_redirect(self):
157
        from authentic2.utils import redirect
158 160
        from django.test.client import RequestFactory
159 161

  
162
        from authentic2.utils import redirect
163

  
160 164
        rf = RequestFactory()
161 165
        request = rf.get('/coin', data={'next': '..'})
162 166
        request2 = rf.get('/coin', data={'next': '..', 'token': 'xxx'})
......
174 178
        self.assertEqualsURL(response['Location'], '/boob/?token=uuu&next=..')
175 179

  
176 180
    def test_redirect_to_login(self):
177
        from authentic2.utils import redirect_to_login
178 181
        from django.test.client import RequestFactory
179 182

  
183
        from authentic2.utils import redirect_to_login
184

  
180 185
        rf = RequestFactory()
181 186
        request = rf.get('/coin', data={'next': '..'})
182 187
        response = redirect_to_login(request)
183 188
        self.assertEqualsURL(response['Location'], '/login/?next=..')
184 189

  
185 190
    def test_continue_to_next_url(self):
186
        from authentic2.utils import continue_to_next_url
187 191
        from django.test.client import RequestFactory
188 192

  
193
        from authentic2.utils import continue_to_next_url
194

  
189 195
        rf = RequestFactory()
190 196
        request = rf.get('/coin', data={'next': '/zob/', 'nonce': 'xxx'})
191 197
        response = continue_to_next_url(request)
192 198
        self.assertEqualsURL(response['Location'], '/zob/?nonce=xxx')
193 199

  
194 200
    def test_login_require(self):
195
        from authentic2.utils import login_require
196 201
        from django.test.client import RequestFactory
197 202

  
203
        from authentic2.utils import login_require
204

  
198 205
        rf = RequestFactory()
199 206
        request = rf.get('/coin', data={'next': '/zob/', 'nonce': 'xxx'})
200 207
        request.session = SessionStore()
......
282 289
    @override_settings(ROOT_URLCONF='tests.cache_urls')
283 290
    def test_cache_decorator_base(self):
284 291
        import random
292

  
285 293
        from authentic2.decorators import CacheDecoratorBase
286 294

  
287 295
        class GlobalCache(CacheDecoratorBase):
......
351 359

  
352 360
class AttributeKindsTest(TestCase):
353 361
    def test_simple(self):
354
        from django.core.exceptions import ValidationError
355 362
        from django import forms
363
        from django.core.exceptions import ValidationError
356 364

  
357 365
        with self.settings(
358 366
            A2_ATTRIBUTE_KINDS=[
......
435 443
    @override_settings(A2_REQUIRED_FIELDS=['username'])
436 444
    def register_with_user(self, user, cred):
437 445
        from django.contrib.auth import get_user_model
438
        from rest_framework import test
439
        from rest_framework import status
446
        from rest_framework import status, test
440 447

  
441 448
        # disable existing attributes
442 449
        models.Attribute.objects.update(disabled=True)
......
543 550
    @override_settings(A2_REQUIRED_FIELDS=['username'])
544 551
    def test_email_is_unique_double_registration(self):
545 552
        from django.contrib.auth import get_user_model
546
        from rest_framework import test
547
        from rest_framework import status
553
        from rest_framework import status, test
548 554

  
549 555
        # disable existing attributes
550 556
        models.Attribute.objects.update(disabled=True)
......
634 640
    @override_settings(A2_REQUIRED_FIELDS=['username'])
635 641
    def test_email_username_is_unique_double_registration(self):
636 642
        from django.contrib.auth import get_user_model
637
        from rest_framework import test
638
        from rest_framework import status
643
        from rest_framework import status, test
639 644

  
640 645
        # disable existing attributes
641 646
        models.Attribute.objects.update(disabled=True)
tests/test_api.py
18 18

  
19 19
import datetime
20 20
import json
21
import mock
22
import pytest
23 21
import random
24 22
import uuid
25 23

  
26

  
27 24
import django
28
from django.contrib.auth.hashers import check_password
25
import mock
26
import pytest
29 27
from django.contrib.auth import get_user_model
28
from django.contrib.auth.hashers import check_password
30 29
from django.contrib.contenttypes.models import ContentType
31 30
from django.core import mail
32 31
from django.urls import reverse
33 32
from django.utils.encoding import force_text
33
from django.utils.http import urlencode
34 34
from django.utils.text import slugify
35 35
from django.utils.timezone import now
36
from django.utils.http import urlencode
37

  
38
from rest_framework import VERSION as drf_version
39
from django_rbac.models import SEARCH_OP
40
from django_rbac.utils import get_role_model, get_ou_model
41 36
from requests.models import Response
37
from rest_framework import VERSION as drf_version
42 38

  
43 39
from authentic2.a2_rbac.models import Role
44 40
from authentic2.a2_rbac.utils import get_default_ou
45
from authentic2.apps.journal.models import EventType, Event
46
from authentic2.models import Service, Attribute, AttributeValue, AuthorizedRole
41
from authentic2.apps.journal.models import Event, EventType
42
from authentic2.models import Attribute, AttributeValue, AuthorizedRole, Service
47 43
from authentic2.utils import good_next_url
44
from django_rbac.models import SEARCH_OP
45
from django_rbac.utils import get_ou_model, get_role_model
48 46

  
49
from .utils import login, basic_authorization_header, get_link_from_mail
47
from .utils import basic_authorization_header, get_link_from_mail, login
50 48

  
51 49
pytestmark = pytest.mark.django_db
52 50

  
tests/test_attribute_kinds.py
19 19
import os
20 20

  
21 21
import PIL.Image
22

  
23 22
from django.conf import settings
23
from webtest import Upload
24 24

  
25 25
from authentic2.custom_user.models import User
26 26
from authentic2.models import Attribute
27 27

  
28 28
from .utils import get_link_from_mail
29
from webtest import Upload
30 29

  
31 30

  
32 31
def test_string(db, app, admin, mailoutbox):
tests/test_auth_oidc.py
18 18
import datetime
19 19
import json
20 20
import os
21
import pytest
22 21
import random
23 22
import re
24 23
import time
25 24

  
26
from jwcrypto.common import base64url_encode, base64url_decode, json_encode
27
from jwcrypto.jwk import JWKSet, JWK
28
from jwcrypto.jws import JWS, InvalidJWSObject
29
from jwcrypto.jwt import JWT
30

  
31
from httmock import urlmatch, HTTMock
32

  
25
import pytest
33 26
from django.contrib.auth import get_user_model
34 27
from django.db import IntegrityError, transaction
35
from django.urls import reverse
36
from django.utils.encoding import force_text, force_str
37 28
from django.http import QueryDict
29
from django.urls import reverse
30
from django.utils.encoding import force_str, force_text
38 31
from django.utils.six.moves.urllib import parse as urlparse
39
from django.utils.timezone import now
40
from django.utils.timezone import utc
41

  
42
from django_rbac.utils import get_ou_model
32
from django.utils.timezone import now, utc
33
from httmock import HTTMock, urlmatch
34
from jwcrypto.common import base64url_decode, base64url_encode, json_encode
35
from jwcrypto.jwk import JWK, JWKSet
36
from jwcrypto.jws import JWS, InvalidJWSObject
37
from jwcrypto.jwt import JWT
43 38

  
39
from authentic2.a2_rbac.utils import get_default_ou
40
from authentic2.custom_user.models import DeletedUser
41
from authentic2.models import Attribute, AttributeValue
42
from authentic2.utils import last_authentication_event
43
from authentic2_auth_oidc.models import OIDCAccount, OIDCClaimMapping, OIDCProvider
44 44
from authentic2_auth_oidc.utils import (
45
    parse_id_token,
46 45
    IDToken,
46
    IDTokenError,
47 47
    get_providers,
48 48
    has_providers,
49
    parse_id_token,
49 50
    register_issuer,
50
    IDTokenError,
51 51
)
52
from authentic2_auth_oidc.models import OIDCProvider, OIDCClaimMapping, OIDCAccount
53
from authentic2.models import Attribute
54
from authentic2.models import AttributeValue
55
from authentic2.utils import last_authentication_event
56
from authentic2.a2_rbac.utils import get_default_ou
57
from authentic2.custom_user.models import DeletedUser
52
from django_rbac.utils import get_ou_model
58 53

  
59 54
from . import utils
60 55

  
tests/test_auth_saml.py
18 18
import os
19 19
import re
20 20

  
21
import pytest
22

  
23 21
import lasso
24

  
22
import pytest
25 23
from django.contrib.auth import get_user_model
26 24
from django.utils.timezone import now
27

  
28 25
from mellon.models import UserSAMLIdentifier
29 26

  
30
from authentic2.models import Attribute
31 27
from authentic2.custom_user.models import DeletedUser
28
from authentic2.models import Attribute
32 29
from authentic2_auth_saml.adapters import AuthenticAdapter, MappingError
33 30

  
34 31
User = get_user_model()
tests/test_backends.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from authentic2.utils import authenticate
18 17
from authentic2.backends import is_user_authenticable
18
from authentic2.utils import authenticate
19 19

  
20 20

  
21 21
def test_user_filters(settings, db, simple_user, user_ou1, ou1):
tests/test_commands.py
18 18
import importlib
19 19
import json
20 20

  
21
import py
21 22
import pytest
22

  
23
from django.contrib.auth import get_user_model
23 24
from django.contrib.contenttypes.models import ContentType
24 25
from django.utils import six
25 26
from django.utils.timezone import now
26
import py
27 27

  
28 28
from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP, VIEW_OP
29 29
from authentic2.a2_rbac.utils import get_default_ou
30
from authentic2.models import UserExternalId
31 30
from authentic2.custom_user.models import DeletedUser
32
from authentic2_auth_oidc.models import OIDCProvider, OIDCAccount
33
from django_rbac.models import ADMIN_OP
34
from django_rbac.models import Operation
35
from django_rbac.utils import get_operation
36
from django_rbac.utils import get_ou_model
37
from django_rbac.utils import get_permission_model
38
from django_rbac.utils import get_role_model
39
from django.contrib.auth import get_user_model
31
from authentic2.models import UserExternalId
32
from authentic2_auth_oidc.models import OIDCAccount, OIDCProvider
33
from django_rbac.models import ADMIN_OP, Operation
34
from django_rbac.utils import (
35
    get_operation,
36
    get_ou_model,
37
    get_permission_model,
38
    get_role_model,
39
)
40 40

  
41
from .utils import login, call_command
41
from .utils import call_command, login
42 42

  
43 43
User = get_user_model()
44 44

  
45 45
if six.PY2:
46 46
    FileType = file  # noqa: F821
47 47
else:
48
    from io import TextIOWrapper, BufferedReader, BufferedWriter
48
    from io import BufferedReader, BufferedWriter, TextIOWrapper
49 49

  
50 50
    FileType = (TextIOWrapper, BufferedReader, BufferedWriter)
51 51

  
tests/test_concurrency.py
17 17
import threading
18 18

  
19 19
import pytest
20

  
21 20
from django.db import connection
22 21

  
23 22
from authentic2.models import Attribute, AttributeValue
tests/test_crypto.py
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18 18
import random
19
import uuid
20 19
import time
20
import uuid
21 21

  
22 22
import pytest
23

  
24 23
from django.utils.encoding import force_bytes
25 24

  
26 25
from authentic2 import crypto
tests/test_csv_import.py
17 17

  
18 18
from __future__ import unicode_literals
19 19

  
20
import pytest
21

  
22
import io
23 20
import codecs
21
import io
24 22

  
25
from django.contrib.auth.hashers import make_password, check_password
23
import pytest
24
from django.contrib.auth.hashers import check_password, make_password
26 25
from django.core import mail
27 26

  
28
from django_rbac.utils import get_role_model
29

  
27
from authentic2.a2_rbac.utils import get_default_ou
28
from authentic2.csv_import import (
29
    CsvHeader,
30
    CsvImporter,
31
    Error,
32
    LineError,
33
    UserCsvImporter,
34
)
30 35
from authentic2.custom_user.models import User
31 36
from authentic2.models import Attribute
32
from authentic2.a2_rbac.utils import get_default_ou
33

  
34
from authentic2.csv_import import CsvImporter, UserCsvImporter, CsvHeader, Error, LineError
37
from django_rbac.utils import get_role_model
35 38

  
36 39
Role = get_role_model()
37 40

  
tests/test_custom_user.py
16 16

  
17 17
from datetime import date
18 18

  
19
import pytest
19 20
from django.contrib.auth import get_user_model
20 21

  
22
from authentic2.custom_user.models import DeletedUser, User
21 23
from authentic2.models import Attribute
22
from authentic2.custom_user.models import User, DeletedUser
23 24
from django_rbac.utils import get_permission_model, get_role_model
24 25

  
25
import pytest
26

  
27 26
Permission = get_permission_model()
28 27
Role = get_role_model()
29 28

  
tests/test_customfields.py
16 16

  
17 17
import pytest
18 18

  
19
from authentic2.saml.models import KeyValue, NAME_ID_FORMATS_CHOICES, SPOptionsIdPPolicy
19
from authentic2.saml.models import NAME_ID_FORMATS_CHOICES, KeyValue, SPOptionsIdPPolicy
20 20

  
21 21
# Adaptation of http://djangosnippets.org/snippets/513/
22 22

  
tests/test_data_transfer.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import pytest
18

  
19 18
from django.core.exceptions import ValidationError
20 19

  
21
from django_rbac.utils import get_role_model, get_ou_model
22

  
23 20
from authentic2.a2_rbac.models import RoleParenting
24 21
from authentic2.data_transfer import (
25
    export_site,
26 22
    ExportContext,
27
    export_roles,
28
    import_site,
29
    export_ous,
30 23
    ImportContext,
31 24
    RoleDeserializer,
32
    search_role,
25
    export_ous,
26
    export_roles,
27
    export_site,
33 28
    import_ou,
29
    import_site,
30
    search_role,
34 31
)
35 32
from authentic2.utils import get_hex_uuid
36

  
33
from django_rbac.utils import get_ou_model, get_role_model
37 34

  
38 35
Role = get_role_model()
39 36
OU = get_ou_model()
tests/test_fields.py
17 17
from __future__ import unicode_literals
18 18

  
19 19
import pytest
20

  
21 20
from django.core.exceptions import ValidationError
22 21

  
23 22
from authentic2.attribute_kinds import PhoneNumberField
tests/test_idp_cas.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.contrib.auth import get_user_model
18
from django.test.client import RequestFactory, Client
18
from django.test.client import Client, RequestFactory
19 19
from django.test.utils import override_settings
20 20
from django.utils.encoding import force_text
21 21
from django.utils.six.moves.urllib import parse as urlparse
22 22

  
23

  
24
from authentic2_idp_cas.models import Ticket, Service, Attribute
25
from authentic2_idp_cas import constants
26
from authentic2.constants import AUTHENTICATION_EVENTS_SESSION_KEY, NONCE_FIELD_NAME
27 23
from authentic2.a2_rbac.utils import get_default_ou
24
from authentic2.constants import AUTHENTICATION_EVENTS_SESSION_KEY, NONCE_FIELD_NAME
25
from authentic2_idp_cas import constants
26
from authentic2_idp_cas.models import Attribute, Service, Ticket
28 27
from django_rbac.utils import get_role_model
29 28

  
30 29
from .utils import Authentic2TestCase
tests/test_idp_oidc.py
17 17
import base64
18 18
import datetime
19 19
import functools
20
from importlib import import_module
21 20
import json
21
from importlib import import_module
22 22

  
23 23
import pytest
24

  
25
from jwcrypto.jwt import JWT
26
from jwcrypto.jwk import JWKSet, JWK
27

  
28
from . import utils
29

  
24
from django.contrib.auth import get_user_model
30 25
from django.core.exceptions import ValidationError
31 26
from django.core.files import File
32 27
from django.http import QueryDict
33 28
from django.test.utils import override_settings
34 29
from django.urls import reverse
35 30
from django.utils.encoding import force_text
36
from django.utils.timezone import now
37
from django.contrib.auth import get_user_model
38 31
from django.utils.six.moves.urllib import parse as urlparse
32
from django.utils.timezone import now
33
from jwcrypto.jwk import JWK, JWKSet
34
from jwcrypto.jwt import JWT
39 35

  
40

  
41
from authentic2.models import Attribute, AuthorizedRole
42
from authentic2_idp_oidc.models import OIDCClient, OIDCAuthorization, OIDCCode, OIDCAccessToken, OIDCClaim
43
from authentic2_idp_oidc.utils import base64url
44
from authentic2_idp_oidc.utils import get_first_rsa_sig_key
45
from authentic2_idp_oidc.utils import get_first_ec_sig_key
46
from authentic2_idp_oidc.utils import make_sub
47
from authentic2_idp_oidc import app_settings
48 36
from authentic2.a2_rbac.utils import get_default_ou
49
from authentic2.utils import make_url, good_next_url
37
from authentic2.models import Attribute, AuthorizedRole
38
from authentic2.utils import good_next_url, make_url
50 39
from authentic2_auth_oidc.utils import parse_timestamp
51
from django_rbac.utils import get_ou_model
52
from django_rbac.utils import get_role_model
40
from authentic2_idp_oidc import app_settings
41
from authentic2_idp_oidc.models import (
42
    OIDCAccessToken,
43
    OIDCAuthorization,
44
    OIDCClaim,
45
    OIDCClient,
46
    OIDCCode,
47
)
48
from authentic2_idp_oidc.utils import (
49
    base64url,
50
    get_first_ec_sig_key,
51
    get_first_rsa_sig_key,
52
    make_sub,
53
)
54
from django_rbac.utils import get_ou_model, get_role_model
55

  
56
from . import utils
53 57

  
54 58
User = get_user_model()
55 59

  
tests/test_idp_saml2.py
17 17

  
18 18
from __future__ import unicode_literals
19 19

  
20
import re
21
import datetime
22 20
import base64
21
import datetime
23 22
import hashlib
24

  
23
import re
25 24
import xml.etree.ElementTree as ET
26 25

  
27
import pytest
26
import lasso
28 27
import mock
29

  
28
import pytest
30 29
from django.contrib.auth import REDIRECT_FIELD_NAME
31 30
from django.core.files import File
32
from django.template import Template, Context
31
from django.template import Context, Template
33 32
from django.urls import reverse
34
from django.utils.translation import gettext as _
35
from django.utils.encoding import force_text, force_str, force_bytes
33
from django.utils.encoding import force_bytes, force_str, force_text
36 34
from django.utils.six.moves.urllib import parse as urlparse
35
from django.utils.translation import gettext as _
37 36

  
38
from authentic2.saml import models as saml_models
39
from authentic2.a2_rbac.models import Role, OrganizationalUnit, RoleAttribute
40
from authentic2.utils import make_url
37
from authentic2.a2_rbac.models import OrganizationalUnit, Role, RoleAttribute
41 38
from authentic2.constants import NONCE_FIELD_NAME, SERVICE_FIELD_NAME
42
from authentic2.models import Attribute, Service
43 39
from authentic2.custom_user.models import User
44 40
from authentic2.idp.saml import saml2_endpoints
41
from authentic2.idp.saml.saml2_endpoints import (
42
    get_extensions,
43
    get_login_hints_extension,
44
)
45
from authentic2.models import Attribute, Service
46
from authentic2.saml import models as saml_models
45 47
from authentic2.saml.models import LibertyProvider, SAMLAttribute
46
from authentic2.idp.saml.saml2_endpoints import get_extensions, get_login_hints_extension
48
from authentic2.utils import make_url
47 49

  
48
import lasso
49 50
from . import utils
50 51

  
51 52

  
tests/test_import_export_site_cmd.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import random
18 17
import json
18
import random
19 19

  
20
import pytest
20 21
from django import VERSION
22
from django.core import management
21 23
from django.core.exceptions import ValidationError
22

  
23 24
from django.utils import six
24 25
from django.utils.six.moves import builtins as __builtin__
25
from django.core import management
26
import pytest
27 26

  
28 27
from django_rbac.utils import get_role_model
29 28

  
tests/test_journal.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from datetime import datetime, timedelta
18 17
import random
18
from datetime import datetime, timedelta
19 19

  
20 20
import mock
21 21
import pytest
22 22
import pytz
23

  
24 23
from django.contrib.auth import get_user_model
25 24
from django.core.management import call_command
26 25
from django.utils.timezone import make_aware, make_naive
......
29 28
from authentic2.a2_rbac.utils import get_default_ou
30 29
from authentic2.apps.journal.forms import JournalForm
31 30
from authentic2.apps.journal.journal import Journal
32
from authentic2.apps.journal.models import EventTypeDefinition, EventType, Event, clean_registry
31
from authentic2.apps.journal.models import (
32
    Event,
33
    EventType,
34
    EventTypeDefinition,
35
    clean_registry,
36
)
33 37
from authentic2.models import Service
34 38

  
35 39
User = get_user_model()
tests/test_journal_app/views.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17

  
18
from django.contrib.auth import get_user_model, login, authenticate
18
from django.contrib.auth import authenticate, get_user_model, login
19 19
from django.http import HttpResponse
20 20

  
21 21
from authentic2.apps.journal.journal import journal
tests/test_large_userbase.py
18 18

  
19 19
import faker
20 20
import pytest
21

  
22 21
from django.contrib.auth import get_user_model
23 22
from django.contrib.contenttypes.models import ContentType
24 23

  
25 24
from authentic2.models import Attribute, AttributeValue
26 25

  
27

  
28 26
User = get_user_model()
29 27

  
30 28
pytestmark = pytest.mark.slow
tests/test_ldap.py
17 17

  
18 18
import json
19 19
import os
20

  
21
import pytest
22
import mock
23 20
import time
24 21

  
25 22
import ldap
26
from ldap.dn import escape_dn_chars
27

  
28
from ldaptools.slapd import Slapd, has_slapd
23
import mock
24
import pytest
29 25
from django.contrib.auth import get_user_model
26
from django.core import mail, management
30 27
from django.core.exceptions import ImproperlyConfigured
31
from django.core import management
32
from django.core import mail
33
from django.utils.encoding import force_bytes
34
from django.utils.encoding import force_text
35 28
from django.utils import timezone
29
from django.utils.encoding import force_bytes, force_text
36 30
from django.utils.six.moves.urllib import parse as urlparse
31
from ldap.dn import escape_dn_chars
32
from ldaptools.slapd import Slapd, has_slapd
37 33

  
38
from authentic2.models import Service
34
from authentic2 import crypto, models
39 35
from authentic2.a2_rbac.models import Role
40 36
from authentic2.a2_rbac.utils import get_default_ou
41
from django_rbac.utils import get_ou_model
42 37
from authentic2.backends import ldap_backend
38
from authentic2.models import Service
43 39
from authentic2.utils import authenticate
44
from authentic2 import crypto, models
40
from django_rbac.utils import get_ou_model
45 41

  
46 42
from . import utils
47 43

  
......
610 606

  
611 607

  
612 608
def test_get_users(slapd, settings, db, monkeypatch, caplog):
613
    import django.db.models.base
614 609
    from types import MethodType
610

  
611
    import django.db.models.base
615 612
    from django.contrib.auth.models import Group
616 613

  
617 614
    settings.LDAP_AUTH_SETTINGS = [
tests/test_login.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import pytest
18

  
19
from django.utils.six.moves.urllib.parse import quote
20 18
from django.contrib.auth import get_user_model
19
from django.utils.six.moves.urllib.parse import quote
21 20

  
22 21
from authentic2 import models
23 22

  
24
from .utils import login, check_log, assert_event
23
from .utils import assert_event, check_log, login
25 24

  
26 25
User = get_user_model()
27 26

  
tests/test_manager.py
17 17

  
18 18
from __future__ import unicode_literals
19 19

  
20
import pytest
21 20
import json
22 21

  
22
import pytest
23
from django.contrib.auth import get_user_model
24
from django.contrib.contenttypes.models import ContentType
23 25
from django.core import mail
24 26
from django.urls import reverse
25
from django.utils.encoding import force_str
26

  
27
from django.utils.encoding import force_bytes, force_str
28
from django.utils.six.moves.urllib.parse import urlparse
27 29
from webtest import Upload
28 30

  
29 31
from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP
30 32
from authentic2.a2_rbac.utils import get_default_ou
31 33
from authentic2.validators import EmailValidator
32

  
33
from django_rbac.utils import get_ou_model, get_role_model, get_permission_model, get_operation
34 34
from django_rbac.models import VIEW_OP
35
from django.contrib.auth import get_user_model
36
from django.contrib.contenttypes.models import ContentType
37
from django.utils.encoding import force_bytes
38
from django.utils.six.moves.urllib.parse import urlparse
39
from .utils import login, get_link_from_mail, request_select2
35
from django_rbac.utils import (
36
    get_operation,
37
    get_ou_model,
38
    get_permission_model,
39
    get_role_model,
40
)
40 41

  
42
from .utils import get_link_from_mail, login, request_select2
41 43

  
42 44
pytestmark = pytest.mark.django_db
43 45

  
......
1003 1005
def test_manager_widget_fields_validation(app, simple_user, simple_role):
1004 1006
    '''Verify that fields corresponding to widget implement queryset restrictions.'''
1005 1007
    from authentic2.manager.forms import (
1006
        ChooseUserForm,
1007 1008
        ChooseRoleForm,
1008
        UsersForm,
1009
        RolesForm,
1009
        ChooseUserForm,
1010 1010
        ChooseUserRoleForm,
1011 1011
        RoleParentsForm,
1012
        RolesForm,
1013
        UsersForm,
1012 1014
    )
1013 1015

  
1014 1016
    error_message = 'Select a valid choice'
tests/test_manager_journal.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import datetime
18

  
18 19
import mock
20
import pytest
21
from django.contrib.sessions.models import Session
22
from django.utils.timezone import make_aware
19 23

  
20
from authentic2.custom_user.models import User
21
from authentic2.a2_rbac.utils import get_default_ou
22 24
from authentic2.a2_rbac.models import Role
23
from authentic2.models import Service
25
from authentic2.a2_rbac.utils import get_default_ou
24 26
from authentic2.apps.journal.models import Event, _registry
27
from authentic2.custom_user.models import User
25 28
from authentic2.journal import journal
26

  
27
from django.contrib.sessions.models import Session
28
from django.utils.timezone import make_aware
29

  
30
import pytest
29
from authentic2.models import Service
31 30

  
32 31
from .utils import login, text_content
33 32

  
tests/test_manager_user_import.py
22 22

  
23 23
import pytest
24 24

  
25
from authentic2.manager.user_import import UserImport, Report
25
from authentic2.manager.user_import import Report, UserImport
26 26
from authentic2.models import Attribute
27 27

  
28 28

  
tests/test_migrations.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import mock
18

  
19 18
from django.contrib.auth.models import AbstractUser
20 19
from django.db.utils import ProgrammingError
21 20
from django.utils.timezone import now
tests/test_models.py
19 19

  
20 20
import pytest
21 21

  
22
from authentic2.models import Attribute
23 22
from authentic2.custom_user.models import User
23
from authentic2.models import Attribute
24 24

  
25 25

  
26 26
def test_attribute_disabled(db):
tests/test_natural_key.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
import pytest
17

  
18 17
from django.contrib.contenttypes.models import ContentType
19
from authentic2.a2_rbac.models import Role, OrganizationalUnit as OU, Permission
18

  
19
from authentic2.a2_rbac.models import OrganizationalUnit as OU
20
from authentic2.a2_rbac.models import Permission, Role
20 21

  
21 22

  
22 23
def test_natural_key_json(db, ou1):
tests/test_profile.py
19 19
from __future__ import unicode_literals
20 20

  
21 21
import pytest
22

  
23 22
from django.urls import reverse
24 23

  
25 24
from authentic2.a2_rbac.utils import get_default_ou
tests/test_registration.py
17 17

  
18 18
from datetime import date
19 19

  
20
from django.contrib.auth import get_user_model, REDIRECT_FIELD_NAME
20
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
21 21
from django.urls import reverse
22 22
from django.utils.http import urlquote
23 23
from django.utils.six.moves.urllib.parse import urlparse
24 24

  
25
from authentic2 import utils, models
25
from authentic2 import models, utils
26 26
from authentic2.apps.journal.models import Event
27 27
from authentic2.validators import EmailValidator
28 28

  
29
from .utils import get_link_from_mail, assert_event
30

  
29
from .utils import assert_event, get_link_from_mail
31 30

  
32 31
User = get_user_model()
33 32

  
tests/test_role_manager.py
16 16

  
17 17
import json
18 18

  
19
from webtest import Upload
20

  
21 19
from django.utils.encoding import force_bytes, force_text
20
from webtest import Upload
22 21

  
23
from authentic2.custom_user.models import User
24
from authentic2.a2_rbac.models import Role, OrganizationalUnit
22
from authentic2.a2_rbac.models import OrganizationalUnit, Role
25 23
from authentic2.a2_rbac.utils import get_default_ou
24
from authentic2.custom_user.models import User
26 25

  
27 26
from .utils import login, text_content
28 27

  
tests/test_saml_x509utils.py
17 17

  
18 18
from authentic2.saml.x509utils import (
19 19
    can_generate_rsa_key_pair,
20
    generate_rsa_keypair,
21 20
    check_key_pair_consistency,
22
    get_xmldsig_rsa_key_value,
23
    get_rsa_public_key_modulus,
24
    get_rsa_public_key_exponent,
25 21
    decapsulate_pem_file,
22
    generate_rsa_keypair,
23
    get_rsa_public_key_exponent,
24
    get_rsa_public_key_modulus,
25
    get_xmldsig_rsa_key_value,
26 26
)
27 27

  
28 28

  
tests/test_template.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import pytest
18

  
19 18
from django.urls import reverse
20 19

  
21 20
from authentic2.a2_rbac.utils import get_default_ou
tests/test_user_manager.py
24 24
from urllib.parse import urlparse
25 25

  
26 26
import pytest
27
from webtest import Upload
28

  
29 27
from django.contrib.auth import get_user_model
30 28
from django.contrib.contenttypes.models import ContentType
31 29
from django.urls import reverse
32 30
from django.utils.six import text_type
31
from webtest import Upload
33 32

  
33
from authentic2.a2_rbac.utils import get_default_ou, get_view_user_perm
34
from authentic2.apps.journal.models import Event
35
from authentic2.custom_user.models import User
36
from authentic2.manager import user_import
37
from authentic2.models import Attribute, AttributeValue
38
from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient
34 39
from django_rbac.models import VIEW_OP
35 40
from django_rbac.utils import (
36 41
    get_operation,
......
39 44
    get_role_model,
40 45
)
41 46

  
42
from authentic2.custom_user.models import User
43
from authentic2.models import Attribute, AttributeValue
44
from authentic2.a2_rbac.utils import get_default_ou
45
from authentic2.a2_rbac.utils import get_view_user_perm
46
from authentic2.manager import user_import
47
from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient
48
from authentic2.apps.journal.models import Event
49

  
50

  
51
from .utils import login, get_link_from_mail, logout
47
from .utils import get_link_from_mail, login, logout
52 48

  
53 49
OU = get_ou_model()
54 50

  
......
1025 1021
    * access user service consents page
1026 1022
    * try to remove a service consent
1027 1023
    """
1028
    from django_rbac.utils import get_role_model, get_operation, get_permission_model
1029
    from django_rbac.models import VIEW_OP
1030 1024
    from authentic2.a2_rbac.models import MANAGE_AUTHORIZATIONS_OP
1025
    from django_rbac.models import VIEW_OP
1026
    from django_rbac.utils import get_operation, get_permission_model, get_role_model
1031 1027
    from tests.conftest import create_user
1032 1028

  
1033 1029
    Role = get_role_model()
tests/test_user_model.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
# authentic2
17 17

  
18
import pytest
19 18
import datetime
20 19

  
21
from django.core.exceptions import ValidationError
20
import pytest
22 21
from django.core import management
22
from django.core.exceptions import ValidationError
23 23
from django.utils.timezone import now
24 24

  
25
from authentic2.custom_user.models import User, DeletedUser
25
from authentic2.custom_user.models import DeletedUser, User
26 26
from authentic2.models import Attribute, AttributeValue, UserExternalId
27 27

  
28 28

  
tests/test_utils.py
16 16
# authentic2
17 17

  
18 18
from django.contrib.auth.middleware import AuthenticationMiddleware
19
from django.contrib.sessions.middleware import SessionMiddleware
20 19
from django.contrib.messages.middleware import MessageMiddleware
20
from django.contrib.sessions.middleware import SessionMiddleware
21 21
from django.core import mail
22 22
from django.utils.functional import lazy
23 23

  
24
from django_rbac.utils import get_ou_model
25

  
26 24
from authentic2.journal import Journal
27 25
from authentic2.utils import (
26
    authenticate,
27
    get_authentication_events,
28 28
    good_next_url,
29
    login,
29 30
    same_origin,
30 31
    select_next_url,
31
    user_can_change_password,
32
    login,
33
    get_authentication_events,
34
    authenticate,
35 32
    send_templated_mail,
33
    user_can_change_password,
36 34
)
37 35
from authentic2.utils.lazy import lazy_join
36
from django_rbac.utils import get_ou_model
38 37

  
39 38

  
40 39
def test_good_next_url(db, rf, settings):
......
105 104

  
106 105

  
107 106
def test_remember_cookie(rf):
108
    from authentic2.utils import get_remember_cookie, prepend_remember_cookie
109 107
    from django.http import HttpResponse
110 108

  
109
    from authentic2.utils import get_remember_cookie, prepend_remember_cookie
110

  
111 111
    request = rf.get('/')
112 112
    request.COOKIES['preferrence'] = '1 2'
113 113
    assert get_remember_cookie(request, 'preferrence') == [1, 2]
tests/test_utils_evaluate.py
23 23
    BaseExpressionValidator,
24 24
    ConditionValidator,
25 25
    ExpressionError,
26
    evaluate_condition,
27 26
    HTTPHeaders,
27
    evaluate_condition,
28 28
)
29 29

  
30 30

  
tests/test_utils_lazy.py
17 17
from __future__ import unicode_literals
18 18

  
19 19
import pytest
20

  
21 20
from django.utils import six
22 21

  
23 22
from authentic2.utils.lazy import lazy_join
tests/test_validators.py
21 21

  
22 22
import mock
23 23
import pytest
24

  
25 24
from django.core.exceptions import ValidationError
26 25

  
27
from authentic2.validators import validate_password, EmailValidator
26
from authentic2.validators import EmailValidator, validate_password
28 27

  
29 28

  
30 29
def test_validate_password():
tests/test_views.py
16 16
# authentic2
17 17

  
18 18
import datetime
19
from .utils import login, logout, get_link_from_mail, assert_event
20
import pytest
21 19

  
20
import pytest
22 21
from django.urls import reverse
23 22
from django.utils.html import escape
24 23
from django.utils.six.moves.urllib.parse import urlparse
25 24

  
26
from authentic2.custom_user.models import User, DeletedUser
25
from authentic2.custom_user.models import DeletedUser, User
26

  
27
from .utils import assert_event, get_link_from_mail, login, logout
27 28

  
28 29
pytestmark = pytest.mark.django_db
29 30

  
tests/test_widgets.py
17 17

  
18 18
from pyquery import PyQuery
19 19

  
20
from authentic2.widgets import DateTimeWidget, DateWidget, TimeWidget
21
from authentic2.widgets import DatalistTextInput
20
from authentic2.widgets import DatalistTextInput, DateTimeWidget, DateWidget, TimeWidget
22 21

  
23 22

  
24 23
def test_datetimepicker_init_and_render_no_locale():
tests/utils.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
# authentic2
17 17

  
18
import re
19 18
import base64
19
import re
20 20
import socket
21
from contextlib import contextmanager, closing
21
from contextlib import closing, contextmanager
22 22

  
23 23
import httmock
24
from lxml import etree
25

  
26 24
from django.core.management import call_command as django_call_command
25
from django.shortcuts import resolve_url
27 26
from django.test import TestCase
28 27
from django.urls import reverse
29
from django.utils.encoding import iri_to_uri, force_text
30
from django.shortcuts import resolve_url
31 28
from django.utils import six
29
from django.utils.encoding import force_text, iri_to_uri
32 30
from django.utils.six.moves.urllib import parse as urlparse
31
from lxml import etree
33 32

  
34
from authentic2 import utils, models
33
from authentic2 import models, utils
35 34
from authentic2.apps.journal.models import Event
36 35

  
37 36

  
tests_rbac/test_rbac.py
16 16

  
17 17
import time
18 18

  
19
import pytest
19 20
from django.contrib.auth import get_user_model
20 21
from django.contrib.contenttypes.models import ContentType
21
from django.test.utils import CaptureQueriesContext
22 22
from django.db import connection
23
from django.test.utils import CaptureQueriesContext
23 24

  
24
from django_rbac import utils, models, backends
25

  
26
import pytest
25
from django_rbac import backends, models, utils
27 26

  
28 27

  
29 28
def test_role_parenting(db):
30
-