pyams-security 2.1.2__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {pyams_security-2.1.2 → pyams_security-2.3.0}/PKG-INFO +15 -1
  2. {pyams_security-2.1.2 → pyams_security-2.3.0}/docs/HISTORY.rst +14 -0
  3. {pyams_security-2.1.2 → pyams_security-2.3.0}/setup.py +1 -1
  4. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/roles.rst +8 -3
  5. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/users.rst +31 -0
  6. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/__init__.py +1 -1
  7. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/base.py +15 -0
  8. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/plugin.py +6 -1
  9. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/locales/fr/LC_MESSAGES/pyams_security.mo +0 -0
  10. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/locales/fr/LC_MESSAGES/pyams_security.po +4 -4
  11. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/userfolder.py +19 -0
  12. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/principal.py +10 -3
  13. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/role.py +15 -9
  14. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/utility.py +7 -4
  15. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/PKG-INFO +15 -1
  16. {pyams_security-2.1.2 → pyams_security-2.3.0}/LICENSE +0 -0
  17. {pyams_security-2.1.2 → pyams_security-2.3.0}/MANIFEST.in +0 -0
  18. {pyams_security-2.1.2 → pyams_security-2.3.0}/docs/README.rst +0 -0
  19. {pyams_security-2.1.2 → pyams_security-2.3.0}/setup.cfg +0 -0
  20. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/__init__.py +0 -0
  21. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/api/__init__.py +0 -0
  22. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/credential.py +0 -0
  23. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/README.rst +0 -0
  24. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/credentials.rst +0 -0
  25. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/manager.rst +0 -0
  26. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/notifications.rst +0 -0
  27. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/passwords.rst +0 -0
  28. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/plugins.rst +0 -0
  29. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/policy.rst +0 -0
  30. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/principals.rst +0 -0
  31. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/profiles.rst +0 -0
  32. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/rest.rst +0 -0
  33. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/doctests/security.rst +0 -0
  34. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/generations/__init__.py +0 -0
  35. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/generations/evolve1.py +0 -0
  36. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/include.py +0 -0
  37. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/index.py +0 -0
  38. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/names.py +0 -0
  39. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/notification.py +0 -0
  40. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/profile.py +0 -0
  41. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/rest.py +0 -0
  42. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/interfaces/site.py +0 -0
  43. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/locales/pyams_security.pot +0 -0
  44. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/notification.py +0 -0
  45. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/password.py +0 -0
  46. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/permission.py +0 -0
  47. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/__init__.py +0 -0
  48. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/admin.py +0 -0
  49. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/group.py +0 -0
  50. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/templates/password-reset.pt +0 -0
  51. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/templates/register-body.pt +0 -0
  52. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/templates/register-info.pt +0 -0
  53. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/plugin/templates/register-message.pt +0 -0
  54. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/policy.py +0 -0
  55. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/profile.py +0 -0
  56. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/property.py +0 -0
  57. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/rest.py +0 -0
  58. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/schema.py +0 -0
  59. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/security.py +0 -0
  60. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/site.py +0 -0
  61. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/tests/__init__.py +0 -0
  62. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/tests/test_utilsdocs.py +0 -0
  63. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/tests/test_utilsdocstrings.py +0 -0
  64. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security/vocabulary.py +0 -0
  65. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/SOURCES.txt +0 -0
  66. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/dependency_links.txt +0 -0
  67. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/entry_points.txt +0 -0
  68. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/namespace_packages.txt +0 -0
  69. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/not-zip-safe +0 -0
  70. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/requires.txt +0 -0
  71. {pyams_security-2.1.2 → pyams_security-2.3.0}/src/pyams_security.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyams_security
3
- Version: 2.1.2
3
+ Version: 2.3.0
4
4
  Summary: PyAMS security management package
5
5
  Home-page: https://pyams.readthedocs.io
6
6
  Author: Thierry Florac
@@ -54,6 +54,20 @@ store roles assigned to principals.
54
54
  Changelog
55
55
  =========
56
56
 
57
+ 2.3.0
58
+ -----
59
+ - allow case-insensitive local user login
60
+
61
+ 2.2.1
62
+ -----
63
+ - added support for custom attributes in roles
64
+
65
+ 2.2.0
66
+ -----
67
+ - added marker interface to handle unknown or missing principals
68
+ - added argument to security manager authentication method to get plugins instance
69
+ instead of plugin name
70
+
57
71
  2.1.2
58
72
  -----
59
73
  - renamed UnknownPrincipal class to avoid strange pickle behaviour...
@@ -1,6 +1,20 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 2.3.0
5
+ -----
6
+ - allow case-insensitive local user login
7
+
8
+ 2.2.1
9
+ -----
10
+ - added support for custom attributes in roles
11
+
12
+ 2.2.0
13
+ -----
14
+ - added marker interface to handle unknown or missing principals
15
+ - added argument to security manager authentication method to get plugins instance
16
+ instead of plugin name
17
+
4
18
  2.1.2
5
19
  -----
6
20
  - renamed UnknownPrincipal class to avoid strange pickle behaviour...
@@ -23,7 +23,7 @@ DOCS = os.path.join(os.path.dirname(__file__),
23
23
  README = os.path.join(DOCS, 'README.rst')
24
24
  HISTORY = os.path.join(DOCS, 'HISTORY.rst')
25
25
 
26
- version = '2.1.2'
26
+ version = '2.3.0'
27
27
  long_description = open(README).read() + '\n\n' + open(HISTORY).read()
28
28
 
29
29
  tests_require = [
@@ -92,18 +92,23 @@ or revoke this role to principals.
92
92
  ... permissions={view_permission.id, manage_permission.id})
93
93
  >>> register_role(config, manager_role)
94
94
 
95
+ You can also add custom properties to a role, which are stored in it's "custom_data" attribute:
96
+
95
97
  >>> contributor_role = Role(id='pyams.ocntributor',
96
98
  ... title='Contributor',
97
99
  ... permissions={view_permission.id},
98
- ... managers={manager_role.id})
100
+ ... managers={manager_role.id},
101
+ ... custom_value='Value')
99
102
  >>> register_role(config, contributor_role)
100
103
 
101
104
  >>> from pyams_security.interfaces.base import IRole
102
105
  >>> queryUtility(IRole, name=manager_role.id)
103
106
  <....Role object at 0x...>
107
+ >>> queryUtility(IRole, name=contributor_role.id).custom_data
108
+ {'custom_value': 'Value'}
104
109
 
105
- If you try to register the same role multiple times, this will comple his permissions and
106
- managers sets, but will not update it's other properties:
110
+ If you try to register the same role multiple times, this will complete his permissions,
111
+ managers sets and custom data, but will not update it's other properties:
107
112
 
108
113
  >>> another_role = Role(id='pyams.manager',
109
114
  ... title='Another manager role',
@@ -350,6 +350,37 @@ A vocabulary is available to select between users folders:
350
350
  {'users': <zope.schema.vocabulary.SimpleTerm object at 0x...>}
351
351
 
352
352
 
353
+ Case insensitive login
354
+ ----------------------
355
+
356
+ By default, local users folder login is case sensitive:
357
+
358
+ >>> folder.case_insensitive_login
359
+ False
360
+
361
+ >>> 'user1' in folder
362
+ True
363
+ >>> 'User1' in folder
364
+ False
365
+ >>> folder.get('User1') is None
366
+ True
367
+
368
+ You can switch case sensitive property to False:
369
+
370
+ >>> folder.case_insensitive_login = True
371
+
372
+ >>> 'user1' in folder
373
+ True
374
+ >>> 'User1' in folder
375
+ True
376
+ >>> folder.get('User1') is user1
377
+ True
378
+
379
+ >>> folder['User4'] = LocalUser()
380
+ >>> sorted(folder.keys())
381
+ ['user1', 'user2@example.com', 'user3@example.com', 'user4']
382
+
383
+
353
384
  Principals groups
354
385
  -----------------
355
386
 
@@ -118,7 +118,7 @@ class ISecurityManager(IContainer, IDirectoryPluginInfo, IAttributeAnnotatable):
118
118
  def extract_credentials(self, request, **kwargs):
119
119
  """Extract credentials from request"""
120
120
 
121
- def authenticate(self, credentials, request, get_plugin_name=False):
121
+ def authenticate(self, credentials, request, get_plugin_name=False, get_plugin=False):
122
122
  """Try to authenticate request with given credentials"""
123
123
 
124
124
  def authenticated_userid(self, request, principal_id=None):
@@ -97,6 +97,9 @@ class IRole(Interface):
97
97
  value_type=TextLine(),
98
98
  required=False)
99
99
 
100
+ custom_data = Dict(title="Custom role data",
101
+ required=False)
102
+
100
103
 
101
104
  class IPrincipalInfo(Interface):
102
105
  """Principal info class
@@ -114,3 +117,15 @@ class IPrincipalInfo(Interface):
114
117
  attributes = Dict(title="Principal groups",
115
118
  description="IDs of principals to which this principal directly belongs",
116
119
  value_type=TextLine())
120
+
121
+
122
+ class IUnavailablePrincipalInfo(IPrincipalInfo):
123
+ """Unavailable principal information parent interface"""
124
+
125
+
126
+ class IUnknownPrincipalInfo(IUnavailablePrincipalInfo):
127
+ """Unknown principal information interface"""
128
+
129
+
130
+ class IMissingPrincipalInfo(IUnavailablePrincipalInfo):
131
+ """Missing principal information interface"""
@@ -56,7 +56,7 @@ class IPlugin(IContained, IAttributeAnnotatable):
56
56
  class IPluginEvent(Interface):
57
57
  """Plug-in event interface"""
58
58
 
59
- plugin = Attribute("Event plug-in name")
59
+ plugin = Attribute("Event source plug-in")
60
60
 
61
61
 
62
62
  #
@@ -200,6 +200,11 @@ class IUsersFolderPlugin(IAuthenticationPlugin, IDirectorySearchPlugin):
200
200
 
201
201
  contains('pyams_security.interfaces.ILocalUser')
202
202
 
203
+ case_insensitive_login = Bool(title=_("Use case insensitive login"),
204
+ description=_("If enabled, users login will not be case sensitive"),
205
+ required=True,
206
+ default=False)
207
+
203
208
  def check_login(self, login):
204
209
  """Check for existence of given login"""
205
210
 
@@ -54,7 +54,7 @@ msgstr "Administrateur (rôle)"
54
54
 
55
55
  #: src/pyams_security/include.py:119
56
56
  msgid "System viewer (role)"
57
- msgstr "Opérateur (rôle)"
57
+ msgstr "Invité (rôle)"
58
58
 
59
59
  #. pylint: disable=invalid-name
60
60
  #: src/pyams_security/principal.py:59
@@ -451,15 +451,15 @@ msgstr ""
451
451
 
452
452
  #: src/pyams_security/interfaces/site.py:37
453
453
  msgid "Site viewers"
454
- msgstr "Opérateurs"
454
+ msgstr "Invités"
455
455
 
456
456
  #: src/pyams_security/interfaces/site.py:38
457
457
  msgid ""
458
458
  "These principals are allowed to view some application settings, without "
459
459
  "update"
460
460
  msgstr ""
461
- "Les détenteurs de ce rôle peuvent accéder à l'interface d'administration, "
462
- "mais sans droits de mise à jour"
461
+ "Les détenteurs de ce rôle peuvent accéder à certains écrans de l'interface d'administration, "
462
+ "mais sans droit de mise à jour"
463
463
 
464
464
  #: src/pyams_security/interfaces/profile.py:34
465
465
  msgid "Profile's avatar"
@@ -76,12 +76,31 @@ class UsersFolder(Folder):
76
76
  title = FieldProperty(IUsersFolderPlugin['title'])
77
77
  enabled = FieldProperty(IUsersFolderPlugin['enabled'])
78
78
 
79
+ case_insensitive_login = FieldProperty(IUsersFolderPlugin['case_insensitive_login'])
80
+
81
+ def get(self, key, default=None):
82
+ if self.case_insensitive_login:
83
+ key = key.lower()
84
+ return super().get(key, default)
85
+
86
+ def __contains__(self, item):
87
+ if self.case_insensitive_login:
88
+ item = item.lower()
89
+ return super().__contains__(item)
90
+
91
+ def __setitem__(self, key, value):
92
+ if self.case_insensitive_login:
93
+ key = key.lower()
94
+ super().__setitem__(key, value)
95
+
79
96
  def authenticate(self, credentials, request): # pylint: disable=unused-argument
80
97
  """Try to authenticate given credentials"""
81
98
  if not self.enabled:
82
99
  return None
83
100
  attrs = credentials.attributes
84
101
  login = attrs.get('login')
102
+ if not login:
103
+ return None
85
104
  principal = self.get(login)
86
105
  if principal is not None:
87
106
  password = attrs.get('password')
@@ -20,7 +20,8 @@ from zope.interface import implementer
20
20
  from zope.principalannotation.interfaces import IPrincipalAnnotationUtility
21
21
  from zope.schema.fieldproperty import FieldProperty
22
22
 
23
- from pyams_security.interfaces.base import IPrincipalInfo
23
+ from pyams_security.interfaces.base import IMissingPrincipalInfo, IPrincipalInfo, IUnavailablePrincipalInfo, \
24
+ IUnknownPrincipalInfo
24
25
  from pyams_security.interfaces.names import UNKNOWN_PRINCIPAL_ID
25
26
  from pyams_utils.adapter import adapter_config
26
27
  from pyams_utils.registry import query_utility
@@ -51,7 +52,7 @@ class PrincipalInfo:
51
52
  return hash(self.id)
52
53
 
53
54
 
54
- @implementer(IPrincipalInfo)
55
+ @implementer(IUnknownPrincipalInfo)
55
56
  class _UnknownPrincipal:
56
57
  """Unknown principal info"""
57
58
 
@@ -62,7 +63,7 @@ class _UnknownPrincipal:
62
63
  UnknownPrincipal = _UnknownPrincipal() # pylint: disable=invalid-name
63
64
 
64
65
 
65
- @implementer(IPrincipalInfo)
66
+ @implementer(IMissingPrincipalInfo)
66
67
  class MissingPrincipal:
67
68
  """Missing principal info
68
69
 
@@ -91,3 +92,9 @@ def get_principal_annotations(principal):
91
92
  if annotations is not None:
92
93
  return annotations.getAnnotations(principal)
93
94
  return None
95
+
96
+
97
+ @adapter_config(required=IUnavailablePrincipalInfo, provides=IAnnotations)
98
+ def unavailable_principal_annotations(principal):
99
+ """Unavailable principal annotations adapter"""
100
+ return None
@@ -42,15 +42,17 @@ class Role:
42
42
  description = FieldProperty(IRole['description'])
43
43
  permissions = FieldProperty(IRole['permissions'])
44
44
  managers = FieldProperty(IRole['managers'])
45
+ custom_data = FieldProperty(IRole['custom_data'])
45
46
 
46
47
  def __init__(self, values=None, **args):
47
48
  if not isinstance(values, dict):
48
49
  values = args
49
- self.id = values.get('id') # pylint: disable=invalid-name
50
- self.title = values.get('title')
51
- self.description = values.get('description')
52
- self.permissions = values.get('permissions')
53
- self.managers = values.get('managers')
50
+ self.id = values.pop('id') # pylint: disable=invalid-name
51
+ self.title = values.pop('title')
52
+ self.description = values.pop('description', None)
53
+ self.permissions = values.pop('permissions', set())
54
+ self.managers = values.pop('managers', set())
55
+ self.custom_data = values or {}
54
56
 
55
57
 
56
58
  class RoleSelector:
@@ -111,6 +113,7 @@ def register_role(config, role):
111
113
  (role.permissions or set())
112
114
  role_utility.managers = (role_utility.managers or set()) | \
113
115
  (role.managers or set())
116
+ role_utility.custom_data.update(role.custom_data)
114
117
 
115
118
 
116
119
  def upgrade_role(config, role, required=True, **kwargs):
@@ -126,10 +129,13 @@ def upgrade_role(config, role, required=True, **kwargs):
126
129
  if required:
127
130
  raise ConfigurationError("Provided role isn't registered!")
128
131
  return
129
- if 'permissions' in kwargs:
130
- role.permissions = (role.permissions or set()) | set(kwargs['permissions'])
131
- if 'managers' in kwargs:
132
- role.managers = (role.managers or set()) | set(kwargs['managers'])
132
+ permissions = kwargs.pop('permissions', None)
133
+ if permissions:
134
+ role.permissions = (role.permissions or set()) | set(permissions)
135
+ managers = kwargs.pop('managers', None)
136
+ if managers:
137
+ role.managers = (role.managers or set()) | set(managers)
138
+ role.custom_data.update(kwargs)
133
139
 
134
140
 
135
141
  @vocabulary_config(name=ROLES_VOCABULARY_NAME)
@@ -111,7 +111,7 @@ class SecurityManager(Folder):
111
111
  return credentials
112
112
  return None
113
113
 
114
- def authenticate(self, credentials, request, get_plugin_name=False):
114
+ def authenticate(self, credentials, request, get_plugin_name=False, get_plugin=False):
115
115
  """Try to authenticate request with given credentials"""
116
116
  for plugin in self.authentication_plugins:
117
117
  try:
@@ -121,10 +121,13 @@ class SecurityManager(Folder):
121
121
  continue
122
122
  else:
123
123
  if principal_id is not None:
124
- if get_plugin_name:
124
+ if get_plugin:
125
+ return principal_id, plugin
126
+ elif get_plugin_name:
125
127
  return principal_id, plugin.prefix
126
- return principal_id
127
- return (None, None) if get_plugin_name else None
128
+ else:
129
+ return principal_id
130
+ return (None, None) if (get_plugin or get_plugin_name) else None
128
131
 
129
132
  def authenticated_userid(self, request, principal_id=None):
130
133
  """Extract authenticated user ID from request"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyams-security
3
- Version: 2.1.2
3
+ Version: 2.3.0
4
4
  Summary: PyAMS security management package
5
5
  Home-page: https://pyams.readthedocs.io
6
6
  Author: Thierry Florac
@@ -54,6 +54,20 @@ store roles assigned to principals.
54
54
  Changelog
55
55
  =========
56
56
 
57
+ 2.3.0
58
+ -----
59
+ - allow case-insensitive local user login
60
+
61
+ 2.2.1
62
+ -----
63
+ - added support for custom attributes in roles
64
+
65
+ 2.2.0
66
+ -----
67
+ - added marker interface to handle unknown or missing principals
68
+ - added argument to security manager authentication method to get plugins instance
69
+ instead of plugin name
70
+
57
71
  2.1.2
58
72
  -----
59
73
  - renamed UnknownPrincipal class to avoid strange pickle behaviour...
File without changes
File without changes