From f61cdb1eb76c969f65ca46b0c41e7fc2df8612e1 Mon Sep 17 00:00:00 2001
From: "renater.salaun" <renater.salaun@047e039d-479c-447e-8a29-aa6bf4a09bab>
Date: Thu, 30 Oct 2014 15:48:14 +0000
Subject: [PATCH] Added code to remove expired tokens

git-svn-id: https://svn.geant.net/GEANT/edugain_testidp_account_manager/trunk@60 047e039d-479c-447e-8a29-aa6bf4a09bab
---
 bin/account-manager-client.pl | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl
index 9590cd5..cca7229 100755
--- a/bin/account-manager-client.pl
+++ b/bin/account-manager-client.pl
@@ -130,6 +130,9 @@ if ($options{'add_test_account'}) {
     if ($options{'token'}) {
         push @{$args{'query'}}, 'token' => $options{'token'};
     }
+    if ($options{'filter_expired'}) {
+        push @{$args{'query'}}, 'creation_date' => {lt => time-($Conf::global{'tokens_validity_period'} * 3600)};
+    }
     
     my $all = IdPAccountManager::AuthenticationToken::list_authentication_tokens(%args);
     
@@ -139,8 +142,14 @@ if ($options{'add_test_account'}) {
     
     foreach my $authentication_token (@$all) {
         $authentication_token->print();
+        $authentication_token->delete || die if ($options{'delete'});        
     }
     
+    if ($options{'delete'}) {
+        printf "%d tokens removed\n", $#{$all}+1;
+
+    }    
+    
 }elsif ($options{'get_authentication_token'}) {
     
     my %args;    
@@ -252,6 +261,14 @@ Parses the SAML metadata file, as defined by the C<federation_metadata_file_path
 
 List all authentication tokens. Criterias can be added to filter tokens.
 
+=item C<account-manager-client.pl --list_authentication_tokens --filter_expired>
+
+List all expired authentication tokens.
+
+=item C<account-manager-client.pl --list_authentication_tokens --filter_expired --delete>
+
+Remove all expired authentication tokens from DB.
+
 =item C<account-manager-client.pl --get_authentication_token --token=dhj67sjJ>
 
 Get informations on a token.
-- 
GitLab