@@ -49,10 +49,16 @@ function clearDatasourceEnv() {
49
49
unset ${prefix} _BACKGROUND_VALIDATION
50
50
unset ${prefix} _BACKGROUND_VALIDATION_MILLIS
51
51
52
- for xa_prop in $( compgen -v | grep -s " ${prefix} _XA_CONNECTION_PROPERTY_" ) ; do
53
- unset ${xa_prop}
52
+ # ## Start of RH-SSO add-on -- KEYCLOAK-15633:
53
+ # ## -----------------------------------------
54
+ # ## Remove / undefine also "${prefix}_CONNECTION_PROPERTY_*" env vars when
55
+ # ## removing / undefining "${prefix}_XA_CONNECTION_PROPERTY_*" env vars
56
+ for property in $( compgen -v | grep -oPs " ${prefix} (|_XA)_CONNECTION_PROPERTY_" ) ; do
57
+ unset " ${property} "
54
58
done
55
59
}
60
+ # ## End of RH-SSO add-on
61
+ # ## --------------------
56
62
57
63
function clearDatasourcesEnv() {
58
64
IFS=' ,' read -a db_backends <<< $DB_SERVICE_PREFIX_MAPPING
@@ -372,42 +378,99 @@ function generate_external_datasource() {
372
378
fi
373
379
}
374
380
381
+ # ## Start of RH-SSO add-on -- KEYCLOAK-15633:
382
+ # ## -----------------------------------------
383
+ # ## Allow specification of datasource connection properties for:
384
+ # ## 1) XA datasources via the DB_XA_CONNECTION_PROPERTY_<property_name> and
385
+ # ## 2) Non-XA datasources via the DB_CONNECTION_PROPERTY_<property_name>
386
+ # ##
387
+ # ## environment variable(s) defined on the container image. The <property_name>
388
+ # ## in the above expressions is the actual name of the connection property to
389
+ # ## be set on the underlying datasource.
390
+ # ##
391
+ function inject_connection_properties_to_datasource_xml() {
392
+ local ds=" ${1} "
393
+
394
+ local failed=" false"
395
+ local is_xa_ds=" false"
396
+
397
+ if [[ " ${ds} " =~ \< datasource[[:space:]].* $ ]]; then
398
+ local conn_prop_env_var=" ${prefix} _CONNECTION_PROPERTY_"
399
+ local conn_prop_xml_elem_name=" connection-property"
400
+ elif [[ " ${ds} " =~ \< xa-datasource[[:space:]].* $ ]]; then
401
+ local conn_prop_env_var=" ${prefix} _XA_CONNECTION_PROPERTY_"
402
+ local conn_prop_xml_elem_name=" xa-datasource-property"
403
+ is_xa_ds=" true"
404
+ else
405
+ log_warning " Unable to determine if '${ds} ' datasource is a non-XA or XA one."
406
+ log_warning " Datasource '$( basename ${jndi_name} ) ' will not be configured."
407
+ failed=" true"
408
+ fi
409
+
410
+ declare -ra conn_props=($( compgen -v | grep -s " ${conn_prop_env_var} " ) )
411
+ if [ " ${is_xa_ds} " == " true" ] && [ -z " ${conn_props} " ]; then
412
+ log_warning " At least one ${prefix} _XA_CONNECTION_PROPERTY_property for datasource ${service_name} is required."
413
+ log_warning " Datasource '$( basename ${jndi_name} ) ' will not be configured."
414
+ failed=" true"
415
+ fi
416
+
417
+ if [ " ${failed} " != " true" ]; then
418
+ for property in " ${conn_props[@]} " ; do
419
+ prop_name=$( sed -e " s/${conn_prop_env_var} //g" <<< " ${property}" )
420
+ prop_value=$( find_env " ${property} " )
421
+ if [ ! -z " ${prop_value} " ]; then
422
+ ds=" ${ds}
423
+ <${conn_prop_xml_elem_name} name=\" ${prop_name} \" >${prop_value} </${conn_prop_xml_elem_name} >"
424
+ fi
425
+ done
426
+ fi
427
+
428
+ # 'ds' value of empty string indicates an error occurred earlier
429
+ if [ " ${failed} " == " true" ]; then
430
+ echo " "
431
+ else
432
+ echo " ${ds} "
433
+ fi
434
+ }
435
+ # ## End of RH-SSO add-on
436
+ # ## --------------------
437
+
375
438
function generate_external_datasource_xml() {
439
+
440
+ # ## Start of RH-SSO add-on -- KEYCLOAK-15633:
441
+ # ## -----------------------------------------
442
+ # ## Modify the 'generate_external_datasource_xml()' method to
443
+ # ## allow specification of connection properties also for non-XA datasources
444
+
376
445
local failed=" false"
446
+ local ds_universal_attrs=" jndi-name=\" ${jndi_name} \" pool-name=\" ${pool_name} \" enabled=\" true\" use-java-context=\" true\" statistics-enabled=\"\$ {wildfly.datasources.statistics-enabled:\$ {wildfly.statistics-enabled:false}}\" "
377
447
378
448
if [ -n " $NON_XA_DATASOURCE " ] && [ " $NON_XA_DATASOURCE " = " true" ]; then
379
- ds=" <datasource jta=\" ${jta} \" jndi-name=\" ${jndi_name} \" pool-name=\" ${pool_name} \" enabled=\" true\" use-java-context=\" true\" statistics-enabled=\"\$ {wildfly.datasources.statistics-enabled:\$ {wildfly.statistics-enabled:false}}\" >
380
- <connection-url>${url} </connection-url>
381
- <driver>$driver </driver>"
449
+ ds=" <datasource jta=\" ${jta} \" ${ds_universal_attrs} >
450
+ <connection-url>${url} </connection-url>"
382
451
else
383
- ds=" <xa-datasource jndi-name=\" ${jndi_name} \" pool-name=\" ${pool_name} \" enabled=\" true\" use-java-context=\" true\" statistics-enabled=\"\$ {wildfly.datasources.statistics-enabled:\$ {wildfly.statistics-enabled:false}}\" >"
384
- local xa_props=$( compgen -v | grep -s " ${prefix} _XA_CONNECTION_PROPERTY_" )
385
- if [ -z " $xa_props " ]; then
386
- log_warning " At least one ${prefix} _XA_CONNECTION_PROPERTY_property for datasource ${service_name} is required. Datasource will not be configured."
387
- failed=" true"
388
- else
389
-
390
- for xa_prop in $( echo $xa_props ) ; do
391
- prop_name=$( echo " ${xa_prop} " | sed -e " s/${prefix} _XA_CONNECTION_PROPERTY_//g" )
392
- prop_val=$( find_env $xa_prop )
393
- if [ ! -z ${prop_val} ]; then
394
- ds=" $ds <xa-datasource-property name=\" ${prop_name} \" >${prop_val} </xa-datasource-property>"
395
- fi
396
- done
452
+ ds=" <xa-datasource ${ds_universal_attrs} >"
453
+ fi
397
454
398
- ds=" $ds
399
- <driver>${driver} </driver>"
400
- fi
455
+ ds=$( inject_connection_properties_to_datasource_xml " ${ds} " )
456
+ # 'ds' value of empty string indicates an error occurred earlier
457
+ if [ " ${ds} " == " " ]; then
458
+ failed=" true"
401
459
fi
402
460
461
+ ds=" $ds
462
+ <driver>${driver} </driver>"
463
+ # ## End of RH-SSO add-on
464
+ # ## --------------------
465
+
403
466
if [ -n " $tx_isolation " ]; then
404
467
ds=" $ds
405
- <transaction-isolation>$tx_isolation </transaction-isolation>"
468
+ <transaction-isolation>$tx_isolation </transaction-isolation>"
406
469
fi
407
470
408
471
if [ -n " $min_pool_size " ] || [ -n " $max_pool_size " ]; then
409
472
if [ -n " $NON_XA_DATASOURCE " ] && [ " $NON_XA_DATASOURCE " = " true" ]; then
410
- ds=" $ds
473
+ ds=" $ds
411
474
<pool>"
412
475
else
413
476
ds=" $ds
@@ -473,9 +536,19 @@ function generate_external_datasource_xml() {
473
536
fi
474
537
}
475
538
539
+ # ## Start of RH-SSO add-on -- KEYCLOAK-15633:
540
+ # ## -----------------------------------------
541
+ # ## Allow specification of datasource connection properties for:
542
+ # ## 1) XA datasources via the DB_XA_CONNECTION_PROPERTY_<property_name> and
543
+ # ## 2) Non-XA datasources via the DB_CONNECTION_PROPERTY_<property_name>
544
+ # ##
545
+ # ## environment variable(s) defined on the container image. The <property_name>
546
+ # ## in the above expressions is the actual name of the connection property to
547
+ # ## be set on the underlying datasource.
548
+ # ##
476
549
function generate_external_datasource_cli() {
477
550
local failed=" false"
478
-
551
+ local is_xa_ds= " false "
479
552
local subsystem_addr=" /subsystem=datasources"
480
553
local ds_resource=" ${subsystem_addr} "
481
554
local other_ds_resource
@@ -487,32 +560,41 @@ function generate_external_datasource_cli() {
487
560
ds_tmp_key_values[" statistics-enabled" ]=" \$ {wildfly.datasources.statistics-enabled:\$ {wildfly.statistics-enabled:false}}"
488
561
ds_tmp_key_values[" driver-name" ]=" ${driver} "
489
562
490
- local -A ds_tmp_xa_connection_properties
563
+ local -A ds_tmp_connection_properties
491
564
492
565
if [ -n " $NON_XA_DATASOURCE " ] && [ " $NON_XA_DATASOURCE " = " true" ]; then
493
566
ds_resource=" ${subsystem_addr} /data-source=${pool_name} "
494
567
other_ds_resource=" ${subsystem_addr} /xa-data-source=${pool_name} "
495
568
569
+ local conn_prop_env_var=" ${prefix} _CONNECTION_PROPERTY_"
570
+ local conn_prop_cli_elem_name=" connection-properties"
571
+
496
572
ds_tmp_key_values[" jta" ]=" ${jta} "
497
573
ds_tmp_key_values[' connection-url' ]=" ${url} "
498
574
499
575
else
500
576
ds_resource=" ${subsystem_addr} /xa-data-source=${pool_name} "
501
577
other_ds_resource=" ${subsystem_addr} /data-source=${pool_name} "
502
578
503
- local xa_props=$( compgen -v | grep -s " ${prefix} _XA_CONNECTION_PROPERTY_" )
504
- if [ -z " $xa_props " ] && [ " $driver " != " postgresql" ] && [ " $driver " != " mysql" ]; then
505
- log_warning " At least one ${prefix} _XA_CONNECTION_PROPERTY_property for datasource ${service_name} is required. Datasource will not be configured."
579
+ local conn_prop_env_var=" ${prefix} _XA_CONNECTION_PROPERTY_"
580
+ local conn_prop_cli_elem_name=" xa-datasource-properties"
581
+ is_xa_ds=" true"
582
+
583
+ declare -ra conn_props=($( compgen -v | grep -s " ${conn_prop_env_var} " ) )
584
+ if [ " ${is_xa_ds} " == " true" ] && [ -z " ${conn_props} " ]; then
585
+ log_warning " At least one ${prefix} _XA_CONNECTION_PROPERTY_property for datasource ${service_name} is required."
586
+ log_warning " Datasource '$( basename ${jndi_name} ) ' will not be configured."
506
587
failed=" true"
507
588
else
508
-
509
- for xa_prop in $( echo $xa_props ) ; do
510
- prop_name=$( echo " ${xa_prop} " | sed -e " s/${prefix} _XA_CONNECTION_PROPERTY_//g" )
511
- prop_val=$( find_env $xa_prop )
512
- if [ ! -z ${prop_val} ]; then
513
- ds_tmp_xa_connection_properties[" $prop_name " ]=" $prop_val "
514
- fi
515
- done
589
+ if [ " ${failed} " != " true" ]; then
590
+ for property in " ${conn_props[@]} " ; do
591
+ prop_name=$( sed -e " s/${conn_prop_env_var} //g" <<< " ${property}" )
592
+ prop_value=$( find_env " ${property} " )
593
+ if [ ! -z " ${prop_value} " ]; then
594
+ ds_tmp_connection_properties[" ${prop_name} " ]=" ${prop_value} "
595
+ fi
596
+ done
597
+ fi
516
598
fi
517
599
fi
518
600
@@ -559,11 +641,11 @@ function generate_external_datasource_cli() {
559
641
done
560
642
ds_tmp_add=" ${ds_tmp_add} )"
561
643
562
- # Add the xa-ds properties
563
- local ds_tmp_xa_properties
564
- for key in " ${! ds_tmp_xa_connection_properties [@]} " ; do
565
- ds_tmp_xa_properties =" ${ds_tmp_xa_properties }
566
- $ds_resource /xa-datasource-properties =${key} :add(value=\" ${ds_tmp_xa_connection_properties [$key]} \" )
644
+ # Add the connection properties to both XA & non-XA datasource
645
+ local ds_tmp_conn_props_add
646
+ for key in " ${! ds_tmp_connection_properties [@]} " ; do
647
+ ds_tmp_conn_props_add =" ${ds_tmp_conn_props_add }
648
+ $ds_resource /${conn_prop_cli_elem_name} =${key} :add(value=\" ${ds_tmp_connection_properties [$key]} \" )
567
649
"
568
650
done
569
651
@@ -589,9 +671,12 @@ function generate_external_datasource_cli() {
589
671
590
672
batch
591
673
${ds_tmp_add}
592
- ${ds_tmp_xa_properties }
674
+ ${ds_tmp_conn_props_add }
593
675
run-batch
594
676
"
677
+ # ## End of RH-SSO add-on
678
+ # ## --------------------
679
+
595
680
if [ " $failed " == " true" ]; then
596
681
echo " "
597
682
else
@@ -810,10 +895,12 @@ function map_properties() {
810
895
if [ -z " $( eval echo \$ ${prefix} _XA_CONNECTION_PROPERTY_URL) " ]; then
811
896
if [ -z " ${! serverNameVar} " ] || [ -z " ${! portVar} " ] || [ -z " ${! databaseNameVar} " ]; then
812
897
if [ " $prefix " != " $service " ]; then
813
- log_warning " Missing configuration for datasource $prefix . ${service} _SERVICE_HOST, ${service} _SERVICE_PORT, and/or ${prefix} _DATABASE is missing. Datasource will not be configured."
898
+ log_warning " Missing configuration for datasource $prefix . ${service} _SERVICE_HOST, ${service} _SERVICE_PORT, and/or ${prefix} _DATABASE is missing."
899
+ log_warning " Datasource '$( basename ${jndi_name} ) ' will not be configured."
814
900
eval ${invalidVar} =" true"
815
901
else
816
- log_warning " Missing configuration for XA datasource $prefix . Either ${prefix} _XA_CONNECTION_PROPERTY_URL or $serverNameVar , and $portVar , and $databaseNameVar is required. Datasource will not be configured."
902
+ log_warning " Missing configuration for XA datasource $prefix . Either ${prefix} _XA_CONNECTION_PROPERTY_URL or $serverNameVar , and $portVar , and $databaseNameVar is required."
903
+ log_warning " Datasource '$( basename ${jndi_name} ) ' will not be configured."
817
904
eval ${invalidVar} =" true"
818
905
fi
819
906
else
@@ -823,7 +910,8 @@ function map_properties() {
823
910
fi
824
911
fi
825
912
else
826
- log_warning " Missing configuration for datasource $prefix . ${service} _SERVICE_HOST, ${service} _SERVICE_PORT, and/or ${prefix} _DATABASE is missing. Datasource will not be configured."
913
+ log_warning " Missing configuration for datasource $prefix . ${service} _SERVICE_HOST, ${service} _SERVICE_PORT, and/or ${prefix} _DATABASE is missing."
914
+ log_warning " Datasource '$( basename ${jndi_name} ) ' will not be configured."
827
915
eval ${invalidVar} =" true"
828
916
fi
829
917
@@ -950,7 +1038,8 @@ function inject_datasource() {
950
1038
fi
951
1039
952
1040
if [ -z " $driver " ]; then
953
- log_warning " DRIVER not set for datasource ${service_name} . Datasource will not be configured."
1041
+ log_warning " DRIVER not set for datasource ${service_name} ."
1042
+ log_warning " Datasource '$( basename ${jndi_name} ) ' will not be configured."
954
1043
else
955
1044
datasource=$( generate_datasource " ${service,,} -${prefix} " " $jndi " " $username " " $password " " $host " " $port " " $database " " $checker " " $sorter " " $driver " " $service_name " " $jta " " $validate " " $url " )
956
1045
@@ -1054,4 +1143,4 @@ function inject_job_repository() {
1054
1143
echo " ${cli} " >> " ${DEFAULT_JOB_REPOSITORY_FILE} "
1055
1144
fi
1056
1145
1057
- }
1146
+ }
0 commit comments