Minor, added authorizator and autheticator class variables in the config used in distribution
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Version 0.8:
|
||||
Introduced authenticator and authorizator implementations.
|
||||
|
||||
Version 0.7:
|
||||
Fix issue #38, added aligned to MQTT 3.1.1
|
||||
|
||||
@@ -196,17 +196,16 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
|
||||
//subscriptions.init(storedSubscriptions);
|
||||
subscriptions.init(m_sessionsStore);
|
||||
|
||||
IAuthenticator authenticator = null;
|
||||
|
||||
String configPath = System.getProperty("moquette.path", null);
|
||||
String configPath = System.getProperty("moquette.path", null);
|
||||
String authenticatorClassName = props.getProperty(Constants.AUTHENTICATOR_CLASS_NAME, "");
|
||||
|
||||
if(!authenticatorClassName.isEmpty()) {
|
||||
authenticator = (IAuthenticator)loadClass(authenticatorClassName, IAuthenticator.class);
|
||||
LOG.info("Loaded custom authenticator {}", authenticatorClassName);
|
||||
|
||||
IAuthenticator authenticator = null;
|
||||
if (!authenticatorClassName.isEmpty()) {
|
||||
authenticator = (IAuthenticator)loadClass(authenticatorClassName, IAuthenticator.class);
|
||||
LOG.info("Loaded custom authenticator {}", authenticatorClassName);
|
||||
}
|
||||
|
||||
if(authenticator == null) {
|
||||
|
||||
if (authenticator == null) {
|
||||
String passwdPath = props.getProperty(PASSWORD_FILE_PROPERTY_NAME, "");
|
||||
if (passwdPath.isEmpty()) {
|
||||
authenticator = new AcceptAllAuthenticator();
|
||||
@@ -214,18 +213,15 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
|
||||
authenticator = new FileAuthenticator(configPath, passwdPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IAuthorizator authorizator = null;
|
||||
|
||||
IAuthorizator authorizator = null;
|
||||
String authorizatorClassName = props.getProperty(Constants.AUTHORIZATOR_CLASS_NAME, "");
|
||||
if(!authorizatorClassName.isEmpty()) {
|
||||
if (!authorizatorClassName.isEmpty()) {
|
||||
authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class);
|
||||
LOG.info("Loaded custom authorizator {}", authorizatorClassName);
|
||||
}
|
||||
|
||||
if(authorizator == null) {
|
||||
}
|
||||
|
||||
if (authorizator == null) {
|
||||
String aclFilePath = props.getProperty(ACL_FILE_PROPERTY_NAME, "");
|
||||
if (aclFilePath != null && !aclFilePath.isEmpty()) {
|
||||
authorizator = new DenyAllAuthorizator();
|
||||
@@ -242,17 +238,14 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(ALLOW_ANONYMOUS_PROPERTY_NAME, "true"));
|
||||
m_processor.init(subscriptions, m_storageService, m_sessionsStore, authenticator, allowAnonymous, authorizator);
|
||||
}
|
||||
|
||||
private Object loadClass(String className, Class<?> cls) {
|
||||
|
||||
Object instance = null;
|
||||
|
||||
try {
|
||||
|
||||
Class<?> clazz = Class.forName(className);
|
||||
|
||||
// check if method getInstance exists
|
||||
@@ -263,21 +256,17 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
|
||||
LOG.error(null, ex);
|
||||
throw new RuntimeException("Cannot call method "+ className +".getInstance", ex);
|
||||
}
|
||||
|
||||
}
|
||||
catch (NoSuchMethodException noMethodEx) {
|
||||
|
||||
catch (NoSuchMethodException nsmex) {
|
||||
try {
|
||||
instance = this.getClass().getClassLoader()
|
||||
.loadClass(className)
|
||||
.asSubclass(cls)
|
||||
.newInstance();
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
|
||||
LOG.error(null, ex);
|
||||
throw new RuntimeException("Cannot load custom authenticator class " + className, ex);
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException ex) {
|
||||
LOG.error(null, ex);
|
||||
throw new RuntimeException("Class " + className + " not found", ex);
|
||||
|
||||
@@ -59,3 +59,20 @@ allow_anonymous true
|
||||
# defined by the system property moquette.path
|
||||
#*********************************************************************
|
||||
password_file config/password_file.conf
|
||||
|
||||
|
||||
#*********************************************************************
|
||||
# Optional
|
||||
# authorizator_class:
|
||||
# class name of the authorizator, by default uses the
|
||||
# password_file.conf.
|
||||
# If not specified uses the class: org.eclipse.moquette.spi.impl.security.AuthorizationsCollector
|
||||
#
|
||||
# Optional
|
||||
# authenticator_class:
|
||||
# class name of the authenticator, default implementation uses
|
||||
# definitions in the acl.conf.
|
||||
# If not specified uses org.eclipse.moquette.spi.impl.security.FileAuthenticator
|
||||
#*********************************************************************
|
||||
# authenticator_class [[path to your class>]]
|
||||
# authorizator_class [[path to your class>]]
|
||||
@@ -34,6 +34,10 @@
|
||||
</developers>
|
||||
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Steven Warwick</name>
|
||||
<url>http://stevenwarwick.com</url>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Igor Yova</name>
|
||||
<url>https://github.com/Fameing</url>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
@Grab(group='org.fusesource.mqtt-client', module='mqtt-client', version='1.10')
|
||||
|
||||
import org.fusesource.mqtt.client.BlockingConnection
|
||||
import org.fusesource.mqtt.client.MQTT
|
||||
import org.fusesource.mqtt.client.Message
|
||||
import org.fusesource.mqtt.client.QoS
|
||||
import org.fusesource.mqtt.client.Topic
|
||||
|
||||
|
||||
String host = args[0]
|
||||
//start a publisher
|
||||
MQTT mqtt2 = new MQTT()
|
||||
mqtt2.setHost(host, 1883)
|
||||
mqtt2.setUserName("gravity")
|
||||
mqtt2.setPassword("passwd")
|
||||
BlockingConnection client = mqtt2.blockingConnection()
|
||||
client.connect()
|
||||
String topicOut = "out"
|
||||
String topicIn = "in"
|
||||
/*println "try to publish (write) on topic ${topicOut}"
|
||||
|
||||
client.publish(topicOut, 'publish test!!'.bytes, QoS.AT_MOST_ONCE, false)
|
||||
println "published"
|
||||
|
||||
println "try to subscribe (read) on topic ${topicIn}"
|
||||
client.subscribe([new Topic(topicIn, QoS.AT_LEAST_ONCE)] as Topic[])
|
||||
println "subscribed"*/
|
||||
println "try to subscribe (read) on topic that should fail, ${topicOut}"
|
||||
client.subscribe([new Topic(topicOut, QoS.AT_LEAST_ONCE)] as Topic[])
|
||||
println "if subscribed is an error!!"
|
||||
|
||||
/*String topicUntouch = "untouchable"
|
||||
println "try to subscribe (read) on untouchable topic for this user, ${topicUntouch}"
|
||||
client.subscribe([new Topic(topicUntouch, QoS.AT_LEAST_ONCE)] as Topic[])
|
||||
println "subscribed to untouchable, if subscribed is an error!!"*/
|
||||
|
||||
println "shutdown client"
|
||||
client.disconnect()
|
||||
Reference in New Issue
Block a user