| SPOPS documentation | Contained in the SPOPS distribution. |
SPOPS::Exception::Security - SPOPS exception with extra security parameters
my $object = eval { My::Class->fetch( $id ) };
if ( $@ ) {
if ( $@->isa( 'SPOPS::Exception::Security' ) ) {
print "Required security: ", $@->security_required, "\n",
"Found security: ", $@->security_found, "\n";
}
}
Same as SPOPS::Exception but we add two new properties:
security_required ($)
Security level that we were trying to meet.
security_found ($)
Security level found.
to_string()
We override the exception stringification to include the requested and found security levels (in human-readable format).
You can also use a shortcut if you are throwing errors:
use SPOPS::Exception::Security qw( spops_security_error );
...
spops_security_error "Security error trying to fetch foo ",
{ security_required => SEC_LEVEL_WRITE,
security_found => SEC_LEVEL_READ };
None known.
Nothing known.
Copyright (c) 2001-2004 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.
Chris Winters <chris@cwinters.com>
| SPOPS documentation | Contained in the SPOPS distribution. |
package SPOPS::Exception::Security; # $Id: Security.pm,v 3.2 2004/06/02 00:48:22 lachoy Exp $ use strict; use base qw( SPOPS::Exception ); use SPOPS::Secure qw( :verbose :level ); $SPOPS::Exception::Security::VERSION = sprintf("%d.%02d", q$Revision: 3.2 $ =~ /(\d+)\.(\d+)/); @SPOPS::Exception::Security::EXPORT_OK = qw( spops_security_error ); my @FIELDS = qw( security_required security_found ); SPOPS::Exception::Security->mk_accessors( @FIELDS ); my %LEVELS = ( SEC_LEVEL_NONE() => SEC_LEVEL_NONE_VERBOSE, SEC_LEVEL_SUMMARY() => SEC_LEVEL_SUMMARY_VERBOSE, SEC_LEVEL_READ() => SEC_LEVEL_READ_VERBOSE, SEC_LEVEL_WRITE() => SEC_LEVEL_WRITE_VERBOSE, ); sub get_fields { return ( $_[0]->SUPER::get_fields, @FIELDS ); } sub spops_security_error { goto &SPOPS::Exception( 'SPOPS::Exception::Security', @_ ); } sub to_string { my ( $self ) = @_; my $req = ( $self->security_required ) ? $LEVELS{ $self->security_required } : 'none specified'; my $fnd = ( $self->security_found ) ? $LEVELS{ $self->security_found } : 'none specified'; return "Security violation. Object requested [$req] and got [$fnd]"; } 1; __END__