Apache-AxKit-Plugin-Session
view release on metacpan or search on metacpan
lib/AxKit/XSP/Auth.pm view on Meta::CPAN
{
return << 'EOC';
foreach my $perm (@{$_{"access"}}) {
if (!exists $$session{"auth_access_".$$perm{'type'}}) {
$$session{"auth_access_".$$perm{'type'}} = $$perm{'value'};
} elsif (!ref($$session{"auth_access_".$$perm{'type'}})) {
$$session{"auth_access_".$$perm{'type'}} = {$$perm{'value'} => undef, $$session{"auth_access_".$$perm{'type'}} => undef};
} else {
$$session{"auth_access_".$$perm{'type'}}{$$perm{'value'}} = undef;
}
}
EOC
}
sub rem_access : XSP_childStruct(@access{$type *value})
{
return << 'EOC';
foreach my $perm (@{$_{"access"}}) {
next if (!exists $$session{"auth_access_".$$perm{'type'}});
if (!defined $$perm{'value'}) {
delete $$session{"auth_access_".$$perm{'type'}};
} elsif (!ref($$session{"auth_access_".$$perm{'type'}})) {
delete $$session{"auth_access_".$$perm{'type'}} if $$session{"auth_access_".$$perm{'type'}} eq $$perm{'value'};
} else {
delete $$session{"auth_access_".$$perm{'type'}}{$$perm{'value'}};
}
}
EOC
}
sub login : XSP_attribOrChild(destination,exclusive) XSP_childStruct(@access{$type *value})
{
my $res = << 'EOC';
my $auth_type = $r->auth_type || "Apache::AxKit::Plugin::Session";
no strict 'refs';
Apache::Request->instance($r)->param('credential_0',$$session{'auth_access_user'});
my $rc;
if (defined $attr_destination) {
$rc = $auth_type->login($r,$attr_destination);
} else {
$rc = $auth_type->login($r);
}
$session = $r->pnotes('SESSION');
EOC
$res .= set_access(@_);
return $res.<<'EOC';
$rc = $auth_type->external_redirect($attr_destination||$r->uri) if $rc == OK && $attr_destination ne 'none';
my $old_id = $$global{'auth_online_users'}{$$session{'auth_access_user'}};
if ($attr_exclusive ne '0' && lc($attr_exclusive) ne 'no' && lc($attr_exclusive) ne 'off') {
if ($old_id && $old_id ne $$session{'_session_id'}) {
my $oldsession = $auth_type->_get_session_from_store($r,$old_id);
eval {
%$oldsession = ('_session_id' => $old_id);
tied(%$oldsession)->delete;
};
}
$$global{'auth_online_users'} ||= {};
$$global{'auth_online_users'}{$$session{'auth_access_user'}} = $$session{'_session_id'};
$$global{'auth_logins'}++;
}
throw Apache::AxKit::Exception::Retval(return_code => $rc) unless $attr_destination eq 'none';
EOC
}
sub logout : XSP_attribOrChild(destination)
{
return set_access(@_).<< 'EOC';
my $auth_type = $r->auth_type || 'Apache::AxKit::Plugin::Session';
no strict 'refs';
my $rc;
if (exists $$global{'auth_online_users'}{$$session{'auth_access_user'}}) {
delete $$global{'auth_online_users'}{$$session{'auth_access_user'}};
$$global{'auth_logouts'}++;
}
if (defined $attr_destination) {
$rc = $auth_type->logout($r,$attr_destination);
} else {
$rc = $auth_type->logout($r,$r->uri);
}
throw Apache::AxKit::Exception::Retval(return_code => $rc);
EOC
}
sub check_permission : XSP_attribOrChild(target,reason) XSP_childStruct($text(lang))
{
return 'if (do {'.has_permission(@_).'}) { '.deny_permission(@_).' }';
}
sub deny_permission : XSP_attribOrChild(reason) XSP_childStruct($text(lang))
{
return '$$session{"auth_reason"} = $attr_reason || "permission_denied"; $$session{"auth_reason_desc"} = $_{"text"}; throw Apache::AxKit::Exception::Retval(return_code => Apache::Constants::FORBIDDEN); ';
}
sub has_permission : XSP_attribOrChild(target) XSP_expr
{
return 'Apache::AxKit::Plugin::Session::has_permission($r,$attr_target)?1:0';
}
sub is_logged_in : XSP_expr
{
return '$$session{"auth_access_user"} ne "guest"?1:0';
}
sub get_permission : XSP_attribOrChild(target) XSP_struct
{
return << 'EOC';
$attr_target = URI->new_abs($attr_target, $r->uri);
if (my $subr = $r->lookup_uri($attr_target)) {
$subr->pnotes('SESSION',$session);
my $type = $subr->auth_type || 'Apache::AxKit::Plugin::Session';
{ "permission" => [ map { AxKit::XSP::Auth::perm2struct($_) } ($type->get_permission_set($subr)) ] };
} else {
{ }
}
EOC
}
sub set_permission : XSP_attribOrChild(target) XSP_childStruct(@permission{$type *value &permission})
{
return << 'EOC';
$attr_target = URI->new_abs($attr_target, $r->uri);
my $subr = $r->lookup_uri($attr_target);
$subr->pnotes('SESSION',$session);
my $type = $subr->auth_type || 'Apache::AxKit::Plugin::Session';
$type->set_permission_set($subr,map { AxKit::XSP::Auth::struct2perm($_) } @{$_{'permission'} || []});
EOC
}
sub add_permission : XSP_attribOrChild(target) XSP_childStruct(@permission{$type *value &permission})
{
return << 'EOC';
$attr_target = URI->new_abs($attr_target, $r->uri);
my $subr = $r->lookup_uri($attr_target);
$subr->pnotes('SESSION',$session);
my $type = $subr->auth_type || 'Apache::AxKit::Plugin::Session';
$type->set_permission_set($subr,@{($type->get_permission_set($subr)) || []},map { AxKit::XSP::Auth::struct2perm($_) } @{$_{'permission'} || []});
EOC
}
sub rem_permission : XSP_attribOrChild(target) XSP_childStruct(@permission{$type *value &permission})
{
return << 'EOC';
$attr_target = URI->new_abs($attr_target, $r->uri);
my $subr = $r->lookup_uri($attr_target);
$subr->pnotes('SESSION',$session);
my $type = $subr->auth_type || 'Apache::AxKit::Plugin::Session';
my @set = @{($type->get_permission_set($subr)) || []};
foreach my $perm (@{$_{'permission'} || []}) {
@set = grep { !perm_equals($_,AxKit::XSP::Auth::struct2perm($perm)) } @set;
}
$type->set_permission_set($subr,@set);
( run in 0.508 second using v1.01-cache-2.11-cpan-39bf76dae61 )