comparison Lib/IMPL/Security.pm @ 247:2270de2469ff

sync
author sergey
date Wed, 31 Oct 2012 04:18:35 +0400
parents 7c517134c42f
children 814d755e5d12
comparison
equal deleted inserted replaced
246:2746a8e5a6c4 247:2270de2469ff
3 use Carp qw(carp); 3 use Carp qw(carp);
4 4
5 ##VERSION## 5 ##VERSION##
6 6
7 require IMPL::Exception; 7 require IMPL::Exception;
8 require IMPL::Security::Principal;
9 require IMPL::Security::AbstractContext;
10 require IMPL::Security::Rule::RoleCheck; 8 require IMPL::Security::Rule::RoleCheck;
11 9
12 our @rules = ( 10 use IMPL::require {
13 \&IMPL::Security::Rule::RoleCheck::SatisfyAll 11 Principal => 'IMPL::Security::Principal',
14 ); 12 AbstractContext => 'IMPL::Security::AbstractContext',
15 13 Context => 'IMPL::Security::Context'
16 our $authority = undef; 14 };
15
16 our @RULES;
17 17
18 sub AccessCheck { 18 sub AccessCheck {
19 my ($self, $object, $desiredAccess, $context) = @_; 19 my ($self, $object, $desiredAccess, $context) = @_;
20 20
21 $context ||= IMPL::Security::AbstractContext->context; 21 $context ||= $self->context;
22 22
23 $_->() or return 0 foreach @{$self->Rules}; 23 $_->($self,$object,$desiredAccess,$context) or return 0 foreach @{$self->Rules};
24 24
25 return 1; 25 return 1;
26 } 26 }
27 27
28 sub Take { 28 sub Take {
32 } 32 }
33 33
34 sub MakeContext { 34 sub MakeContext {
35 my ($this,$principal,$refRoles,$auth) = @_; 35 my ($this,$principal,$refRoles,$auth) = @_;
36 36
37 return new IMPL::Security::Context( 37 return Context->new(
38 principal => $principal, 38 principal => $principal,
39 rolesAssigned => $refRoles, 39 rolesAssigned => $refRoles,
40 auth => $auth 40 auth => $auth
41 ); 41 );
42 } 42 }
43 43
44 sub Rules { 44 sub Rules {
45 return \@rules; 45 return \@RULES;
46 }
47
48 sub authority {
49 return $authority;
50 } 46 }
51 47
52 sub principal { 48 sub principal {
53 return 49 return
54 IMPL::Security::AbstractContext->current 50 AbstractContext->current
55 && IMPL::Security::AbstractContext->current->principal 51 && AbstractContext->current->principal
56 || IMPL::Security::Principal->nobody; 52 || Principal->nobody;
57 } 53 }
58 54
59 sub context { 55 sub context {
60 IMPL::Security::AbstractContext->current; 56 AbstractContext->current;
61 } 57 }
62 58
63 1; 59 1;
64 60
65 __END__ 61 __END__