Loading config.yaml +9 −5 Changes for config.yaml: 9 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -15,11 +15,15 @@ BLOGI: DATABASE: DRIVER: "sqlite" CONNECTION: "/var/lib/blogi/blog.db" LDAP: HOST: "ldap://ldaphost:389" DOMAIN: "mydomain.local" BASEDN: "CN=Users,DC=mydomain,DC=local" LOGINFILTER: " " AUTHDB: URL: - "https://auth.example.com" CLIENTNAME: - "blogiclient" CLIENTSECRET: - "clientsecret" DOMAIN: - "example.com" REDIS: HOST: "127.0.0.1" PORT: 6379 Loading docker-config.yaml +8 −3 Changes for docker-config.yaml: 8 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -20,6 +20,11 @@ BLOGI: DOMAIN: NAME: "%COOKIE%" AUTHDB: URL: "%CLIENTURL%" CLIENTNAME: "%CLIENTNAME%" CLIENTSECRET: "%CLIENTSECRET%" URL: - "%CLIENTURL%" CLIENTNAME: - "%CLIENTNAME%" CLIENTSECRET: - "%CLIENTSECRET%" DOMAIN: - "%AUTHDOMAIN%" src/auth.cpp +53 −43 Changes for src/auth.cpp: 53 added lines, 43 removed lines. Original line number Diff line number Diff line Loading @@ -65,13 +65,14 @@ blogi::Auth::~Auth(){ } void blogi::Auth::login(const int tid,const char* username, const char* password,uuid::uuid &authid, const std::string &ssid){ void blogi::Auth::_doLogin(const AuthSource &src, const char *username, const char *password, uuid::uuid &authid, const int tid, const std::string *ssid){ libhttppp::HTTPException httpException; authdb::client::ClientConnection authcon; authcon.setUrl(_config.getAuthUrl()); authcon.setClientName(_config.getClientName()); authcon.setClientSecret(_config.getClientSecret()); authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authdb::client::Client clt(authcon); Loading @@ -93,17 +94,17 @@ void blogi::Auth::login(const int tid,const char* username, const char* password ret = clt.GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6"); if(ret){ if(ssid){ Session sess(*_dbconn[tid]); sess.addSessionData(ssid,"authid",authcon.getSessionID().c_str()); sess.addSessionData(*ssid,"authid",authcon.getSessionID().c_str()); class authdb::SessionData sdat; clt.SessionInfo(sdat); // Can throw AuthBackendError clt.SessionInfo(sdat); uuid::uuid uid; sdat.getUid(uid); sess.addSessionData(ssid,"uid",uid.c_str()); sess.addSessionData(*ssid,"uid",uid.c_str()); } authid = authcon.getSessionID(); } else { clt.remSession(); Loading @@ -115,62 +116,66 @@ void blogi::Auth::login(const int tid,const char* username, const char* password clt.remSession(); } catch (authdb::AuthBackendError &cleanupE) { } httpException[libhttppp::HTTPException::Error] << "Authentication backend error: " << e.what(); throw httpException; } } void blogi::Auth::Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid){ void blogi::Auth::login(const int tid,const char* username, const char* password,uuid::uuid &authid, const std::string &ssid, const std::string &domain){ libhttppp::HTTPException httpException; authdb::client::ClientConnection authcon; authcon.setUrl(_config.getAuthUrl()); authcon.setClientName(_config.getClientName()); authcon.setClientSecret(_config.getClientSecret()); authdb::client::Client clt(authcon); // Parse user@domain if no explicit domain provided std::string user(username); std::string dom = domain; if(dom.empty()){ auto atpos = user.rfind('@'); if(atpos != std::string::npos){ dom = user.substr(atpos + 1); user = user.substr(0, atpos); } } if(!clt.ClientAuth()){ httpException[libhttppp::HTTPException::Error] << "ClientAuth failed!"; const AuthSource *src = _config.findAuthSource(dom); if(!src){ httpException[libhttppp::HTTPException::Error] << "No auth source found for domain: " << dom; throw httpException; } authcon.setUsername(username); authcon.setUserPassword(password); bool ret = clt.UserAuth(); if(!ret) { httpException[libhttppp::HTTPException::Error] << "UserAuth failed (Invalid credentials)!"; throw httpException; _doLogin(*src, user.c_str(), password, authid, tid, &ssid); } try { ret = clt.GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6"); void blogi::Auth::Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid, const std::string &domain){ libhttppp::HTTPException httpException; if(ret){ authid = authcon.getSessionID(); } else { // GPO check failed, clean up the session clt.remSession(); httpException[libhttppp::HTTPException::Error] << "User GPO check failed!"; throw httpException; // Parse user@domain if no explicit domain provided std::string user(username); std::string dom = domain; if(dom.empty()){ auto atpos = user.rfind('@'); if(atpos != std::string::npos){ dom = user.substr(atpos + 1); user = user.substr(0, atpos); } } catch (authdb::AuthBackendError &e) { try { clt.remSession(); } catch (authdb::AuthBackendError &cleanupE) { } httpException[libhttppp::HTTPException::Error] << "Authentication backend error: " << e.what(); const AuthSource *src = _config.findAuthSource(dom); if(!src){ httpException[libhttppp::HTTPException::Error] << "No auth source found for domain: " << dom; throw httpException; } _doLogin(*src, user.c_str(), password, authid, tid, nullptr); } bool blogi::Auth::isLoggedIn(const int tid,const uuid::uuid &authid){ // Try all auth sources until one succeeds for(size_t i = 0; i < _config.getAuthSourceCount(); ++i){ const AuthSource &src = _config.getAuthSource(i); try { authdb::client::ClientConnection authcon; authcon.setUrl( _config.getAuthUrl()); authcon.setClientName(_config.getClientName()); authcon.setClientSecret(_config.getClientSecret()); authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authcon.setSessionID(authid); std::unique_ptr<authdb::client::Client> clt; Loading @@ -184,6 +189,11 @@ bool blogi::Auth::isLoggedIn(const int tid,const uuid::uuid &authid){ if(clt->ClientAuth() && clt->GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6")){ return true; } } catch(...) { // This source didn't work, try the next one continue; } } return false; } Loading src/auth.h +4 −2 Changes for src/auth.h: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -45,11 +45,13 @@ namespace blogi { public: Auth(std::vector<std::unique_ptr<dbpp::Database>> &pcon,const blogi::Config &cfg); ~Auth(); void login(const int tid,const char *username,const char *password,uuid::uuid &authid,const std::string &ssid); void Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid); void login(const int tid,const char *username,const char *password,uuid::uuid &authid,const std::string &ssid,const std::string &domain=""); void Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid,const std::string &domain=""); bool isLoggedIn(const int tid,const uuid::uuid &authid); bool isLoggedIn(const int tid,libhttppp::HttpRequest &curreq,const std::string &ssid); private: void _doLogin(const AuthSource &src, const char *username, const char *password, uuid::uuid &authid, const int tid, const std::string *ssid); std::vector<std::unique_ptr<dbpp::Database>> &_dbconn; const blogi::Config &_config; Loading src/blogi.cpp +1 −1 Changes for src/blogi.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -386,7 +386,7 @@ void blogi::Blogi::loginPage(libhttppp::HttpRequest &curreq,const int tid,const condat << "<div id=\"content\">" << "<span>" << blogi::tr(_lang,"Login") << "</span>" << "<form action=\""<< PlgArgs->config->buildurl("login") << "\" method=\"post\">" << blogi::tr(_lang,"username:") << "<br> <input type=\"text\" name=\"username\" value=\"\"><br>" << blogi::tr(_lang,"username:") << "<br> <input type=\"text\" name=\"username\" value=\"\" placeholder=\"user@domain\"><br>" << blogi::tr(_lang,"password:") << "<br> <input type=\"password\" name=\"password\" value=\"\"><br>" << "<button type=\"submit\">" << blogi::tr(_lang,"Submit") << "</button>" << "</form>" Loading Loading
config.yaml +9 −5 Changes for config.yaml: 9 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -15,11 +15,15 @@ BLOGI: DATABASE: DRIVER: "sqlite" CONNECTION: "/var/lib/blogi/blog.db" LDAP: HOST: "ldap://ldaphost:389" DOMAIN: "mydomain.local" BASEDN: "CN=Users,DC=mydomain,DC=local" LOGINFILTER: " " AUTHDB: URL: - "https://auth.example.com" CLIENTNAME: - "blogiclient" CLIENTSECRET: - "clientsecret" DOMAIN: - "example.com" REDIS: HOST: "127.0.0.1" PORT: 6379 Loading
docker-config.yaml +8 −3 Changes for docker-config.yaml: 8 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -20,6 +20,11 @@ BLOGI: DOMAIN: NAME: "%COOKIE%" AUTHDB: URL: "%CLIENTURL%" CLIENTNAME: "%CLIENTNAME%" CLIENTSECRET: "%CLIENTSECRET%" URL: - "%CLIENTURL%" CLIENTNAME: - "%CLIENTNAME%" CLIENTSECRET: - "%CLIENTSECRET%" DOMAIN: - "%AUTHDOMAIN%"
src/auth.cpp +53 −43 Changes for src/auth.cpp: 53 added lines, 43 removed lines. Original line number Diff line number Diff line Loading @@ -65,13 +65,14 @@ blogi::Auth::~Auth(){ } void blogi::Auth::login(const int tid,const char* username, const char* password,uuid::uuid &authid, const std::string &ssid){ void blogi::Auth::_doLogin(const AuthSource &src, const char *username, const char *password, uuid::uuid &authid, const int tid, const std::string *ssid){ libhttppp::HTTPException httpException; authdb::client::ClientConnection authcon; authcon.setUrl(_config.getAuthUrl()); authcon.setClientName(_config.getClientName()); authcon.setClientSecret(_config.getClientSecret()); authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authdb::client::Client clt(authcon); Loading @@ -93,17 +94,17 @@ void blogi::Auth::login(const int tid,const char* username, const char* password ret = clt.GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6"); if(ret){ if(ssid){ Session sess(*_dbconn[tid]); sess.addSessionData(ssid,"authid",authcon.getSessionID().c_str()); sess.addSessionData(*ssid,"authid",authcon.getSessionID().c_str()); class authdb::SessionData sdat; clt.SessionInfo(sdat); // Can throw AuthBackendError clt.SessionInfo(sdat); uuid::uuid uid; sdat.getUid(uid); sess.addSessionData(ssid,"uid",uid.c_str()); sess.addSessionData(*ssid,"uid",uid.c_str()); } authid = authcon.getSessionID(); } else { clt.remSession(); Loading @@ -115,62 +116,66 @@ void blogi::Auth::login(const int tid,const char* username, const char* password clt.remSession(); } catch (authdb::AuthBackendError &cleanupE) { } httpException[libhttppp::HTTPException::Error] << "Authentication backend error: " << e.what(); throw httpException; } } void blogi::Auth::Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid){ void blogi::Auth::login(const int tid,const char* username, const char* password,uuid::uuid &authid, const std::string &ssid, const std::string &domain){ libhttppp::HTTPException httpException; authdb::client::ClientConnection authcon; authcon.setUrl(_config.getAuthUrl()); authcon.setClientName(_config.getClientName()); authcon.setClientSecret(_config.getClientSecret()); authdb::client::Client clt(authcon); // Parse user@domain if no explicit domain provided std::string user(username); std::string dom = domain; if(dom.empty()){ auto atpos = user.rfind('@'); if(atpos != std::string::npos){ dom = user.substr(atpos + 1); user = user.substr(0, atpos); } } if(!clt.ClientAuth()){ httpException[libhttppp::HTTPException::Error] << "ClientAuth failed!"; const AuthSource *src = _config.findAuthSource(dom); if(!src){ httpException[libhttppp::HTTPException::Error] << "No auth source found for domain: " << dom; throw httpException; } authcon.setUsername(username); authcon.setUserPassword(password); bool ret = clt.UserAuth(); if(!ret) { httpException[libhttppp::HTTPException::Error] << "UserAuth failed (Invalid credentials)!"; throw httpException; _doLogin(*src, user.c_str(), password, authid, tid, &ssid); } try { ret = clt.GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6"); void blogi::Auth::Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid, const std::string &domain){ libhttppp::HTTPException httpException; if(ret){ authid = authcon.getSessionID(); } else { // GPO check failed, clean up the session clt.remSession(); httpException[libhttppp::HTTPException::Error] << "User GPO check failed!"; throw httpException; // Parse user@domain if no explicit domain provided std::string user(username); std::string dom = domain; if(dom.empty()){ auto atpos = user.rfind('@'); if(atpos != std::string::npos){ dom = user.substr(atpos + 1); user = user.substr(0, atpos); } } catch (authdb::AuthBackendError &e) { try { clt.remSession(); } catch (authdb::AuthBackendError &cleanupE) { } httpException[libhttppp::HTTPException::Error] << "Authentication backend error: " << e.what(); const AuthSource *src = _config.findAuthSource(dom); if(!src){ httpException[libhttppp::HTTPException::Error] << "No auth source found for domain: " << dom; throw httpException; } _doLogin(*src, user.c_str(), password, authid, tid, nullptr); } bool blogi::Auth::isLoggedIn(const int tid,const uuid::uuid &authid){ // Try all auth sources until one succeeds for(size_t i = 0; i < _config.getAuthSourceCount(); ++i){ const AuthSource &src = _config.getAuthSource(i); try { authdb::client::ClientConnection authcon; authcon.setUrl( _config.getAuthUrl()); authcon.setClientName(_config.getClientName()); authcon.setClientSecret(_config.getClientSecret()); authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authcon.setSessionID(authid); std::unique_ptr<authdb::client::Client> clt; Loading @@ -184,6 +189,11 @@ bool blogi::Auth::isLoggedIn(const int tid,const uuid::uuid &authid){ if(clt->ClientAuth() && clt->GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6")){ return true; } } catch(...) { // This source didn't work, try the next one continue; } } return false; } Loading
src/auth.h +4 −2 Changes for src/auth.h: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -45,11 +45,13 @@ namespace blogi { public: Auth(std::vector<std::unique_ptr<dbpp::Database>> &pcon,const blogi::Config &cfg); ~Auth(); void login(const int tid,const char *username,const char *password,uuid::uuid &authid,const std::string &ssid); void Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid); void login(const int tid,const char *username,const char *password,uuid::uuid &authid,const std::string &ssid,const std::string &domain=""); void Apilogin(const int tid,const char *username,const char *password,uuid::uuid &authid,const std::string &domain=""); bool isLoggedIn(const int tid,const uuid::uuid &authid); bool isLoggedIn(const int tid,libhttppp::HttpRequest &curreq,const std::string &ssid); private: void _doLogin(const AuthSource &src, const char *username, const char *password, uuid::uuid &authid, const int tid, const std::string *ssid); std::vector<std::unique_ptr<dbpp::Database>> &_dbconn; const blogi::Config &_config; Loading
src/blogi.cpp +1 −1 Changes for src/blogi.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -386,7 +386,7 @@ void blogi::Blogi::loginPage(libhttppp::HttpRequest &curreq,const int tid,const condat << "<div id=\"content\">" << "<span>" << blogi::tr(_lang,"Login") << "</span>" << "<form action=\""<< PlgArgs->config->buildurl("login") << "\" method=\"post\">" << blogi::tr(_lang,"username:") << "<br> <input type=\"text\" name=\"username\" value=\"\"><br>" << blogi::tr(_lang,"username:") << "<br> <input type=\"text\" name=\"username\" value=\"\" placeholder=\"user@domain\"><br>" << blogi::tr(_lang,"password:") << "<br> <input type=\"password\" name=\"password\" value=\"\"><br>" << "<button type=\"submit\">" << blogi::tr(_lang,"Submit") << "</button>" << "</form>" Loading