Fixed issue #42

This commit is contained in:
selva.andre
2014-05-05 22:53:42 +02:00
parent 4d2bf38a66
commit 8a7db6ee15
6 changed files with 28 additions and 11 deletions
+3
View File
@@ -1,3 +1,6 @@
Version 0.6:
Fix issue 42, bad password file path composition
Version 0.5: Version 0.5:
Fix issue 20 (no flush of message on PINGREQ) Fix issue 20 (no flush of message on PINGREQ)
Fix issue 21 (bad channel timeout handler) Fix issue 21 (bad channel timeout handler)
@@ -23,16 +23,21 @@ public class FileAuthenticator implements IAuthenticator {
private Map<String, String> m_identities = new HashMap<String, String>(); private Map<String, String> m_identities = new HashMap<String, String>();
FileAuthenticator(String filePath) { FileAuthenticator(String parent, String filePath) {
LOG.info("Loading password file: " + filePath); File file = new File(parent, filePath);
File file = new File(filePath); LOG.info("Loading password file: " + file);
if (file.isDirectory()) {
LOG.warn(String.format("Bad file reference %s is a directory", file));
return;
}
try { try {
FileReader reader = new FileReader(file); FileReader reader = new FileReader(file);
parse(reader); parse(reader);
} catch (FileNotFoundException fex) { } catch (FileNotFoundException fex) {
LOG.warn(String.format("Parsing not existing file %s", filePath), fex); LOG.warn(String.format("Parsing not existing file %s", file), fex);
} catch (ParseException pex) { } catch (ParseException pex) {
LOG.warn(String.format("Fromat ero in parsing password file %s", filePath), pex); LOG.warn(String.format("Fromat ero in parsing password file %s", file), pex);
} }
} }
@@ -188,8 +188,8 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
subscriptions.init(m_storageService); subscriptions.init(m_storageService);
String passwdPath = props.getProperty("password_file"); String passwdPath = props.getProperty("password_file");
String configPath = System.getProperty("moquette.path", ""); String configPath = System.getProperty("moquette.path", null);
IAuthenticator authenticator = new FileAuthenticator(configPath + passwdPath); IAuthenticator authenticator = new FileAuthenticator(configPath, passwdPath);
m_processor.init(subscriptions, m_storageService, authenticator); m_processor.init(subscriptions, m_storageService, authenticator);
} }
@@ -29,6 +29,7 @@ class ConfigurationParser {
ConfigurationParser() { ConfigurationParser() {
m_properties.put("port", Integer.toString(Constants.PORT)); m_properties.put("port", Integer.toString(Constants.PORT));
m_properties.put("host", Constants.HOST); m_properties.put("host", Constants.HOST);
m_properties.put("password_file", "");
} }
/** /**
@@ -40,8 +40,8 @@ public class Server {
public void startServer() throws IOException { public void startServer() throws IOException {
ConfigurationParser confParser = new ConfigurationParser(); ConfigurationParser confParser = new ConfigurationParser();
try { try {
String configPath = System.getProperty("moquette.path", ""); String configPath = System.getProperty("moquette.path", null);
confParser.parse(new File(configPath + "config/moquette.conf")); confParser.parse(new File(configPath, "config/moquette.conf"));
} catch (ParseException pex) { } catch (ParseException pex) {
LOG.warn("An error occured in parsing configuration, fallback on default configuration", pex); LOG.warn("An error occured in parsing configuration, fallback on default configuration", pex);
} }
@@ -13,7 +13,7 @@ public class FileAuthenticatorTest {
@Test @Test
public void loadPasswordFile_verifyValid() { public void loadPasswordFile_verifyValid() {
String file = getClass().getResource("/password_file.conf").getPath(); String file = getClass().getResource("/password_file.conf").getPath();
IAuthenticator auth = new FileAuthenticator(file); IAuthenticator auth = new FileAuthenticator(null, file);
assertTrue(auth.checkValid("testuser", "passwd")); assertTrue(auth.checkValid("testuser", "passwd"));
} }
@@ -21,8 +21,16 @@ public class FileAuthenticatorTest {
@Test @Test
public void loadPasswordFile_verifyInvalid() { public void loadPasswordFile_verifyInvalid() {
String file = getClass().getResource("/password_file.conf").getPath(); String file = getClass().getResource("/password_file.conf").getPath();
IAuthenticator auth = new FileAuthenticator(file); IAuthenticator auth = new FileAuthenticator(null, file);
assertFalse(auth.checkValid("testuser2", "passwd")); assertFalse(auth.checkValid("testuser2", "passwd"));
} }
@Test
public void loadPasswordFile_verifyDirectoryRef() {
IAuthenticator auth = new FileAuthenticator("", "");
assertFalse(auth.checkValid("testuser2", "passwd"));
}
} }