| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | package Apache::Sling::AuthzUtil; | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | require Exporter; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | our @EXPORT_OK = (); | |||||||||
| 15 | |||||||||||
| 16 | 2 | our $VERSION = '0.27'; | |||||||||
| 17 | |||||||||||
| 18 | #{{{imports | ||||||||||
| 19 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use lib qw ( .. ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 3 | ▶ | sub get_acl_setup { | ||||||||
|
Subroutine
get_acl_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 36 | 3 | my ( $base_url, $remote_dest ) = @_; | |||||||||
| 37 | 3 | ▶ | croak "No base url defined!" unless defined $base_url; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 2 | ▶ | croak "No destination to view ACL for defined!" unless defined $remote_dest; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | 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 | 1 | ▶ | sub get_acl_eval { | ||||||||
|
Subroutine
get_acl_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 1 | my ($res) = @_; | |||||||||
| 58 | 1 | 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 | 4 | ▶ | sub delete_setup { | ||||||||
|
Subroutine
delete_setup: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 75 | 4 | my ( $base_url, $remote_dest, $principal ) = @_; | |||||||||
| 76 | 4 | ▶ | croak "No base url defined!" unless defined $base_url; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 3 | ▶ | croak "No destination to delete ACL for defined!" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | unless defined $remote_dest; | ||||||||||
| 79 | 2 | ▶ | croak "No principal to delete ACL for defined!" unless defined $principal; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 1 | my $post_variables = "\$post_variables = [':applyTo','$principal']"; | |||||||||
| 81 | 1 | 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 | 1 | ▶ | sub delete_eval { | ||||||||
|
Subroutine
delete_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 99 | 1 | my ($res) = @_; | |||||||||
| 100 | 1 | 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 | 13 | ▶ | sub modify_privilege_setup { | ||||||||
|
Subroutine
modify_privilege_setup: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||
| 117 | 13 | my ( $base_url, $remote_dest, $principal, $grant_privileges, | |||||||||
| 118 | $deny_privileges ) | ||||||||||
| 119 | = @_; | ||||||||||
| 120 | 13 | ▶ | croak "No base url defined!" unless defined $base_url; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 12 | ▶ | croak "No destination to modify privilege for defined!" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | unless defined $remote_dest; | ||||||||||
| 123 | 11 | ▶ | croak "No principal to modify privilege for defined!" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | unless defined $principal; | ||||||||||
| 125 | 10 | 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 | my $post_variables = "\$post_variables = ['principalId','$principal',"; | |||||||||
| 135 | 10 | foreach my $grant ( @{$grant_privileges} ) { | |||||||||
| 136 | 29 | ▶ | if ( $privileges{$grant} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | 28 | $post_variables .= "'privilege\@jcr:$grant','granted',"; | |||||||||
| 138 | } | ||||||||||
| 139 | else { | ||||||||||
| 140 | 1 | croak "Unsupported grant privilege: \"$grant\" supplied!\n"; | |||||||||
| 141 | } | ||||||||||
| 142 | } | ||||||||||
| 143 | 9 | foreach my $deny ( @{$deny_privileges} ) { | |||||||||
| 144 | 29 | ▶ | if ( $privileges{$deny} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 28 | $post_variables .= "'privilege\@jcr:$deny','denied',"; | |||||||||
| 146 | } | ||||||||||
| 147 | else { | ||||||||||
| 148 | 1 | croak "Unsupported deny privilege: \"$deny\" supplied!\n"; | |||||||||
| 149 | } | ||||||||||
| 150 | } | ||||||||||
| 151 | 8 | $post_variables =~ s/,$/]/x; | |||||||||
| 152 | 8 | 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 | 1 | ▶ | sub modify_privilege_eval { | ||||||||
|
Subroutine
modify_privilege_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 170 | 1 | my ($res) = @_; | |||||||||
| 171 | 1 | return ( $$res->code =~ /^200$/x ); | |||||||||
| 172 | } | ||||||||||
| 173 | |||||||||||
| 174 | #}}} | ||||||||||
| 175 | |||||||||||
| 176 | 2 | 1; | |||||||||
| 177 | |||||||||||
| 178 | __END__ | ||||||||||