NAME
My::Security - Implement a security object and basic operations
SYNOPSIS
use My::Security;
use SPOPS::Secure qw( :all );
# Create a security object with security level WRITE for user $user
# on object $obj
my $sec = My::Security->new();
$sec->{class} = ref $obj;
$sec->{object_id} = $obj->id;
$sec->{scope} = SEC_SCOPE_USER;
$sec->{scope_id} = $user->id;
$sec->{security_level} = SEC_LEVEL_WRITE;
$sec->save;
# Clone that object and change its scope to GROUP and level to READ
my $secg = $sec->clone({ scope => SEC_SCOPE_GROUP,
scope_id => $group->id,
security_level => SEC_LEVEL_READ });
$secg->save;
# Find security settings for a particular object ($spops) and user
my $settings = My::Security->fetch_by_object(
$spops,
{ user => [ $user ] } );
foreach my $scope ( keys %{ $settings } ) {
print "Security for scope $scope: $settings{ $scope }\n";
}
# See if there are any security objects protecting a particular SPOPS
# object ($spops) related to a particular user (this isn't used as
# often as 'fetch_by_object')
use SPOPS::Secure qw( SEC_SCOPE_USER );
my $sec_obj = My::Security->fetch_match( $spops,
{ scope => SEC_SCOPE_USER,
scope_id => $user->id } );
DESCRIPTION
This class works a little behind-the-scenes, so you probably will not deal directly with it very much. Instead, check out SPOPS::Secure for module developer (and other) information.
Each security setting to an object is itself an object. In this manner we can use the SPOPS framework to create/edit/remove security settings. (Note that if you modify this class to use 'SPOPS::Secure' in its @ISA, you will probably collapse the Earth -- or at least your system -- in a self-referential object definition cycle. Do not do that.)
METHODS
fetch_match( $obj, { scope = SCOPE, scope_id => $ } );
Returns a security object matching the $obj for the scope and scope_id passed in, undef if none found.
Examples:
my $sec_class = 'My::Security';
# Returns security object matching $obj with a scope of WORLD
my $secw = $sec_class->fetch_match( $obj,
{ scope => SEC_SCOPE_WORLD } );
# Returns security object matching $obj with a scope of GROUP
# matching the ID from $group
my $secg = $sec_class->fetch_match( $obj,
{ scope => SEC_SCOPE_GROUP,
scope_id => $group->id } );
# Returns security object matching $obj with a scope of USER
# matching the ID from $user
my $secg = $sec_class->fetch_match( $obj, scope => SEC_SCOPE_USER,
scope_id => $user->id );
fetch_by_object( $obj, [ { user = \@, group => \@ } ] )>
Returns a hashref with security information for a particular object. The keys of the hashref are SEC_SCOPE_WORLD, SEC_SCOPE_USER, and SEC_SCOPE_GROUP as exported by SPOPS::Secure.
You can restrict the security returned for USER and/or GROUP by passing an arrayref of objects or ID values under the 'user' or 'group' keys.
Examples:
my \%info = $sec->fetch_by_object( $obj );
Returns all security information for $obj.
my \%info = $sec->fetch_by_object( $obj, { user => [ 1, 2, 3 ] } );
Returns $obj security information for WORLD, all GROUPs but only USERs with ID 1, 2 or 3.
my \%info = $sec->fetch_by_object( $obj, { user => [ 1, 2, 3 ],
group => [ 817, 901, 716 ] } );
Returns $obj security information for WORLD, USERs 1, 2 and 3 and GROUPs 817, 901, 716.
TO DO
Nothing known.
BUGS
None known.
COPYRIGHT
Copyright (c) 2001-2002 intes.net, inc.. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHORS
Chris Winters <chris@cwinters.com>