-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEmbeddedArtemisInitializer.java
More file actions
79 lines (72 loc) · 2.87 KB
/
EmbeddedArtemisInitializer.java
File metadata and controls
79 lines (72 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package uk.gov.justice.artemis;
import java.util.Set;
import org.apache.activemq.artemis.core.security.CheckType;
import org.apache.activemq.artemis.core.security.Role;
import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
/**
*
* An utility class for initialising an EmbeddedJMS instance <br>
* with certain checks and configuration objects.
*
* @see org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS
*
*/
public final class EmbeddedArtemisInitializer {
/**
* Private constructor to avoid instantiating the utility class.
*/
private EmbeddedArtemisInitializer() {}
/**
* Initialise an EmbeddedJMS with a configuration XML and security manager.
*
* @param jmsServer to be initialised
* @return EmbeddedJMS
* @see org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS
*/
public static EmbeddedJMS initialize(final EmbeddedJMS jmsServer) {
jmsServer.setConfigResourcePath("broker.xml");
jmsServer.setSecurityManager(getSecurityManager());
return jmsServer;
}
/**
* Ensure that the ActiveMQServerLogger loggers are in the class path and loaded correctly. <br>
* <br>
* The ActiveMQServerLogger_$logger classes are generated dynamically and bundled in the <br>
* executable jars.<br>
* Having ActiveMQ jars without the bundled _$logger in the class path lead to <br>
* spurious errors that we want to avoid by having an initialisation check.
*/
public static void checkLoggers() {
org.apache.activemq.artemis.core.server.ActiveMQServerLogger.class.getCanonicalName();
org.apache.activemq.artemis.core.server.ActiveMQServerLogger_$logger.class
.getCanonicalName();
}
/**
* An overridden security manager to cater for multiple test configuration <br>
* users and passwords. <br>
* <br>
* The returned security manager does not check for user passwords or user roles. <br>
* <br>
* Different project setups use different user/passwords in connections<br>
* which can quite conveniently be handled by this SecurityManager.
* <br>
* The EmbeddedArtemisServer should only be used <b>for testing</b>.
*
* @return ActiveMQSecurityManager
* @see ActiveMQSecurityManager
*/
public static ActiveMQSecurityManager getSecurityManager() {
return new ActiveMQSecurityManager() {
@Override
public boolean validateUser(final String user, final String password) {
return true;
}
@Override
public boolean validateUserAndRole(final String user, final String password,
final Set<Role> roles, final CheckType checkType) {
return true;
}
};
}
}