Mercurial > pub > Impl
comparison Lib/IMPL/Security/Role.pm @ 230:6d8092d8ce1b
*reworked IMPL::Security
*reworked IMPL::Web::Security
*refactoring
author | sergey |
---|---|
date | Mon, 08 Oct 2012 03:37:37 +0400 |
parents | 4d0e1962161c |
children | 69a1f1508696 |
comparison
equal
deleted
inserted
replaced
229:47f77e6409f7 | 230:6d8092d8ce1b |
---|---|
1 package IMPL::Security::Role; | 1 package IMPL::Security::Role; |
2 use strict; | |
2 | 3 |
3 use parent qw(IMPL::Object); | 4 use IMPL::require { |
5 AbstractRole => 'IMPL::Security::AbstractRole' | |
6 }; | |
4 | 7 |
5 use IMPL::Class::Property; | 8 use IMPL::declare { |
9 base => [ | |
10 'IMPL::Object' => undef, | |
11 'IMPL::Security::AbstractRole' => undef | |
12 ], | |
13 props => [ | |
14 @{AbstractRole->abstractProps()} | |
15 ] | |
16 }; | |
6 | 17 |
7 BEGIN { | 18 __PACKAGE__->abstractProps([]); |
8 public property roleName => prop_get | owner_set; | 19 |
9 public property parentRoles => prop_get | owner_set | prop_list; | |
10 } | |
11 | 20 |
12 sub CTOR { | 21 sub CTOR { |
13 my ($this,$name,$parentRoles) = @_; | 22 my ($this,$name,$parentRoles) = @_; |
14 | 23 |
15 $this->roleName($name) if $name; | 24 $this->roleName($name) if $name; |
16 $this->parentRoles($parentRoles) if $parentRoles; | 25 $this->parentRoles($parentRoles) if $parentRoles; |
17 } | 26 } |
18 | |
19 sub Satisfy { | |
20 my ($this,@roles) = @_; | |
21 | |
22 return 1 unless $this->_FilterRoles( @roles ); | |
23 return 0; | |
24 } | |
25 | |
26 sub _FilterRoles { | |
27 my ($this,@roles) = @_; | |
28 | |
29 @roles = grep not (ref $_ ? $this == $_ : $this->roleName eq $_), @roles; | |
30 | |
31 @roles = $_->_FilterRoles(@roles) or return foreach $this->parentRoles ; | |
32 | |
33 return @roles; | |
34 } | |
35 | |
36 | 27 |
37 1; | 28 1; |
38 | 29 |
39 __END__ | 30 __END__ |
40 | 31 |
41 =pod | 32 =pod |
42 | 33 |
43 =head1 NAME | 34 =head1 NAME |
44 | 35 |
45 C<IMPL::Security::Role> Роль | 36 C<IMPL::Security::Role> - стандартная реализация роли безопасности. |
37 | |
38 =head1 SYNOPSIS | |
39 | |
40 =begin code | |
41 | |
42 # create the megarole | |
43 my $role = IMPL::Security::Role->new(megarole => [ $adminRole, $directorRole ] ); | |
44 | |
45 #use it in context | |
46 my $context = IMPL::Security::Context->new( | |
47 principal => $user, | |
48 assignedRoles => [$user->roles, $megarole] | |
49 ); | |
50 | |
51 $context->Impersonate( sub { | |
52 # do something forbidden | |
53 }); | |
54 | |
55 =end code | |
46 | 56 |
47 =head1 DESCRIPTION | 57 =head1 DESCRIPTION |
48 | 58 |
49 Может включать в себя базовые роли. | 59 Позволяет создавать объекты ролей без привязки к источникам данных и модулям |
50 Имеется метод для проверки наличия необходимых ролей в текущей роли. | 60 авторизации. Чаще всего используется при реализации каких либо механизмов |
61 безопасности, где требуется создать временную роль. | |
51 | 62 |
52 =head1 MEMBERS | 63 C<IMPL::Security::AbstractRole> |
53 | |
54 =over | |
55 | |
56 =item C<[get] roleName> | |
57 | |
58 Имя роли, ее идентификатор | |
59 | |
60 =item C<[get,list] parentRoles> | |
61 | |
62 Список родительских ролей | |
63 | |
64 =item C<Satisfy(@roles_list)> | |
65 | |
66 Проверяет наличие ролей указанных ролей из списка @roles_list. | |
67 Допускается использование как самих объектов, так и имен ролей. | |
68 Возвращает 0 в случае неудачи (хотябы одна роль не была удовлетворена), 1 при наличии необходимых ролей. | |
69 | |
70 =back | |
71 | 64 |
72 =cut | 65 =cut |