1818
1919import java .io .IOException ;
2020import java .net .URI ;
21+ import java .util .ArrayList ;
22+ import java .util .Objects ;
23+ import java .util .Optional ;
24+ import java .util .Properties ;
2125
26+ import org .apache .activemq .artemis .api .config .ActiveMQDefaultConfiguration ;
2227import org .apache .activemq .artemis .cli .ConfigurationException ;
2328import org .apache .activemq .artemis .core .server .ActivateCallback ;
2429import org .apache .activemq .artemis .dto .BrokerDTO ;
30+ import org .apache .activemq .artemis .dto .JaasSecurityDTO ;
31+ import org .apache .activemq .artemis .dto .PropertyDTO ;
32+ import org .apache .activemq .artemis .dto .SecurityManagerDTO ;
2533import org .apache .activemq .artemis .dto .ServerDTO ;
2634import org .apache .activemq .artemis .integration .Broker ;
2735import org .apache .activemq .artemis .spi .core .security .ActiveMQSecurityManager ;
@@ -44,7 +52,42 @@ private static BrokerDTO createBrokerConfiguration(URI configURI,
4452 } catch (IOException ioe ) {
4553 throw new ConfigurationException ("Invalid configuration URI, can't find configuration scheme: " + configURI .getScheme ());
4654 }
47- return factory .createBroker (configURI , artemisHome , artemisInstance , artemisURIInstance );
55+ BrokerDTO broker = factory .createBroker (configURI , artemisHome , artemisInstance , artemisURIInstance );
56+
57+ populateSecurityWithSystemProperties (broker );
58+
59+ return broker ;
60+ }
61+
62+ private static void populateSecurityWithSystemProperties (BrokerDTO broker ) {
63+ Properties systemProperties = System .getProperties ();
64+ String systemSecurityJaasPropertyPrefix = ActiveMQDefaultConfiguration .getDefaultSystemSecurityJaasPropertyPrefix ();
65+ String systemSecurityManagerPropertyPrefix = ActiveMQDefaultConfiguration .getDefaultSystemSecurityManagerPropertyPrefix ();
66+
67+ if (systemProperties .containsKey (systemSecurityJaasPropertyPrefix + "domain" )) {
68+ broker .security = broker .security instanceof JaasSecurityDTO ?
69+ (JaasSecurityDTO ) broker .security : new JaasSecurityDTO ();
70+ } else if (systemProperties .containsKey (systemSecurityManagerPropertyPrefix + "className" )) {
71+ broker .security = broker .security instanceof SecurityManagerDTO ?
72+ (SecurityManagerDTO ) broker .security : new SecurityManagerDTO ();
73+ }
74+
75+ if (broker .security instanceof JaasSecurityDTO security ) {
76+ security .domain = Optional .ofNullable ((String )systemProperties .get (
77+ systemSecurityJaasPropertyPrefix + "domain" )).orElse (security .domain );
78+ security .certificateDomain = Optional .ofNullable ((String )systemProperties .get (
79+ systemSecurityJaasPropertyPrefix + "certificateDomain" )).orElse (security .certificateDomain );
80+ } else if (broker .security instanceof SecurityManagerDTO security ) {
81+ security .className = Optional .ofNullable ((String )systemProperties .get (
82+ systemSecurityManagerPropertyPrefix + "className" )).orElse (security .className );
83+ security .properties = Objects .requireNonNullElse (security .properties , new ArrayList <>());
84+ systemProperties .forEach ((key , value ) -> {
85+ if (((String )key ).startsWith (systemSecurityManagerPropertyPrefix + "properties." )) {
86+ security .properties .add (new PropertyDTO (((String )key ).substring (
87+ systemSecurityManagerPropertyPrefix .length () + 11 ), (String )value ));
88+ }
89+ });
90+ }
4891 }
4992
5093 public static BrokerDTO createBrokerConfiguration (String configuration ,
0 commit comments