<div dir="ltr">RoleFromEmailDomain could be a good feature, why not.<div><br></div><div>you can extact the domain with a more simple way. </div><div><br></div><div>domain = email.split("@")[-1]</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jul 7, 2017 at 12:05 PM Paulo Matos <pmatos@linki.tools> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 07/07/17 11:43, Pierre Tardy wrote:<br>
><br>
><br>
> On Fri, Jul 7, 2017 at 11:30 AM Paulo Matos <pmatos@linki.tools> wrote:<br>
><br>
><br>
><br>
> On 07/07/17 10:47, Pierre Tardy wrote:<br>
> > Hi Paulo,<br>
> ><br>
> > This is not something that is supported by current code.<br>
><br>
> By 'This' you mean disabling anonymous access?<br>
><br>
> By this I mean using '*' in getRolesFromEmails.<br>
><br>
> The design for people who need tight control like disabling anonymous<br>
> access is more to use an authentication plugin that supports group (or<br>
> create one for themselves)<br>
<br>
Not sure if I understood what you meant but this seems to work well:<br>
<br>
class RoleForDomain(util.RolesFromEmails):<br>
<br>
def __init__(self, **kwargs):<br>
super(util.RolesFromEmails, self).__init__()<br>
<br>
self.domain_roles = {}<br>
for role, domains in kwargs.items():<br>
for domain in domains:<br>
self.domain_roles.setdefault(domain, []).append(role)<br>
<br>
def getRolesFromUser(self, userDetails):<br>
if 'email' in userDetails:<br>
email = userDetails['email']<br>
edomain = re.search('@[a-zA-Z0-9_.]+', email).group()[1:]<br>
if edomain in self.domain_roles:<br>
roles = self.domain_roles[edomain]<br>
return roles<br>
return []<br>
<br>
authz = util.Authz(<br>
stringsMatcher=util.fnmatchStrMatcher,<br>
allowRules=[<br>
util.AnyEndpointMatcher(role="admin", defaultDeny=True),<br>
util.AnyControlEndpointMatcher(role="admin"),<br>
],<br>
roleMatchers=[<br>
RoleForDomain(admin=["<a href="http://matos-sorge.com" rel="noreferrer" target="_blank">matos-sorge.com</a>"])<br>
]<br>
)<br>
auth=util.UserPasswordAuth({'<a href="mailto:pmatos@matos-sorge.com" target="_blank">pmatos@matos-sorge.com</a>': 'foobar'})<br>
<br>
<br>
In this case if you are not logged in you won't see anything, but if you<br>
login as <a href="mailto:pmatos@matos-sorge.com" target="_blank">pmatos@matos-sorge.com</a>, you'll see everything. Not entirely<br>
clear on how it works, but it does. What I can't understand is really<br>
the endpoints bit which looks a bit complicated.<br>
<br>
Would you be interested in a pull request with the code for RoleForDomain?<br>
<br>
<br>
--<br>
Paulo Matos<br>
</blockquote></div>