Mojolicious::Plugin::RoutesAuthDBI::Access

¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !

NAME

Mojolicious::Plugin::RoutesAuthDBI::Access - Generation routes, authentication and controll access to routes trought sintax of ->over(...), see Mojolicious::Routes::Route#over

DB DESIGN DIAGRAM

See https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/blob/master/Diagram.svg

Generate the routes from DB

  • route -> actions.action <- controllers [ <- namespaces]

    Route to action method on controller. If no ref from namespace to controller then controller will find on $app->routes->namespaces as usual.

  • routes -> actions.callback

    Route to callback (no ref to controller, defined callback column (as text "sub {...}") in db table actions)

Access controll flow

There are two ways of flow: explicit and implicit.

  • Explicit access

    Check by tables ids: routes, actions, controllers, namespaces. Check refs to user roles ids.

  • Implicit access

    Access to routes by names: action, controller, namespace, role. This way used for db route to access namespace and for non db routes by syntax:

    $r->route('/foo')->...->to('foo#bar')->over(access=>{auth=>1})->...; 

    or

    $r->...->over(access=>{auth=>1, role => <id|name>})->...; # access to route by role id|name

SYNOPSIS

$app->plugin('RoutesAuthDBI', 
    dbh => $app->dbh,
    auth => {...},
    access => {< options below >},
);
  • namespace - default 'Mojolicious::Plugin::RoutesAuthDBI',

  • module - default 'Access' (this module),

    Both above options determining the module which will play as manager of authentication, accessing and generate routing from DBI source.

  • fail_auth_cb = sub {my $c = shift;...}

    This callback invoke when request need auth route but authentication was failure.

  • fail_access_cb = sub {my ($c, $route, $r_hash, $u) = @_;...}

    This callback invoke when request need auth route but access was failure. $route - Mojolicious::Routes::Route object, $r_hash - route hashref db item, $u - useer hashref.

EXPORT SUBS

  • load_user($c, $uid) - fetch user record from table users by COOKIES. Import for Mojolicious::Plugin::Authentication. Required.

  • validate_user($c, $login, $pass, $extradata) - fetch user record from table users by Mojolicious::Plugin::Authentication. Required.

METHODS NEEDS IN PLUGIN

  • init_class()

    Make initialization of class vars: $dbh, $sth, $init_conf. Return $self object.

  • apply_route($app, $r_hash)

    Heart of routes generation from db tables and not only. Insert to app->routes an hash item $r_hash. DB schema specific. Return new Mojolicious route.

  • db_routes()

    Fetch records for apply_routes. Must return arrayref of hashrefs routes.

  • load_user_roles($user)

    Fetch records roles for session user.

  • access_explicit($id1, $id2)

    Check access to route ($id1 arrayref - either route id or action id or controller id or namespace id) by roles ids ($id2 arrayref). Must return false for deny access or true - allow access.

  • access_namespace($namespace, $id2)

    Check implicit access to route by $namespace for user roles ids ($id2 arrayref). Must return false for deny access or true - allow access to all actions of this namespace.

  • access_controller($namespace, $controller, $id2)

    Check implicit access to route by $namespace and $controller for user roles ids ($id2 arrayref). Must return false for deny access or true - allow access to all actions of this controller.

  • access_action($namespace, $controller, $action, $id2)

    Check implicit access to route by $namespace and $controller and $action for user roles ids ($id2 arrayref). Must return false for deny access or true - allow access to this action.

  • access_role($role, $id2)

    Check implicit access to route by $role (id|name) and user roles ids ($id2 arrayref). Must return false for deny access or true - allow access.

SEE ALSO

Mojolicious::Plugin::RoutesAuthDBI

Mojolicious::Plugin::RoutesAuthDBI::Sth

AUTHOR

Михаил Че (Mikhail Che), <mche [on] cpan.org>

BUGS / CONTRIBUTING

Please report any bugs or feature requests at https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/issues. Pull requests welcome also.

COPYRIGHT

Copyright 2016 Mikhail Che.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.