Skip to content
Snippets Groups Projects
Commit b4a377c9 authored by renater.salaun's avatar renater.salaun
Browse files

Initial version of the code

git-svn-id: https://svn.geant.net/GEANT/edugain_testidp_account_manager/trunk@2 047e039d-479c-447e-8a29-aa6bf4a09bab
parent 39a24a47
No related branches found
No related tags found
No related merge requests found
#!/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";
}
}
#!/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']
);
## 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 ;
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;
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;
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;
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;
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)
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment