From 446c8465728fffe7a9278accb41c5af14a5fad34 Mon Sep 17 00:00:00 2001 From: andsel Date: Sun, 13 Dec 2015 17:01:23 +0100 Subject: [PATCH] Exposed the a Server.start method to injiect IAuthenticator and IAuthorizator to be embedded (fix issue #114) --- .../src/main/java/io/moquette/server/Server.java | 10 +++++++--- .../io/moquette/spi/impl/SimpleMessaging.java | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/broker/src/main/java/io/moquette/server/Server.java b/broker/src/main/java/io/moquette/server/Server.java index 031a3f90..70d54648 100644 --- a/broker/src/main/java/io/moquette/server/Server.java +++ b/broker/src/main/java/io/moquette/server/Server.java @@ -24,6 +24,8 @@ import io.moquette.server.config.FilesystemConfig; import io.moquette.server.config.IConfig; import io.moquette.server.netty.NettyAcceptor; import io.moquette.spi.impl.ProtocolProcessor; +import io.moquette.spi.security.IAuthenticator; +import io.moquette.spi.security.IAuthorizator; import io.moquette.spi.security.ISslContextCreator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,10 +107,12 @@ public class Server { * set of InterceptHandler. * */ public void startServer(IConfig config, List handlers) throws IOException { - startServer(config, handlers, null); + startServer(config, handlers, null, null, null); } - public void startServer(IConfig config, List handlers, ISslContextCreator sslCtxCreator) throws IOException { + public void startServer(IConfig config, List handlers, + ISslContextCreator sslCtxCreator, IAuthenticator authenticator, + IAuthorizator authorizator) throws IOException { if (handlers == null) { handlers = Collections.emptyList(); } @@ -118,7 +122,7 @@ public class Server { config.setProperty("intercept.handler", handlerProp); } LOG.info("Persistent store file: " + config.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME)); - final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config, handlers); + final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config, handlers, authenticator, authorizator); if (sslCtxCreator == null) { sslCtxCreator = new DefaultMoquetteSslContextCreator(config); diff --git a/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java b/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java index da1f624f..0f6d96e6 100644 --- a/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java +++ b/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java @@ -67,7 +67,19 @@ public class SimpleMessaging { return INSTANCE; } - public ProtocolProcessor init(IConfig props, List embeddedObservers) { + /** + * Initialize the processing part of the broker. + * @param props the properties carrier where some props like port end host could be loaded. + * For the full list check of configurable properties check moquette.conf file. + * @param embeddedObservers a list of callbacks to be notified of certain events inside the broker. + * Could be empty list of null. + * @param authenticator an implementation of the authenticator to be used, if null load that specified in config + * and fallback on the default one (permit all). + * @param authorizator an implementation of the authorizator to be used, if null load that specified in config + * and fallback on the default one (permit all). + * */ + public ProtocolProcessor init(IConfig props, List embeddedObservers, + IAuthenticator authenticator, IAuthorizator authorizator) { subscriptions = new SubscriptionsStore(); m_mapStorage = new MapDBPersistentStore(props); @@ -92,7 +104,6 @@ public class SimpleMessaging { String configPath = System.getProperty("moquette.path", null); String authenticatorClassName = props.getProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, ""); - IAuthenticator authenticator = null; if (!authenticatorClassName.isEmpty()) { authenticator = (IAuthenticator)loadClass(authenticatorClassName, IAuthenticator.class); LOG.info("Loaded custom authenticator {}", authenticatorClassName); @@ -107,7 +118,6 @@ public class SimpleMessaging { } } - IAuthorizator authorizator = null; String authorizatorClassName = props.getProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, ""); if (!authorizatorClassName.isEmpty()) { authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class);