Changeset 2344


Ignore:
Timestamp:
04/10/20 11:27:06 (4 years ago)
Author:
nanardon
Message:

Ensure object from acl are deferenced to allow object alias to work

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Acls.pm

    r2320 r2344  
    171171 
    172172sub check { 
    173     my ($self, $obj, $attr, $perm, $who, $groups) = @_; 
     173    my ($self, $obj, $attr, $perm, $who, $groups, $base) = @_; 
    174174    # Asking 'r' perm over create or delete has no sense: 
    175175    $attr =~ /^@(CREATE|DELETE)$/ && $perm eq 'r' and return; 
    176176 
    177177    foreach my $acl (@{$self->{_acls}}, @{$self->{_default_acls}}) { 
    178         my $res = $acl->match($obj, $attr, $perm, $who, $groups); 
     178        my $res = $acl->match($obj, $attr, $perm, $who, $groups, $base); 
    179179        if ( defined($res) ) { 
    180180            if ( $ENV{LA_ACL_DEBUG} ) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Acls/Acl.pm

    r2343 r2344  
    6565} 
    6666 
    67 =head2 match($obj, $attr, $perm, $who, $groups) 
     67=head2 match($obj, $attr, $perm, $who, $groups, $base) 
    6868 
    6969Return true is this sub acl apply to C<$obj>/C<$attr> for C<$perm> by user 
     
    7373 
    7474sub match { 
    75     my ($self, $obj, $attr, $perm, $who, $groups) = @_; 
     75    my ($self, $obj, $attr, $perm, $who, $groups, $base) = @_; 
    7676    my $objtype = ref $obj ? lc($obj->type) : $obj; 
    7777    $attr = lc($attr); 
     
    8989        # Obj have attr eq login user 
    9090        if (substr($u->{user}, 0, 1) eq '$') { # check attr content 
    91             if (ref $obj) { 
    92                 my $attribute = substr($u->{user}, 1); 
    93                 my $val = $obj->_get_c_field($attribute) or return; 
    94                 my @vals = ref $val ? (@{ $val }) : ($val); 
    95                 foreach (@vals) { 
    96                     my $uobj = $obj->base->get_object('user', $_) or next; 
    97                     return $u->{$perm} if ($uobj->id eq $who); 
    98                 } 
     91            my $attribute = substr($u->{user}, 1); 
     92            my $val = $obj->_get_c_field($attribute) or return; 
     93            my @vals = ref $val ? (@{ $val }) : ($val); 
     94            foreach (@vals) { 
     95                return $u->{$perm} if ($self->_objId('user', $_, $base) eq $who); 
    9996            } 
    10097        # user is in group 
    10198        } elsif (substr($u->{user}, 0, 1) eq '%') { # group 
    10299            my $group = substr($u->{user}, 1); 
    103             return $u->{$perm} if (grep { $group eq $_ } grep { $_ } @{$groups ||[]}); 
     100            return $u->{$perm} if (grep { $self->_objId('group', $group, $base) eq $_ } grep { $_ } @{$groups ||[]}); 
    104101        # any user 
    105102        } elsif ($u->{user} eq '*' || $u->{user} eq $who) { 
     
    116113    } 
    117114    return; 
     115} 
     116 
     117sub _objId { 
     118    my ( $self, $otype, $id, $base ) = @_; 
     119 
     120    $base or return $id; 
     121 
     122    my $obj = $base->get_object( $otype, $id ) or return $id; 
     123 
     124    return $obj->AclID; 
    118125} 
    119126 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r2316 r2344  
    12771277            $who = ''; 
    12781278        } 
    1279         my $res = $self->{_acls}->check($obj, $attr, $perm, $who, $groups); 
     1279        my $res = $self->{_acls}->check($obj, $attr, $perm, $who, $groups, $self); 
    12801280        $self->log(LA_INFO, 'permission denied for "%s" to get %s.%s for %s', 
    12811281           $who, ref $obj ? $obj->id . '(' . $obj->type . ')' : $obj, $attr, $perm) if (!$res); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r2342 r2344  
    129129    $self->{_id} 
    130130} 
     131 
     132=head2 AclID 
     133 
     134Return object for acl check 
     135 
     136=cut 
     137 
     138sub AclID { $_[0]->id } 
    131139 
    132140=head2 Iid 
Note: See TracChangeset for help on using the changeset viewer.