Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Do you know where your variables are?
 
PerlMonks  

Re^4: User access controlled by subroutine attribute.

by rlb3 (Deacon)
on Aug 14, 2006 at 17:49 UTC ( [id://567349]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^3: User access controlled by subroutine attribute.
in thread User access controlled by subroutine attribute.

That is true but then there is no point of making access attached to each sub with an attribute.

  • Comment on Re^4: User access controlled by subroutine attribute.

Replies are listed 'Best First'.
Re^5: User access controlled by subroutine attribute.
by gellyfish (Monsignor) on Aug 15, 2006 at 04:06 UTC

    I see it as protection from developer error. You probably want to have authorization handled in a way that allows you to both restrict the overt choices that a user can make and also to give the user a more friendly message up front, which all probably requires explicit coding nearer the front end. However if there is the possibility of an unintended method getting called (a typo in a dispatch table or an unchecked action parameter for instance,) then you might feel it is appropriate to prevent that method being called by unauthorized users. Call it a belt and braces approach.

    /J\

      Hello, All

      Thank you all for your responses. After thinking about it I decided to make a basic implementation.

      package Access::Attribute; use strict; use warnings; use Attribute::Handlers; use Data::Dumper; sub UNIVERSAL::access_root : ATTR(CODE) { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; if ($< != 0) { die "Access Denied to subroutine " . *{$symbol}{NAME} . "\n"; } } sub UNIVERSAL::access_list : ATTR(CODE) { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; return if !$data; my @data = (ref $data) ? @$data : $data; my $match = 0; for my $user (@data) { my @passwd = getpwnam($user); next if !@passwd; $match = 1 if $< == $passwd[2]; } if ($match == 0) { die "Access Denied to subroutine " . *{$symbol}{NAME} . "\n"; } } 1;

      This is mostly to teach myself Attributes, but I thought I would share it.

      Thanks,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://567349]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.