Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
11
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

27. SECURITY

27.1 Enabling an Authorization Policy

By default, Pyramid enables no authorization policy. All views are accessible by completely anonymous users. In order to begin protecting views from execution based on security settings, you need to enable an authorization policy.

27.1.1 Enabling an Authorization Policy Imperatively

Use the set_authorization_policy() method of the Configurator to enable an authorization policy.

You must also enable an authentication policy in order to enable the authorization policy. This is because authorization, in general, depends upon authentication. Use the set_authentication_policy() and method during application setup to specify the authentication policy.

For example:

1

2

3

4

5

6

7

8

from pyramid.config import Configurator

from pyramid.authentication import AuthTktAuthenticationPolicy from pyramid.authorization import ACLAuthorizationPolicy authentication_policy = AuthTktAuthenticationPolicy(’seekrit’) authorization_policy = ACLAuthorizationPolicy()

config = Configurator() config.set_authentication_policy(authentication_policy) config.set_authorization_policy(authorization_policy)

latex-note.png

the authentication_policy and authorization_policy arguments may also be passed to their respective methods mentioned above as dotted Python name values, each representing the dotted name path to a suitable implementation global defined at Python module scope.

The above configuration enables a policy which compares the value of an “auth ticket” cookie passed in the request’s environment which contains a reference to a single principal against the principals present in any ACL found in the resource tree when attempting to call some view.

294

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]