Fixed issue #42
This commit is contained in:
+10
-5
@@ -23,16 +23,21 @@ public class FileAuthenticator implements IAuthenticator {
|
||||
|
||||
private Map<String, String> m_identities = new HashMap<String, String>();
|
||||
|
||||
FileAuthenticator(String filePath) {
|
||||
LOG.info("Loading password file: " + filePath);
|
||||
File file = new File(filePath);
|
||||
FileAuthenticator(String parent, String filePath) {
|
||||
File file = new File(parent, filePath);
|
||||
LOG.info("Loading password file: " + file);
|
||||
if (file.isDirectory()) {
|
||||
LOG.warn(String.format("Bad file reference %s is a directory", file));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
FileReader reader = new FileReader(file);
|
||||
parse(reader);
|
||||
} 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) {
|
||||
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);
|
||||
|
||||
String passwdPath = props.getProperty("password_file");
|
||||
String configPath = System.getProperty("moquette.path", "");
|
||||
IAuthenticator authenticator = new FileAuthenticator(configPath + passwdPath);
|
||||
String configPath = System.getProperty("moquette.path", null);
|
||||
IAuthenticator authenticator = new FileAuthenticator(configPath, passwdPath);
|
||||
|
||||
m_processor.init(subscriptions, m_storageService, authenticator);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class ConfigurationParser {
|
||||
ConfigurationParser() {
|
||||
m_properties.put("port", Integer.toString(Constants.PORT));
|
||||
m_properties.put("host", Constants.HOST);
|
||||
m_properties.put("password_file", "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,8 +40,8 @@ public class Server {
|
||||
public void startServer() throws IOException {
|
||||
ConfigurationParser confParser = new ConfigurationParser();
|
||||
try {
|
||||
String configPath = System.getProperty("moquette.path", "");
|
||||
confParser.parse(new File(configPath + "config/moquette.conf"));
|
||||
String configPath = System.getProperty("moquette.path", null);
|
||||
confParser.parse(new File(configPath, "config/moquette.conf"));
|
||||
} catch (ParseException pex) {
|
||||
LOG.warn("An error occured in parsing configuration, fallback on default configuration", pex);
|
||||
}
|
||||
|
||||
+10
-2
@@ -13,7 +13,7 @@ public class FileAuthenticatorTest {
|
||||
@Test
|
||||
public void loadPasswordFile_verifyValid() {
|
||||
String file = getClass().getResource("/password_file.conf").getPath();
|
||||
IAuthenticator auth = new FileAuthenticator(file);
|
||||
IAuthenticator auth = new FileAuthenticator(null, file);
|
||||
|
||||
assertTrue(auth.checkValid("testuser", "passwd"));
|
||||
}
|
||||
@@ -21,8 +21,16 @@ public class FileAuthenticatorTest {
|
||||
@Test
|
||||
public void loadPasswordFile_verifyInvalid() {
|
||||
String file = getClass().getResource("/password_file.conf").getPath();
|
||||
IAuthenticator auth = new FileAuthenticator(file);
|
||||
IAuthenticator auth = new FileAuthenticator(null, file);
|
||||
|
||||
assertFalse(auth.checkValid("testuser2", "passwd"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadPasswordFile_verifyDirectoryRef() {
|
||||
IAuthenticator auth = new FileAuthenticator("", "");
|
||||
|
||||
assertFalse(auth.checkValid("testuser2", "passwd"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user