Added integration of DBAuthenticator & integration test with H2 DB
This commit is contained in:
committed by
Christophe Mourette
parent
cad1165071
commit
4bcecd5aa3
@@ -105,7 +105,7 @@ public class SimpleMessaging {
|
||||
String authenticatorClassName = props.getProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
|
||||
|
||||
if (!authenticatorClassName.isEmpty()) {
|
||||
authenticator = (IAuthenticator)loadClass(authenticatorClassName, IAuthenticator.class);
|
||||
authenticator = (IAuthenticator)loadClass(authenticatorClassName, IAuthenticator.class, props);
|
||||
LOG.info("Loaded custom authenticator {}", authenticatorClassName);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class SimpleMessaging {
|
||||
|
||||
String authorizatorClassName = props.getProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
|
||||
if (!authorizatorClassName.isEmpty()) {
|
||||
authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class);
|
||||
authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class, props);
|
||||
LOG.info("Loaded custom authorizator {}", authorizatorClassName);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class SimpleMessaging {
|
||||
return m_processor;
|
||||
}
|
||||
|
||||
private Object loadClass(String className, Class<?> cls) {
|
||||
private Object loadClass(String className, Class<?> cls, IConfig props) {
|
||||
Object instance = null;
|
||||
try {
|
||||
Class<?> clazz = Class.forName(className);
|
||||
@@ -163,13 +163,25 @@ public class SimpleMessaging {
|
||||
}
|
||||
catch (NoSuchMethodException nsmex) {
|
||||
try {
|
||||
// check if constructor with IConfig parameter exists
|
||||
instance = this.getClass().getClassLoader()
|
||||
.loadClass(className)
|
||||
.asSubclass(cls)
|
||||
.newInstance();
|
||||
.getConstructor(IConfig.class).newInstance(props);
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
|
||||
LOG.error(null, ex);
|
||||
throw new RuntimeException("Cannot load custom authenticator class " + className, ex);
|
||||
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||
try {
|
||||
// fallback to default constructor
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.moquette.spi.impl.security;
|
||||
|
||||
import io.moquette.BrokerConstants;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.moquette.spi.security.IAuthenticator;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.slf4j.Logger;
|
||||
@@ -25,6 +27,15 @@ public class DBAuthenticator implements IAuthenticator {
|
||||
private final PreparedStatement preparedStatement;
|
||||
|
||||
|
||||
|
||||
|
||||
public DBAuthenticator(IConfig conf){
|
||||
this(conf.getProperty(BrokerConstants.DB_AUTHENTICATOR_DRIVER, ""),
|
||||
conf.getProperty(BrokerConstants.DB_AUTHENTICATOR_URL,""),
|
||||
conf.getProperty(BrokerConstants.DB_AUTHENTICATOR_QUERY, ""),
|
||||
conf.getProperty(BrokerConstants.DB_AUTHENTICATOR_DIGEST,""));
|
||||
}
|
||||
|
||||
/** provide authenticator from SQL database
|
||||
* @param driver : jdbc driver class like : "org.postgresql.Driver"
|
||||
* @param jdbcUrl : jdbc url like : "jdbc:postgresql://host:port/dbname"
|
||||
|
||||
Reference in New Issue
Block a user