annotate Lib/Security/Authz.pm @ 43:009aa9ca2e48

merge
author Sergey
date Thu, 07 Jan 2010 15:41:49 +0300
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package Security::Authz;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use Security;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 our @ISA = qw(Object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 DeclareProperty User => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 sub _CurrentUser {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 my ($class) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 if (ref $class) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 return $class->{$User};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 if (Security->CurrentSession) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 Security->CurrentSession->User;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 return undef;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 sub demand {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 my ($class,@Roles) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 return 0 if not $class->_CurrentUser;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 my %UserRoles = map { $_->Name, 1 } $class->_CurrentUser->Roles;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 return not grep {not $UserRoles{$_}} @Roles;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 }