SpringBoot + ActiveMQ - How to install trusted packages?

I create two Springboot servers and client applications exchanging using JMS and everything works fine on release 5.12.1 for activemq, but as soon as I upgrade to version 5.12.3 I get the following error

 org.springframework.jms.support.converter.MessageConversionException: Could not convert JMS message; nested exception is javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class MyClass! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes. 

I went to the URL that is provided, and I realized that my problem was with the new security in ActiveMQ release 5.12.2 , and I understand that I can fix it by specifying reliable packages, but I donโ€™t know where to put this configuration in my SpringBoot project.

The only link I make to the JMS queue on my client and on my server is setting its URI in application.properties and @EnableJms on the JMS in my "main" class with @EnableJms , and here my configuration is on a separate broker:

 @Configuration @ConfigurationProperties(prefix = "activemq") public class BrokerConfiguration { /** * Defaults to TCP 10000 */ private String connectorURI = "tcp://0.0.0.0:10000"; private String kahaDBDataDir = "../../data/activemq"; public String getConnectorURI() { return connectorURI; } public void setConnectorURI(String connectorURI) { this.connectorURI = connectorURI; } public String getKahaDBDataDir() { return kahaDBDataDir; } public void setKahaDBDataDir(String kahaDBDataDir) { this.kahaDBDataDir = kahaDBDataDir; } @Bean(initMethod = "start", destroyMethod = "stop") public BrokerService broker() throws Exception { KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter(); persistenceAdapter.setDirectory(new File(kahaDBDataDir)); final BrokerService broker = new BrokerService(); broker.addConnector(getConnectorURI()); broker.setPersistent(true); broker.setPersistenceAdapter(persistenceAdapter); broker.setShutdownHooks(Collections.<Runnable> singletonList(new SpringContextHook())); broker.setUseJmx(false); final ManagementContext managementContext = new ManagementContext(); managementContext.setCreateConnector(true); broker.setManagementContext(managementContext); return broker; } } 

So, I would like to know where I should specify trusted packages.

Thanks:)

+8
java spring-boot activemq
source share
4 answers

Add the following bean:

 @Bean public ActiveMQConnectionFactory activeMQConnectionFactory() { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("your broker URL"); factory.setTrustedPackages(Arrays.asList("com.my.package")); return factory; } 

The ability to do this through the configuration property has been added for the next version: https://github.com/spring-projects/spring-boot/issues/5631

+11
source share

You can simply set one of the following spring boot properties in application.properties to install trusted packages.

spring.activemq.packages.trust-all=true

or

spring.activemq.packages.trusted=<package1>,<package2>,<package3>

+11
source share

Method: public void setTrustedPackages(List<String> trustedPackages)

Description: Add all the packets that are used to send and receive the Message object.

Code: connectionFactory.setTrustedPackages(Arrays.asList("org.api","java.util"))

Implemented Code:

 private static final String DEFAULT_BROKER_URL = "tcp://localhost:61616"; private static final String RESPONSE_QUEUE = "api-response"; @Bean public ActiveMQConnectionFactory connectionFactory(){ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); connectionFactory.setBrokerURL(DEFAULT_BROKER_URL); connectionFactory.setTrustedPackages(Arrays.asList("org.api","java.util")); return connectionFactory; } @Bean public JmsTemplate jmsTemplate(){ JmsTemplate template = new JmsTemplate(); template.setConnectionFactory(connectionFactory()); template.setDefaultDestinationName(RESPONSE_QUEUE); return template; } 
+1
source share

Yes, I found its config in the new version

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> spring: profiles: active: @profileActive@ cache: ehcache: config: ehcache.xml activemq: packages: trusted: com.stylrplus.api.model 
0
source share

All Articles