Exposed the a Server.start method to injiect IAuthenticator and IAuthorizator to be embedded (fix issue #114)
This commit is contained in:
@@ -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<? extends InterceptHandler> handlers) throws IOException {
|
||||
startServer(config, handlers, null);
|
||||
startServer(config, handlers, null, null, null);
|
||||
}
|
||||
|
||||
public void startServer(IConfig config, List<? extends InterceptHandler> handlers, ISslContextCreator sslCtxCreator) throws IOException {
|
||||
public void startServer(IConfig config, List<? extends InterceptHandler> 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);
|
||||
|
||||
@@ -67,7 +67,19 @@ public class SimpleMessaging {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public ProtocolProcessor init(IConfig props, List<? extends InterceptHandler> 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<? extends InterceptHandler> 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);
|
||||
|
||||
Reference in New Issue
Block a user