The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Jifty::CurrentUser

DESCRIPTION

Most applications need to have a concept of who the current user is. So Jifty supports this concept internally. Every Jifty::Object (which most things in Jifty are descended from) except the CurrentUser itself is instantiated with a Jifty::CurrentUser subclass as a parameter to the creator.

This class describes (and implements a trivial version) of the access control API that a Jifty application needs to implemenet to provide user-based access control

It's generally expected that your application will override this class if you want any sort of access control.

new

Creates a new Jifty::CurrentUser object. Calls _init, an app-specific initialization routine.

superuser

A convenience constructor that returns a new CurrentUser object that's marked as a superuser.

user_object

This gets or sets your application's user object for the current user. Generally, you're epxected to set and load it in the _init method in your Jifty::CurrentUser subclass.

Example:

        sub _init {
            my $self = shift;
            my %args = (@_);
        
            if (delete $args{'_bootstrap'} ) {
                $self->is_bootstrap_user(1);
            } elsif (keys %args) {
                $self->user_object(Wifty::Model::User->new(current_user => $self));
                $self->user_object->load_by_cols(%args);
            }
            $self->SUPER::_init(%args);
        }
        

id

Returns 0 if we don't have a user_object. When we do have a user_object, return that user's id.

current_user

Every class in a Jifty application has a "current_user" method that returns the user who's doing things, in the form of a Jifty::CurrentUser object a subclass thereof. For the somewhat obvious reason that you can't actually lift yourself up by tugging on your own bootstraps, a Jifty::CurrentUser object return itself rather than another Jifty::CurrentUser object

AUTHENTICATION AND AUTHORIZATION

To use Jifty's built-in authentication and authorization system, your user objects need to implement the following API methods:

password_is STRING

Your user_object should have a method called password_is which returns true if passed a string that matches the user's current password.

username

Return a string which identifies the user in some way.

auth_token

Return a string which proves that the user is who they claim to be. A simple way to do this, for example, would be to hash the username and some server-side secret.

RIGHTS AND ACCESS CONTROL

In any system that relies on users' rights to perform actions, it's sometimes necessary to walk around the access control system. There are two primary cases for this:

is_superuser

Sometimes, while the system is running, you need to do something on behalf of a user that they shouldn't be able to do themselves. Maybe you need to let a new user sign up for your service (You don't want to let any user create more users, right?) or to write an entry to a changelog. If the user has the is_superuser flag set, things still get read from the database, but the user can walk around any and all ACL checks. Think "Neo" from the Matrix. The superuser can walk through walls, stop bullets and so on.

is_bootstrap_user

When your system is first getting going, you can't assume anything. There probably aren't any rights in the system to check. A user with the "is_bootstrap_user" flag set is a self-reliant superuser. Nothing is read from the database, no ACLs are checked. You probably never need to do anything with bootstrap users.

current_user_can ACTION

For a current user object, the current user can always read, but never write or do anything else.