Added 'admin_username' and 'admin_password' options
This commit is contained in:
parent
9d844f333c
commit
66105b8dd8
4 changed files with 19 additions and 4 deletions
|
@ -80,8 +80,8 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element)
|
|||
}
|
||||
else {
|
||||
PLAINMessage plainMessage(authRequest->getMessage() ? *authRequest->getMessage() : createSafeByteArray(""));
|
||||
user_ = plainMessage.getAuthenticationID();
|
||||
if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), getLocalJID().getDomain()), plainMessage.getPassword())) {
|
||||
user_ = plainMessage.getAuthenticationID();
|
||||
// we're waiting for usermanager signal now
|
||||
// authenticated_ = true;
|
||||
// getXMPPLayer()->resetParser();
|
||||
|
|
|
@ -6,6 +6,8 @@ port = 5222
|
|||
server_mode = 1
|
||||
backend_host=localhost # < this option doesn't work yet
|
||||
backend_port=10001
|
||||
admin_username=admin
|
||||
admin_password=test
|
||||
#cert= #patch to PKCS#12 certificate
|
||||
#cert_password= #password to that certificate if any
|
||||
users_per_backend=2
|
||||
|
|
|
@ -44,6 +44,8 @@ bool Config::load(const std::string &configfile, boost::program_options::options
|
|||
("service.backend_port", value<std::string>()->default_value("10000"), "Port to bind backend server to")
|
||||
("service.cert", value<std::string>()->default_value(""), "PKCS#12 Certificate.")
|
||||
("service.cert_password", value<std::string>()->default_value(""), "PKCS#12 Certificate password.")
|
||||
("service.admin_username", value<std::string>()->default_value(""), "Administrator username.")
|
||||
("service.admin_password", value<std::string>()->default_value(""), "Administrator password.")
|
||||
("registration.enable_public_registration", value<bool>()->default_value(true), "True if users should be able to register.")
|
||||
("registration.language", value<std::string>()->default_value("en"), "Default language for registration form")
|
||||
("registration.instructions", value<std::string>()->default_value(""), "Instructions showed to user in registration form")
|
||||
|
|
|
@ -48,20 +48,31 @@ static LoggerPtr logger_xml = Logger::getLogger("Component.XML");
|
|||
|
||||
class MyUserRegistry : public Swift::UserRegistry {
|
||||
public:
|
||||
MyUserRegistry(Component *c) {component = c;}
|
||||
MyUserRegistry(Component *c, Config *cfg) {component = c; config = cfg;}
|
||||
~MyUserRegistry() {}
|
||||
bool isValidUserPassword(const JID& user, const Swift::SafeByteArray& password) const {
|
||||
if (!CONFIG_STRING(config, "service.admin_username").empty() && user.getNode() == CONFIG_STRING(config, "service.admin_username")) {
|
||||
LOG4CXX_INFO(logger, "Admin is trying to login");
|
||||
if (Swift::safeByteArrayToString(password) == CONFIG_STRING(config, "service.admin_password")) {
|
||||
onPasswordValid(user);
|
||||
}
|
||||
else {
|
||||
onPasswordInvalid(user);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
users[user.toBare().toString()] = Swift::safeByteArrayToString(password);
|
||||
Swift::Presence::ref response = Swift::Presence::create();
|
||||
response->setTo(component->getJID());
|
||||
response->setFrom(user);
|
||||
response->setType(Swift::Presence::Available);
|
||||
component->onUserPresenceReceived(response);
|
||||
std::cout << "CONNECTED LOGIN 1" << user.toString() << "\n";
|
||||
return true;
|
||||
}
|
||||
mutable std::map<std::string, std::string> users;
|
||||
mutable Component *component;
|
||||
mutable Config *config;
|
||||
};
|
||||
|
||||
Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
|
||||
|
@ -90,7 +101,7 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
|
|||
|
||||
if (CONFIG_BOOL(m_config, "service.server_mode")) {
|
||||
LOG4CXX_INFO(logger, "Creating component in server mode on port " << CONFIG_INT(m_config, "service.port"));
|
||||
m_userRegistry = new MyUserRegistry(this);
|
||||
m_userRegistry = new MyUserRegistry(this, m_config);
|
||||
m_server = new Swift::Server(loop, m_factories, m_userRegistry, m_jid, CONFIG_INT(m_config, "service.port"));
|
||||
if (!CONFIG_STRING(m_config, "service.cert").empty()) {
|
||||
LOG4CXX_INFO(logger, "Using PKCS#12 certificate " << CONFIG_STRING(m_config, "service.cert"));
|
||||
|
|
Loading…
Add table
Reference in a new issue