mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add option unsecure.allow_all_passwords to disable password restrictions and allow any type of passwords (even empty ones)
This commit is contained in:
parent
30ff0a84ef
commit
a567bd3780
@ -1,97 +1,97 @@
|
|||||||
#include "JsonCreateUser.h"
|
#include "JsonCreateUser.h"
|
||||||
|
|
||||||
#include "../model/email/Email.h"
|
#include "../model/email/Email.h"
|
||||||
#include "../controller/User.h"
|
#include "../controller/User.h"
|
||||||
#include "../controller/EmailVerificationCode.h"
|
#include "../controller/EmailVerificationCode.h"
|
||||||
|
|
||||||
#include "../SingletonManager/EmailManager.h"
|
#include "../SingletonManager/EmailManager.h"
|
||||||
#include "../SingletonManager/SessionManager.h"
|
#include "../SingletonManager/SessionManager.h"
|
||||||
|
|
||||||
#include "../tasks/AuthenticatedEncryptionCreateKeyTask.h"
|
#include "../tasks/AuthenticatedEncryptionCreateKeyTask.h"
|
||||||
|
|
||||||
Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params)
|
Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params)
|
||||||
{
|
{
|
||||||
std::string email;
|
std::string email;
|
||||||
std::string first_name;
|
std::string first_name;
|
||||||
std::string last_name;
|
std::string last_name;
|
||||||
std::string password;
|
std::string password;
|
||||||
int emailType;
|
int emailType;
|
||||||
auto em = EmailManager::getInstance();
|
auto em = EmailManager::getInstance();
|
||||||
auto sm = SessionManager::getInstance();
|
auto sm = SessionManager::getInstance();
|
||||||
|
|
||||||
// if is json object
|
// if is json object
|
||||||
if (params.type() == typeid(Poco::JSON::Object::Ptr)) {
|
if (params.type() == typeid(Poco::JSON::Object::Ptr)) {
|
||||||
Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>();
|
Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>();
|
||||||
/// Throws a RangeException if the value does not fit
|
/// Throws a RangeException if the value does not fit
|
||||||
/// into the result variable.
|
/// into the result variable.
|
||||||
/// Throws a NotImplementedException if conversion is
|
/// Throws a NotImplementedException if conversion is
|
||||||
/// not available for the given type.
|
/// not available for the given type.
|
||||||
/// Throws InvalidAccessException if Var is empty.
|
/// Throws InvalidAccessException if Var is empty.
|
||||||
try {
|
try {
|
||||||
paramJsonObject->get("email").convert(email);
|
paramJsonObject->get("email").convert(email);
|
||||||
paramJsonObject->get("first_name").convert(first_name);
|
paramJsonObject->get("first_name").convert(first_name);
|
||||||
paramJsonObject->get("last_name").convert(last_name);
|
paramJsonObject->get("last_name").convert(last_name);
|
||||||
paramJsonObject->get("emailType").convert(emailType);
|
paramJsonObject->get("emailType").convert(emailType);
|
||||||
if ((ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
|
if ((ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
|
||||||
paramJsonObject->get("password").convert(password);
|
paramJsonObject->get("password").convert(password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Poco::Exception& ex) {
|
catch (Poco::Exception& ex) {
|
||||||
return stateError("json exception", ex.displayText());
|
return stateError("json exception", ex.displayText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return stateError("parameter format unknown");
|
return stateError("parameter format unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto user = controller::User::create();
|
auto user = controller::User::create();
|
||||||
if (user->load(email) > 0) {
|
if (user->load(email) > 0) {
|
||||||
return customStateError("exist", "user already exist");
|
return customStateError("exist", "user already exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password.size()) {
|
if (password.size()) {
|
||||||
ErrorList errors;
|
ErrorList errors;
|
||||||
if (!sm->checkPwdValidation(password, &errors)) {
|
if (!(ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_ALLOW_ALL_PASSWORDS) && !sm->checkPwdValidation(password, &errors)) {
|
||||||
Poco::JSON::Object* result = new Poco::JSON::Object;
|
Poco::JSON::Object* result = new Poco::JSON::Object;
|
||||||
result->set("state", "error");
|
result->set("state", "error");
|
||||||
result->set("msg", errors.getLastError()->getString(false));
|
result->set("msg", errors.getLastError()->getString(false));
|
||||||
if (errors.errorCount()) {
|
if (errors.errorCount()) {
|
||||||
result->set("details", errors.getLastError()->getString(false));
|
result->set("details", errors.getLastError()->getString(false));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create user
|
// create user
|
||||||
user = controller::User::create(email, first_name, last_name);
|
user = controller::User::create(email, first_name, last_name);
|
||||||
auto userModel = user->getModel();
|
auto userModel = user->getModel();
|
||||||
Session* session = nullptr;
|
Session* session = nullptr;
|
||||||
|
|
||||||
if (!userModel->insertIntoDB(true)) {
|
if (!userModel->insertIntoDB(true)) {
|
||||||
userModel->sendErrorsAsEmail();
|
userModel->sendErrorsAsEmail();
|
||||||
return stateError("insert user failed");
|
return stateError("insert user failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password.size()) {
|
if (password.size()) {
|
||||||
session = sm->getNewSession();
|
session = sm->getNewSession();
|
||||||
session->setUser(user);
|
session->setUser(user);
|
||||||
session->generateKeys(true, true);
|
session->generateKeys(true, true);
|
||||||
session->setClientIp(mClientIP);
|
session->setClientIp(mClientIP);
|
||||||
|
|
||||||
// calculate encryption key, could need some time, will save encrypted privkey to db
|
// calculate encryption key, could need some time, will save encrypted privkey to db
|
||||||
UniLib::controller::TaskPtr create_authenticated_encrypten_key = new AuthenticatedEncryptionCreateKeyTask(user, password);
|
UniLib::controller::TaskPtr create_authenticated_encrypten_key = new AuthenticatedEncryptionCreateKeyTask(user, password);
|
||||||
create_authenticated_encrypten_key->scheduleTask(create_authenticated_encrypten_key);
|
create_authenticated_encrypten_key->scheduleTask(create_authenticated_encrypten_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto emailOptIn = controller::EmailVerificationCode::create(userModel->getID(), model::table::EMAIL_OPT_IN_REGISTER);
|
auto emailOptIn = controller::EmailVerificationCode::create(userModel->getID(), model::table::EMAIL_OPT_IN_REGISTER);
|
||||||
auto emailOptInModel = emailOptIn->getModel();
|
auto emailOptInModel = emailOptIn->getModel();
|
||||||
if (!emailOptInModel->insertIntoDB(false)) {
|
if (!emailOptInModel->insertIntoDB(false)) {
|
||||||
emailOptInModel->sendErrorsAsEmail();
|
emailOptInModel->sendErrorsAsEmail();
|
||||||
return stateError("insert emailOptIn failed");
|
return stateError("insert emailOptIn failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType)));
|
em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType)));
|
||||||
|
|
||||||
return stateSuccess();
|
return stateSuccess();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -37,6 +37,10 @@ void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Po
|
|||||||
if (parsedResult.size() != 0) {
|
if (parsedResult.size() != 0) {
|
||||||
json_result = handle(parsedResult);
|
json_result = handle(parsedResult);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
json_result = stateError("empty body");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(method == "GET") {
|
else if(method == "GET") {
|
||||||
Poco::URI uri(request.getURI());
|
Poco::URI uri(request.getURI());
|
||||||
|
|||||||
@ -246,6 +246,9 @@ namespace ServerConfig {
|
|||||||
if (cfg.getInt("unsecure.allow_cors_all", 0) == 1) {
|
if (cfg.getInt("unsecure.allow_cors_all", 0) == 1) {
|
||||||
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_CORS_ALL);
|
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_CORS_ALL);
|
||||||
}
|
}
|
||||||
|
if (cfg.getInt("unsecure.allow_all_passwords", 0) == 1) {
|
||||||
|
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_ALLOW_ALL_PASSWORDS);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,7 +44,8 @@ namespace ServerConfig {
|
|||||||
NOT_UNSECURE = 0,
|
NOT_UNSECURE = 0,
|
||||||
UNSECURE_PASSWORD_REQUESTS = 1,
|
UNSECURE_PASSWORD_REQUESTS = 1,
|
||||||
UNSECURE_AUTO_SIGN_TRANSACTIONS = 2,
|
UNSECURE_AUTO_SIGN_TRANSACTIONS = 2,
|
||||||
UNSECURE_CORS_ALL = 4
|
UNSECURE_CORS_ALL = 4,
|
||||||
|
UNSECURE_ALLOW_ALL_PASSWORDS = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user