commit | author | age
|
b32552
|
1 |
from webob import Response |
99edc5
|
2 |
from pyramid.httpexceptions import HTTPForbidden |
6df90b
|
3 |
from pyramid.compat import bytes_ |
b32552
|
4 |
|
0c29cf
|
5 |
|
MM |
6 |
def x_view(request): # pragma: no cover |
|
7 |
return Response('this is private!') |
|
8 |
|
b32552
|
9 |
|
CM |
10 |
def forbidden_view(context, request): |
0c29cf
|
11 |
msg = context.message |
MM |
12 |
result = context.result |
|
13 |
message = msg + '\n' + str(result) |
|
14 |
resp = HTTPForbidden() |
|
15 |
resp.body = bytes_(message) |
|
16 |
return resp |
|
17 |
|
b32552
|
18 |
|
CM |
19 |
def includeme(config): |
0c29cf
|
20 |
from pyramid.authentication import AuthTktAuthenticationPolicy |
MM |
21 |
from pyramid.authorization import ACLAuthorizationPolicy |
|
22 |
|
|
23 |
authn_policy = AuthTktAuthenticationPolicy('seekr1t', hashalg='sha512') |
|
24 |
authz_policy = ACLAuthorizationPolicy() |
|
25 |
config._set_authentication_policy(authn_policy) |
|
26 |
config._set_authorization_policy(authz_policy) |
|
27 |
config.add_view(x_view, name='x', permission='private') |
|
28 |
config.add_view(forbidden_view, context=HTTPForbidden) |