Personal tools
You are here: Home Documentation Manuals PAS reference manual Developing for PAS The user object Roles plugin
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

3.2.6. Roles plugin

Up one level

The IRolesPlugin plugins determine the global roles for a principal. Like the other interfaces the IRolesPlugin interface contains only a single method:

def getRolesForPrincipal( principal, request=None ):

""" principal -> ( role_1, ... role_N )

o Return a sequence of role names which the principal has.

o May assign roles based on values in the REQUEST object, if present.
"""

Here is a simple example:

def getRolesForPrincipal(self, principal, request=None):
# Only act on the current user
if getSecurityManager().getUser().getId()!=principal:
return ()

# Only act if the request originates from the local host
if request is not None:
ip=request.get("HTTP_X_FORWARDED_FOR", request.get("REMOTE_ADDR", ""))
if ip!="127.0.0.1":
return ()

return ("Manager",)

This gives the current user in Manager role if the site is being accessed from the Zope server itself.

by Wichert Akkerman last modified April 2, 2007 - 08:02 All content is copyright Plone Foundation and the individual contributors.

remove roles with a roles plugin

Posted by unset at July 14, 2008 - 23:32
I see how such a plugin can add roles to those added by other roles plugins, but is it possible to *REMOVE* roles that are assigned by other roles plugins? For instance, I may want to strip all but the Member role if you are authenticating from IP's outside of organization.

Re: remove roles with a roles plugin

Posted by Wichert Akkerman at July 15, 2008 - 07:00
No, as the interface clearly states a roles plugin can only add roles, If you want to prevent roles from being added you will need to customize the role plugin that sets them.

Re: remove roles with a roles plugin

Posted by unset at July 16, 2008 - 19:23
Thanks for the reply. If you have multiple roles plugins (portal_role_manager, local_roles, an LDAP plugin, etc.), you'd have to customize them all. That doesn't sound modular to me. If you could chain them, each having an opportunity to modify the set of roles (either add or subtract), then you could write a single plugin that could modify the results of any other. I guess this would be a major shift in the PAS architecture.

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by