Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authomatic can be set roles after login #35

Closed
wants to merge 17 commits into from
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.0b2 (unreleased)
------------------

- Implementation of IRolesPlugin to set roles to connected user (through provider).
[bsuttor]

- Add french translation
[mpeeters]

Expand Down
2 changes: 2 additions & 0 deletions src/pas/plugins/authomatic/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
zcml:condition="not-have plone-5"
/>

<include package="Products.CMFCore" file="permissions.zcml" />

<!-- Control panel -->
<browser:page
class=".controlpanel.AuthomaticSettingsEditFormSettingsControlPanel"
Expand Down
19 changes: 19 additions & 0 deletions src/pas/plugins/authomatic/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def manage_addAuthomaticPlugin(context, id, title='', RESPONSE=None, **kw):
pas_interfaces.IAuthenticationPlugin,
pas_interfaces.IPropertiesPlugin,
pas_interfaces.IUserEnumerationPlugin,
pas_interfaces.IRolesPlugin
)
class AuthomaticPlugin(BasePlugin):
"""Authomatic PAS Plugin
Expand Down Expand Up @@ -287,5 +288,23 @@ def enumerateUsers(
return sorted(ret, key=itemgetter(sort_by))
return ret

@security.private
def getRolesForPrincipal(self, user, request=None):
""" Fullfill RolesPlugin requirements """
identity = self._useridentities_by_userid.get(user.getId(), None)
if not identity:
return ()
keys = [key for key in identity._identities.keys()]
provider_id = keys[0]

if 'roles' in identity._identities[provider_id].keys():
roles = identity._identities[provider_id]['roles']
if isinstance(roles, list):
return tuple(roles)
else:
return ()
else:
return ()


InitializeClass(AuthomaticPlugin)