[ 
https://issues.apache.org/jira/browse/ARTEMIS-4231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17737401#comment-17737401
 ] 

Justin Bertram edited comment on ARTEMIS-4231 at 6/27/23 1:17 AM:
------------------------------------------------------------------

You can enable the management console via an embedded instance of Jetty managed 
by the broker using the following code:
{code:java}
System.setProperty("hawtio.realm", "hawtio");
System.setProperty("hawtio.role", "myRole");
System.setProperty("hawtio.rolePrincipalClasses", 
"org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal");
System.setProperty("java.security.auth.login.config", "/path/to/login.config");
String pathToArtemis = "/path/to/artemis";
EmbeddedActiveMQ server = new EmbeddedActiveMQ();
server.setMbeanServer(ManagementFactory.getPlatformMBeanServer());
server.setConfiguration(config.setJMXManagementEnabled(true)); 
server.start();
WebServerComponent webServerComponent = new WebServerComponent();
WebServerDTO webServerDTO = new WebServerDTO();
webServerDTO.path = "web";
BindingDTO bindingDTO = new BindingDTO();
bindingDTO.uri = "http://localhost:8161";;
AppDTO branding = new AppDTO();
branding.name = "branding";
branding.url = "activemq-branding";
branding.war = "activemq-branding.war";
AppDTO plugin = new AppDTO();
plugin.name = "plugin";
plugin.url = "artemis-plugin";
plugin.war = "artemis-plugin.war";
AppDTO console = new AppDTO();
console.name = "console";
console.url = "console";
console.war = "console.war";
bindingDTO.addApp(branding);
bindingDTO.addApp(plugin);
bindingDTO.addApp(console);
webServerDTO.addBinding(bindingDTO);
webServerComponent.configure(webServerDTO, pathToArtemis, pathToArtemis);
server.getActiveMQServer().addExternalComponent(webServerComponent, true);{code}

Your {{login.config}} might look something like this:
{noformat}
hawtio {
   org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule 
required
       debug=false
       reload=true
       org.apache.activemq.jaas.properties.user="hawtio-users.properties"
       org.apache.activemq.jaas.properties.role="hawtio-roles.properties";
};{noformat}
{{hawtio-users.properties}}:
{noformat}
myUser=myPass{noformat}
{{hawtio-roles.properties}}:
{noformat}
myRole=myUser{noformat}
Then you can login to the console at {{http://localhost:8161/console}} with the 
user {{myUser}} and the password {{myPass}}.


was (Author: jbertram):
You can enable the management console via an embedded instance of Jetty managed 
by the broker using the following code:
{code:java}
System.setProperty("hawtio.realm", "hawtio");
System.setProperty("hawtio.role", "myRole");
System.setProperty("hawtio.rolePrincipalClasses", 
"org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal");
System.setProperty("java.security.auth.login.config", "/path/to/login.config");
String pathToArtemis = "/path/to/artemis";
EmbeddedActiveMQ server = new EmbeddedActiveMQ();
server.setMbeanServer(ManagementFactory.getPlatformMBeanServer());
server.setConfiguration(config.setJMXManagementEnabled(true)); 
server.start();
WebServerComponent webServerComponent = new WebServerComponent();
WebServerDTO webServerDTO = new WebServerDTO();
webServerDTO.path = "web";
BindingDTO bindingDTO = new BindingDTO();
bindingDTO.uri = "http://localhost:8161";;
AppDTO branding = new AppDTO();
branding.name = "branding";
branding.url = "activemq-branding";
branding.war = "activemq-branding.war";
AppDTO plugin = new AppDTO();
plugin.name = "plugin";
plugin.url = "artemis-plugin";
plugin.war = "artemis-plugin.war";
AppDTO console = new AppDTO();
console.name = "console";
console.url = "console";
console.war = "console.war";
bindingDTO.addApp(branding);
bindingDTO.addApp(plugin);
bindingDTO.addApp(console);
webServerDTO.addBinding(bindingDTO);
webServerComponent.configure(webServerDTO, pathToArtemis, pathToArtemis);
server.getActiveMQServer().addExternalComponent(webServerComponent, true);{code}

Your {{login.config}} might look something like this:
{noformat}
hawtio {
   org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule 
required
       debug=false
       reload=true
       org.apache.activemq.jaas.properties.user="hawtio-users.properties"
       org.apache.activemq.jaas.properties.role="hawtio-roles.properties";
};{noformat}
{{hawtio-users.properties}}:
{noformat}
myUser=myPass{noformat}
{{hawtio-roles.properties}}:
{noformat}
myRole=myUser{noformat}
Then you can login to the console with the user {{myUser}} and the password 
{{myPass}}.

> Configure EmbeddedWebServer programmatically
> --------------------------------------------
>
>                 Key: ARTEMIS-4231
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4231
>             Project: ActiveMQ Artemis
>          Issue Type: Wish
>          Components: Configuration
>    Affects Versions: 2.28.0
>            Reporter: Raymond
>            Assignee: Justin Bertram
>            Priority: Major
>
> I would like to use the management console within my embedded broker.
> 1) I have Spring Boot application (using Jetty as a web server).
> 2) In the application I use an embedded broker.
> I use [this 
> documentation|https://activemq.apache.org/components/artemis/documentation/latest/embedding-activemq.html].
> The code:
> {code:java}
> EmbeddedActiveMQ server = new EmbeddedActiveMQ();
> server.setConfiguration(config); 
> server.start();{code}
> Now as a second step, I like to enable the management console. I checked 
> [this 
> documentation|https://activemq.apache.org/components/artemis/documentation/latest/web-server.html]
>  page. There it says that the embedded webserver can be managed through 
> various operations on the {{ActiveMQServerControl}}. The configuration is 
> done through "{{etc/bootstrap.xml}}". I of course don't have any 
> configuration files. Is there a way to programmatically run and configure the 
> management console together with my Spring Boot application?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to