Skip to content
Snippets Groups Projects
AuthenticationToken.pm 5.85 KiB
package IdPAccountManager::AuthenticationToken;

## Copyright (c) GEANT
## This software was developed by RENATER. The research leading to these results has received funding
## from the European Community¹s Seventh Framework Programme (FP7/2007-2013) under grant agreement nº 238875 (GÉANT).

use strict;

use IdPAccountManager::Data::Authenticationtoken;
use IdPAccountManager::Data::Authenticationtoken::Manager;

use IdPAccountManager::Tools;
use Conf;

use Digest::MD5;
use POSIX qw(strftime);

use Carp;

INIT {
    ## Set error mode  to non fatal
    IdPAccountManager::Data::Authenticationtoken::Manager->error_mode('return');
}

sub new {
    my ($pkg) = shift;
    my %args = @_;

    my $self = {};

    ## Bless AuthenticationToken object
    bless $self, $pkg;

    ## Object may be created either with a hashref as argument or an IdPAccountManager::Data::Authenticationtoken object
    ## Second case is usefull when fetching a set of IdPAccountManager::Data::Authenticationtoken via IdPAccountManager::Data::Authenticationtoken::Manager
    if (ref($_[0]) eq 'IdPAccountManager::Data::Authenticationtoken') {
        $self->{'persistent'} = $_[0];
    } else {
        $self->{'persistent'} =
          IdPAccountManager::Data::Authenticationtoken->new(%args);
    }

    return $self;
}

## Load an authentication token from DB
sub load {
    my $self = shift;

    return $self->{'persistent'}->load(speculative => 1);
}

## Get object parameter
sub get {
    my $self           = shift;
    my $attribute_name = shift;

    return $self->{'persistent'}->$attribute_name;
}

## Set object parameters
sub set {
    my $self       = shift;
    my %parameters = @_;

    foreach my $parameter_name (keys %parameters) {
        $self->{'persistent'}->$parameter_name($parameters{$parameter_name});
    }

    return 1;