diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl new file mode 100755 index 0000000000000000000000000000000000000000..2e564b6e188f6f8493f26738c54b0aafa4be40b6 --- /dev/null +++ b/bin/account-manager-client.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +## 18/07/2014, Olivier Salaün +## Command-line client for the Test IdP Account Manager + +use strict; +use utf8; +use lib "/opt/testidp/IdPAccountManager/lib"; + +use Getopt::Long; + +use IdPAccountManager::TestAccount; + +my %options; +unless (&GetOptions(\%options, 'help', 'create_test_account', 'account_profile=s', 'sp_entityid=s')) { + die "Unknown options."; +} + +if ($options{'help'}) { + printf "$0 --create_test_account --account_profile=<profile_id> --sp_entityid=<entityid>\n"; +} + +if ($options{'create_test_account'}) { + + unless ($options{'account_profile'}) { + die "Missing account_profile option"; + } + + unless ($options{'sp_entityid'}) { + die "Missing sp_entityid option"; + } + + my $test_account = new IdPAccountManager::TestAccount(account_profile => $options{'account_profile'}, + sp_entityid => $options{'sp_entityid'}); + unless (defined $test_account) { + die "Failed to create test account"; + } +} diff --git a/bin/create-database.pl b/bin/create-database.pl new file mode 100755 index 0000000000000000000000000000000000000000..d4684b1e5a8566342f02a7750bafc8dce51409f7 --- /dev/null +++ b/bin/create-database.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl +## Initialize Rose::DB code given the DB structure + +use Rose::DB; +use Rose::DB::Object::Loader; +use Getopt::Long; + +my %options; +unless (&GetOptions(\%options, 'database=s')) { + die "Unknown options."; +} + +my $dbname = $options{'database'} || 'idp_account_manager'; + +$loader = + Rose::DB::Object::Loader->new( + db_dsn => "dbi:mysql:dbname=$dbname;host=localhost", + db_username => 'idpadmin', + db_password => 'PQur;m9#I[', + db_options => { AutoCommit => 1, ChopBlanks => 1 }, + class_prefix => 'IdPAccountManager::Data', + #with_unique_keys => 0, + ); + +$loader->make_modules(with_managers => 1, + module_dir => '/tmp', + #with_relationships => ['one to many','many to one'] + ); diff --git a/conf/create-manager-db.sql b/conf/create-manager-db.sql new file mode 100644 index 0000000000000000000000000000000000000000..1e51272bd4e3c6b42cae600f5028d5beceade95b --- /dev/null +++ b/conf/create-manager-db.sql @@ -0,0 +1,12 @@ +## Test IdP Account Manager DB creation script + +CREATE TABLE `testaccounts` ( + `id` bigint(20) NOT NULL auto_increment, + `user_id` varchar(50) NOT NULL, + `user_password` varchar(50) NOT NULL, + `creation_date` int default NULL, + `expiration_date` int default NULL, + PRIMARY KEY (`id`), + UNIQUE (user_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; + diff --git a/lib/IdPAccountManager/Data/DB/AutoBase1.pm b/lib/IdPAccountManager/Data/DB/AutoBase1.pm new file mode 100644 index 0000000000000000000000000000000000000000..cef561fa9498d4521c4d500ede944f1a03b0f161 --- /dev/null +++ b/lib/IdPAccountManager/Data/DB/AutoBase1.pm @@ -0,0 +1,18 @@ +package IdPAccountManager::Data::DB::AutoBase1; + +use strict; + +use base 'Rose::DB'; + +__PACKAGE__->use_private_registry; + +__PACKAGE__->register_db +( + connect_options => { AutoCommit => 1, ChopBlanks => 1 }, + driver => 'mysql', + dsn => 'dbi:mysql:dbname=idp_account_manager;host=localhost', + password => 'PQur;m9#I[', + username => 'idpadmin', +); + +1; diff --git a/lib/IdPAccountManager/Data/DB/Object/AutoBase2.pm b/lib/IdPAccountManager/Data/DB/Object/AutoBase2.pm new file mode 100644 index 0000000000000000000000000000000000000000..a7d9068caad21881926853fc02db78397633d41e --- /dev/null +++ b/lib/IdPAccountManager/Data/DB/Object/AutoBase2.pm @@ -0,0 +1,9 @@ +package IdPAccountManager::Data::DB::Object::AutoBase2; + +use base 'Rose::DB::Object'; + +use IdPAccountManager::Data::DB::AutoBase1; + +sub init_db { IdPAccountManager::Data::DB::AutoBase1->new } + +1; diff --git a/lib/IdPAccountManager/Data/Testaccount.pm b/lib/IdPAccountManager/Data/Testaccount.pm new file mode 100644 index 0000000000000000000000000000000000000000..c651422eb2efbe41d967f7f71135a606a436bc88 --- /dev/null +++ b/lib/IdPAccountManager/Data/Testaccount.pm @@ -0,0 +1,24 @@ +package IdPAccountManager::Data::Testaccount; + +use strict; + +use base qw(IdPAccountManager::Data::DB::Object::AutoBase2); + +__PACKAGE__->meta->setup( + table => 'testaccounts', + + columns => [ + id => { type => 'bigserial', not_null => 1 }, + user_id => { type => 'varchar', length => 50, not_null => 1 }, + user_password => { type => 'varchar', length => 50, not_null => 1 }, + creation_date => { type => 'integer' }, + expiration_date => { type => 'integer' }, + ], + + primary_key_columns => [ 'id' ], + + unique_key => [ 'user_id' ], +); + +1; + diff --git a/lib/IdPAccountManager/Data/Testaccount/Manager.pm b/lib/IdPAccountManager/Data/Testaccount/Manager.pm new file mode 100644 index 0000000000000000000000000000000000000000..a2d6b36a6aeb052bf497c0f7788a41cf09d0b77d --- /dev/null +++ b/lib/IdPAccountManager/Data/Testaccount/Manager.pm @@ -0,0 +1,14 @@ +package IdPAccountManager::Data::Testaccount::Manager; + +use strict; + +use base qw(Rose::DB::Object::Manager); + +use IdPAccountManager::Data::Testaccount; + +sub object_class { 'IdPAccountManager::Data::Testaccount' } + +__PACKAGE__->make_manager_methods('testaccounts'); + +1; + diff --git a/lib/IdPAccountManager/TestAccount.pm b/lib/IdPAccountManager/TestAccount.pm new file mode 100644 index 0000000000000000000000000000000000000000..de034a59597730cafbcb203b666fdf57dee72c78 --- /dev/null +++ b/lib/IdPAccountManager/TestAccount.pm @@ -0,0 +1,36 @@ +package IdPAccountManager::TestAccount; + +use Moose; +use Moose::Util::TypeConstraints; + +subtype 'entityid', + as 'Str', + where { /^(urn:|http(s)?\:\/\/)/ }, + message { "$_ is not a valide entityid"}; + +has 'account_profile' => (is => 'ro', + isa => 'Str', + required => 1); +has 'sp_entityid' => (is => 'rw', + isa => 'entityid', + required => 1, + ); + +#before 'new' => sub { print "about to call new\n"; }; + +1; # Magic true value required at end of module +__END__ + +=head1 NAME + +IdPAccountManager::TestAccount - Manage test user accounts for the Test Identity Provider + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 SUBROUTINES/METHODS + +=head1 AUTHOR + +Olivier Salaün (olivier.salaun@renater.fr) diff --git a/lib/IdPAccountManager/TestAccount.pm.ORIG b/lib/IdPAccountManager/TestAccount.pm.ORIG new file mode 100644 index 0000000000000000000000000000000000000000..de034a59597730cafbcb203b666fdf57dee72c78 --- /dev/null +++ b/lib/IdPAccountManager/TestAccount.pm.ORIG @@ -0,0 +1,36 @@ +package IdPAccountManager::TestAccount; + +use Moose; +use Moose::Util::TypeConstraints; + +subtype 'entityid', + as 'Str', + where { /^(urn:|http(s)?\:\/\/)/ }, + message { "$_ is not a valide entityid"}; + +has 'account_profile' => (is => 'ro', + isa => 'Str', + required => 1); +has 'sp_entityid' => (is => 'rw', + isa => 'entityid', + required => 1, + ); + +#before 'new' => sub { print "about to call new\n"; }; + +1; # Magic true value required at end of module +__END__ + +=head1 NAME + +IdPAccountManager::TestAccount - Manage test user accounts for the Test Identity Provider + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 SUBROUTINES/METHODS + +=head1 AUTHOR + +Olivier Salaün (olivier.salaun@renater.fr)