Mercurial > pub > Impl
comparison Lib/Security/Authz.pm @ 0:03e58a454b20
Создан репозитарий
author | Sergey |
---|---|
date | Tue, 14 Jul 2009 12:54:37 +0400 |
parents | |
children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:03e58a454b20 |
---|---|
1 package Security::Authz; | |
2 use Common; | |
3 use Security; | |
4 | |
5 our @ISA = qw(Object); | |
6 | |
7 BEGIN { | |
8 DeclareProperty User => ACCESS_READ; | |
9 } | |
10 | |
11 sub _CurrentUser { | |
12 my ($class) = @_; | |
13 | |
14 if (ref $class) { | |
15 return $class->{$User}; | |
16 } else { | |
17 if (Security->CurrentSession) { | |
18 Security->CurrentSession->User; | |
19 } else { | |
20 return undef; | |
21 } | |
22 } | |
23 } | |
24 | |
25 sub demand { | |
26 my ($class,@Roles) = @_; | |
27 | |
28 return 0 if not $class->_CurrentUser; | |
29 | |
30 my %UserRoles = map { $_->Name, 1 } $class->_CurrentUser->Roles; | |
31 | |
32 return not grep {not $UserRoles{$_}} @Roles; | |
33 } |