File Coverage

blib/lib/Apache/Sling/AuthzUtil.pm
Criterion Covered Total %
statement 55 55 100.0
branch 20 20 100.0
condition n/a
subroutine 13 13 100.0
pod 6 6 100.0
total 94 94 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package Apache::Sling::AuthzUtil;
4              
5 2     2   24462 use 5.008001;
  2         8  
  2         72  
6 2     2   11 use strict;
  2         3  
  2         81  
7 2     2   10 use warnings;
  2         5  
  2         49  
8 2     2   11 use Carp;
  2         3  
  2         158  
9              
10             require Exporter;
11              
12 2     2   10 use base qw(Exporter);
  2         9  
  2         203  
13              
14             our @EXPORT_OK = ();
15              
16             our $VERSION = '0.27';
17              
18             #{{{imports
19 2     2   10 use strict;
  2         4  
  2         53  
20 2     2   1660 use lib qw ( .. );
  2         1300  
  2         11  
21              
22             #}}}
23              
24             #{{{sub get_acl_setup
25              
26             =pod
27              
28             =head2 get_acl_setup
29              
30             Returns a textual representation of the request needed to retrieve the ACL for
31             a node in JSON format.
32              
33             =cut
34              
35             sub get_acl_setup {
36 3     3 1 164 my ( $base_url, $remote_dest ) = @_;
37 3 100       18 croak "No base url defined!" unless defined $base_url;
38 2 100       30 croak "No destination to view ACL for defined!" unless defined $remote_dest;
39 1         11 return "get $base_url/$remote_dest.acl.json";
40             }
41              
42             #}}}
43              
44             #{{{sub get_acl_eval
45              
46             =pod
47              
48             =head2 get_acl_eval
49              
50             Inspects the result returned from issuing the request generated in
51             get_acl_setup returning true if the result indicates the node ACL was returned
52             successfully, else false.
53              
54             =cut
55              
56             sub get_acl_eval {
57 1     1 1 3 my ($res) = @_;
58 1         6 return ( $$res->code =~ /^200$/x );
59             }
60              
61             #}}}
62              
63             #{{{sub delete_setup
64              
65             =pod
66              
67             =head2 delete_setup
68              
69             Returns a textual representation of the request needed to retrieve the ACL for
70             a node in JSON format.
71              
72             =cut
73              
74             sub delete_setup {
75 4     4 1 375 my ( $base_url, $remote_dest, $principal ) = @_;
76 4 100       21 croak "No base url defined!" unless defined $base_url;
77 3 100       16 croak "No destination to delete ACL for defined!"
78             unless defined $remote_dest;
79 2 100       14 croak "No principal to delete ACL for defined!" unless defined $principal;
80 1         3 my $post_variables = "\$post_variables = [':applyTo','$principal']";
81 1         7 return "post $base_url/$remote_dest.deleteAce.html $post_variables";
82             }
83              
84             #}}}
85              
86             #{{{sub delete_eval
87              
88             =pod
89              
90             =head2 delete_eval
91              
92             Inspects the result returned from issuing the request generated in delete_setup
93             returning true if the result indicates the node ACL was deleted successfully,
94             else false.
95              
96             =cut
97              
98             sub delete_eval {
99 1     1 1 3 my ($res) = @_;
100 1         6 return ( $$res->code =~ /^200$/x );
101             }
102              
103             #}}}
104              
105             #{{{sub modify_privilege_setup
106              
107             =pod
108              
109             =head2 modify_privilege_setup
110              
111             Returns a textual representation of the request needed to modify the privileges
112             on a node for a specific principal.
113              
114             =cut
115              
116             sub modify_privilege_setup {
117 13     13 1 2509 my ( $base_url, $remote_dest, $principal, $grant_privileges,
118             $deny_privileges )
119             = @_;
120 13 100       46 croak "No base url defined!" unless defined $base_url;
121 12 100       37 croak "No destination to modify privilege for defined!"
122             unless defined $remote_dest;
123 11 100       31 croak "No principal to modify privilege for defined!"
124             unless defined $principal;
125 10         85 my %privileges = (
126             'read', 1, 'modifyProperties', 1,
127             'addChildNodes', 1, 'removeNode', 1,
128             'removeChildNodes', 1, 'write', 1,
129             'readAccessControl', 1, 'modifyAccessControl', 1,
130             'lockManagement', 1, 'versionManagement', 1,
131             'nodeTypeManagement', 1, 'retentionManagement', 1,
132             'lifecycleManagement', 1, 'all', 1
133             );
134 10         22 my $post_variables = "\$post_variables = ['principalId','$principal',";
135 10         14 foreach my $grant ( @{$grant_privileges} ) {
  10         23  
136 29 100       62 if ( $privileges{$grant} ) {
137 28         61 $post_variables .= "'privilege\@jcr:$grant','granted',";
138             }
139             else {
140 1         13 croak "Unsupported grant privilege: \"$grant\" supplied!\n";
141             }
142             }
143 9         14 foreach my $deny ( @{$deny_privileges} ) {
  9         20  
144 29 100       55 if ( $privileges{$deny} ) {
145 28         69 $post_variables .= "'privilege\@jcr:$deny','denied',";
146             }
147             else {
148 1         13 croak "Unsupported deny privilege: \"$deny\" supplied!\n";
149             }
150             }
151 8         37 $post_variables =~ s/,$/]/x;
152 8         76 return "post $base_url/$remote_dest.modifyAce.html $post_variables";
153             }
154              
155             #}}}
156              
157             #{{{sub modify_privilege_eval
158              
159             =pod
160              
161             =head2 modify_privilege_eval
162              
163             Inspects the result returned from issuing the request generated in
164             modify_privilege_setup returning true if the result indicates the privileges
165             were modified successfully, else false.
166              
167             =cut
168              
169             sub modify_privilege_eval {
170 1     1 1 2 my ($res) = @_;
171 1         7 return ( $$res->code =~ /^200$/x );
172             }
173              
174             #}}}
175              
176             1;
177              
178             __END__