-
Notifications
You must be signed in to change notification settings - Fork 46
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
Use pyramid SecurityPolicy #9955
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from pyramid.authentication import AuthTktCookieHelper | ||
from pyramid.authorization import ACLHelper, Authenticated, Everyone | ||
from pyramid.interfaces import ISecurityPolicy | ||
|
||
from c2cgeoportal_geoportal.resources import defaultgroupsfinder | ||
from jinja2.runtime import identity | ||
from macaroonbakery.bakery._identity import Identity | ||
|
||
|
||
class SecurityPolicy(ISecurityPolicy): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it normal that self is missing in the ISecurityPolicy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for other interfaces, but pretty sure we do not really need inheritance, just a class and methods with such prototype. |
||
def __init__( | ||
self, | ||
identity_providers: List([Callable[pyramid.request.request], Dict[str, Any]]), | ||
groupfinder: Callable[[str, pyramid.request.Request], List[str]], | ||
): | ||
self.groupfinder = groupfinder or defaultgroupsfinder | ||
self.helper = AuthTktCookieHelper(secret) | ||
|
||
def identity(self, request: pyramid.request.Request) -> Dict[str, Any]: | ||
for identity_provider in [self.helper.identify, self.identity_providers]: | ||
identity = identity_provider(request) | ||
if identity is not None: | ||
return Identity | ||
return None | ||
|
||
def authenticated_userid(self, request: pyramid.request.Request): | ||
identity = request.identity | ||
if identity is not None: | ||
return identity['userid'] | ||
|
||
def permits( | ||
self, | ||
request: pyramid.request.Request, | ||
context, | ||
permission, | ||
): | ||
identity = request.identity | ||
principals = set([Everyone]) | ||
if identity is not None: | ||
principals.add(Authenticated) | ||
principals.add(identity['userid']) | ||
user = request.user | ||
principals.update(self.groupfinder(user)) | ||
return ACLHelper().permits(context, principals, permission) | ||
|
||
def remember(self, request, userid, **kw): | ||
return self.helper.remember(request, userid, **kw) | ||
|
||
def forget(self, request, **kw): | ||
return self.helper.forget(request, **kw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDE imports, remove