added config options for authorizator_class and authenticator_class

This commit is contained in:
Luca Capra
2015-07-06 16:37:42 +02:00
parent 4663fa507b
commit f4ec180d85
4 changed files with 74 additions and 22 deletions
+1
View File
@@ -34,3 +34,4 @@ broker/runner
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
broker/moquette_store.*
@@ -60,6 +60,8 @@ class ConfigurationParser {
m_properties.put(PASSWORD_FILE_PROPERTY_NAME, ""); m_properties.put(PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(PERSISTENT_STORE_PROPERTY_NAME, DEFAULT_PERSISTENT_PATH); m_properties.put(PERSISTENT_STORE_PROPERTY_NAME, DEFAULT_PERSISTENT_PATH);
m_properties.put(ALLOW_ANONYMOUS_PROPERTY_NAME, true); m_properties.put(ALLOW_ANONYMOUS_PROPERTY_NAME, true);
m_properties.put(AUTHENTICATOR_CLASS_NAME, "");
m_properties.put(AUTHORIZATOR_CLASS_NAME, "");
} }
/** /**
@@ -43,6 +43,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import org.eclipse.moquette.commons.Constants;
import static org.eclipse.moquette.commons.Constants.PASSWORD_FILE_PROPERTY_NAME; import static org.eclipse.moquette.commons.Constants.PASSWORD_FILE_PROPERTY_NAME;
import static org.eclipse.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; import static org.eclipse.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME;
@@ -195,29 +197,73 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
//subscriptions.init(storedSubscriptions); //subscriptions.init(storedSubscriptions);
subscriptions.init(m_sessionsStore); subscriptions.init(m_sessionsStore);
String passwdPath = props.getProperty(PASSWORD_FILE_PROPERTY_NAME, ""); IAuthenticator authenticator = null;
String configPath = System.getProperty("moquette.path", null); String configPath = System.getProperty("moquette.path", null);
IAuthenticator authenticator; String authenticatorClassName = props.getProperty(Constants.AUTHENTICATOR_CLASS_NAME, "");
if (passwdPath.isEmpty()) {
authenticator = new AcceptAllAuthenticator(); if(!authenticatorClassName.isEmpty()) {
} else {
authenticator = new FileAuthenticator(configPath, passwdPath); try {
authenticator = this.getClass().getClassLoader()
.loadClass(authenticatorClassName)
.asSubclass(IAuthenticator.class)
.newInstance();
LOG.info("Loaded custom authenticator {}", authenticatorClassName);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
LOG.error("Cannot load custom authenticator class " + authenticatorClassName, ex);
}
} }
String aclFilePath = props.getProperty(ACL_FILE_PROPERTY_NAME, ""); if(authenticator == null) {
IAuthorizator authorizator; String passwdPath = props.getProperty(PASSWORD_FILE_PROPERTY_NAME, "");
if (aclFilePath != null && !aclFilePath.isEmpty()) { if (passwdPath.isEmpty()) {
authorizator = new DenyAllAuthorizator(); authenticator = new AcceptAllAuthenticator();
File aclFile = new File(configPath, aclFilePath); } else {
try { authenticator = new FileAuthenticator(configPath, passwdPath);
authorizator = ACLFileParser.parse(aclFile);
} catch (ParseException pex) {
LOG.error(String.format("Format error in parsing acl file %s", aclFile), pex);
} }
LOG.info("Using acl file defined at path {}", aclFilePath); }
} else {
authorizator = new PermitAllAuthorizator();
LOG.info("Starting without ACL definition"); IAuthorizator authorizator = null;
String authorizatorClassName = props.getProperty(Constants.AUTHORIZATOR_CLASS_NAME, "");
if(!authorizatorClassName.isEmpty()) {
try {
authorizator = this.getClass().getClassLoader()
.loadClass(authorizatorClassName)
.asSubclass(IAuthorizator.class)
.newInstance();
LOG.info("Loaded custom authorizator {}", authorizatorClassName);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
LOG.error("Cannot load custom authorizator class " + authenticatorClassName, ex);
}
}
if(authorizator == null) {
String aclFilePath = props.getProperty(ACL_FILE_PROPERTY_NAME, "");
if (aclFilePath != null && !aclFilePath.isEmpty()) {
authorizator = new DenyAllAuthorizator();
File aclFile = new File(configPath, aclFilePath);
try {
authorizator = ACLFileParser.parse(aclFile);
} catch (ParseException pex) {
LOG.error(String.format("Format error in parsing acl file %s", aclFile), pex);
}
LOG.info("Using acl file defined at path {}", aclFilePath);
} else {
authorizator = new PermitAllAuthorizator();
LOG.info("Starting without ACL definition");
}
} }
boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(ALLOW_ANONYMOUS_PROPERTY_NAME, "true")); boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(ALLOW_ANONYMOUS_PROPERTY_NAME, "true"));
@@ -39,4 +39,7 @@ public class Constants {
public static final String KEY_MANAGER_PASSWORD_PROPERTY_NAME = "key_manager_password"; public static final String KEY_MANAGER_PASSWORD_PROPERTY_NAME = "key_manager_password";
public static final String ALLOW_ANONYMOUS_PROPERTY_NAME = "allow_anonymous"; public static final String ALLOW_ANONYMOUS_PROPERTY_NAME = "allow_anonymous";
public static final String ACL_FILE_PROPERTY_NAME = "acl_file"; public static final String ACL_FILE_PROPERTY_NAME = "acl_file";
public static final String AUTHORIZATOR_CLASS_NAME = "authorizator_class";
public static final String AUTHENTICATOR_CLASS_NAME = "authenticator_class";
} }