Skip to content
Snippets Groups Projects
Commit 8ee1cff7 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

don't hardcode database parameters in code

parent 72d475db
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,15 @@ pod2usage(
-verbose => 0
) unless $action;
IdPAccountManager::DB->register_db(
driver => $Conf::global{database_type},
database => $Conf::global{database_name},
host => $Conf::global{database_host},
password => $Conf::global{database_password},
username => $Conf::global{database_user}
);
my $db = IdPAccountManager::DB->new();
if ($action eq 'add_test_account') {
......@@ -62,6 +71,7 @@ if ($action eq 'add_test_account') {
) unless $options{'sp_entityid'};
my $test_account = IdPAccountManager::Data::TestAccount->new(
db => $db,
account_profile => $options{'account_profile'},
sp_entityid => $options{'sp_entityid'}
);
......@@ -94,7 +104,7 @@ if ($action eq 'add_test_account') {
}
my $accounts =
IdPAccountManager::Data::TestAccount::Manager->get_testaccounts(%args);
IdPAccountManager::Data::TestAccount::Manager->get_testaccounts(db => $db, %args);
if (! @$accounts) {
printf "No matching test account in DB\n";
......@@ -160,7 +170,9 @@ if ($action eq 'add_test_account') {
## Check if entry already exists in DB first
my $service_provider =
IdPAccountManager::Data::ServiceProvider->new(
entityid => $options{'sp_entityid'});
db => $db,
entityid => $options{'sp_entityid'}
);
if ($service_provider->load(speculative => 1)) {
printf "Entry for %s already in DB; update it with new data\n",
$options{'sp_entityid'};
......@@ -171,6 +183,7 @@ if ($action eq 'add_test_account') {
} else {
$service_provider = IdPAccountManager::Data::ServiceProvider->new(
db => $db,
entityid => $options{'sp_entityid'},
contacts => $options{'contacts'},
displayname => $options{'displayname'}
......@@ -188,7 +201,7 @@ if ($action eq 'add_test_account') {
my %args;
my $providers = IdPAccountManager::Data::ServiceProvider::Manager->get_serviceproviders(%args);
my $providers = IdPAccountManager::Data::ServiceProvider::Manager->get_serviceproviders(db => $db, %args);
if (@$providers) {
printf "No service provider in DB\n";
......@@ -213,7 +226,7 @@ if ($action eq 'add_test_account') {
}
my $tokens =
IdPAccountManager::Data::AuthenticationToken::Manager->get_authenticationtokens(%args);
IdPAccountManager::Data::AuthenticationToken::Manager->get_authenticationtokens(db => $db, %args);
if (!@$tokens) {
printf "No corresponding token found in DB\n";
......@@ -239,7 +252,7 @@ if ($action eq 'add_test_account') {
}
my $authentication_token =
IdPAccountManager::AuthenticationToken->new(%args);
IdPAccountManager::AuthenticationToken->new(db => $db, %args);
die "No corresponding token found in DB\n"
unless $authentication_token->load();
......@@ -265,6 +278,7 @@ if ($action eq 'add_test_account') {
) unless $options{'sp_entityid'};
my $authentication_token = IdPAccountManager::Data::AuthenticationToken->new(
db => $db,
'email_address' => $options{'email_address'},
'sp_entityid' => $options{'sp_entityid'}
);
......@@ -278,6 +292,7 @@ if ($action eq 'add_test_account') {
unless $authentication_token->delete();
$authentication_token = IdPAccountManager::Data::AuthenticationToken->new(
db => $db,
'email_address' => $options{'email_address'},
'sp_entityid' => $options{'sp_entityid'}
);
......
......@@ -44,10 +44,10 @@ our %global = (
'database_name' => 'idp_account_manager',
## Database username
'database_user' => 'idpadmin',
'database_user' => 'root',
## Database user password
'database_password' => 'secret',
'database_password' => 'root',
## Log file for the manager
'log_file' => '/opt/testidp/IdPAccountManager/log/manager.log',
......
......@@ -7,13 +7,26 @@ 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 => 'root',
username => 'root',
__PACKAGE__->SUPER::register_db (
connect_options => { AutoCommit => 1, ChopBlanks => 1 },
driver => 'mysql',
host => 'localhost',
database => 'fake',
password => 'fake',
username => 'fake',
);
sub register_db {
my ($pkg, %args) = @_;
__PACKAGE__->SUPER::register_db (
connect_options => { AutoCommit => 1, ChopBlanks => 1 },
driver => $args{driver},
host => $args{host},
database => $args{database},
password => $args{password},
username => $args{username}
);
}
1;
......@@ -28,6 +28,16 @@ sub new {
message => ''
);
IdPAccountManager::DB->register_db(
driver => $Conf::global{database_type},
database => $Conf::global{database_name},
host => $Conf::global{database_host},
password => $Conf::global{database_password},
username => $Conf::global{database_user}
);
$self->{db} = IdPAccountManager::DB->new();
my $http_query = CGI->new();
## Input parameters
......@@ -298,6 +308,7 @@ sub req_select_sp {
## Create a serviceprovider object to store major parameters for this SP in DB
my $service_provider = IdPAccountManager::Data::ServiceProvider->new(
db => $self->{db},
entityid => $self->{'param_in'}{'sp_entityid'},
dev_sp_contact => $Conf::global{'dev_sp_contact'}
);
......@@ -338,6 +349,7 @@ sub req_select_sp {
} else {
$service_provider = IdPAccountManager::Data::ServiceProvider->new(
db => $self->{db},
entityid => $self->{'param_in'}{'sp_entityid'},
contacts => join(',', @contacts),
displayname => $display_name,
......@@ -393,6 +405,7 @@ sub req_generate_token {
## Create a serviceprovider object to load parameters for this SP from DB
my $service_provider = IdPAccountManager::Data::ServiceProvider->new(
db => $self->{db},
entityid => $self->{'param_in'}{'sp_entityid'},
dev_sp_contact => $Conf::global{'dev_sp_contact'}
);
......@@ -423,6 +436,7 @@ sub req_generate_token {
}
my $authentication_token = IdPAccountManager::Data::AuthenticationToken->new(
db => $self->{db},
'email_address' => $self->{'param_in'}{'email_address'},
'sp_entityid' => $self->{'param_in'}{'sp_entityid'}
);
......@@ -450,6 +464,7 @@ sub req_generate_token {
}
$authentication_token = IdPAccountManager::Data::AuthenticationToken->new(
db => $self->{db},
'email_address' => $self->{'param_in'}{'email_address'},
'sp_entityid' => $self->{'param_in'}{'sp_entityid'}
);
......@@ -523,6 +538,7 @@ sub req_validate_token {
}
my $authentication_token = IdPAccountManager::Data::AuthenticationToken->new(
db => $self->{db},
token => $self->{'param_in'}{'authentication_token'});
unless ($authentication_token->load()) {
......@@ -565,6 +581,7 @@ sub req_validate_token {
foreach my $profile ($Conf::global{'account_profiles'}) {
my $test_account = IdPAccountManager::Data::TestAccount->new(
db => $self->{db},
account_profile => $profile,
sp_entityid => $self->{'param_in'}{'sp_entityid'}
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment