Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support memcached and redis encrypted password. #1033

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using System.Linq;
using System.Security;
using System.Text.Json;
using System.Text.Json.Serialization;
using Enyim.Caching;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached;
using GeneXus.Encryption;
using GeneXus.Services;
using GeneXus.Utils;

Expand All @@ -26,21 +26,46 @@ public Memcached()
MemcachedClient InitCache()
{
GXServices services = ServiceFactory.GetGXServices();
String address = string.Empty;
string address = string.Empty;
string password = string.Empty;
string username = string.Empty;
if (services != null)
{
GXService providerService = ServiceFactory.GetGXServices()?.Get(GXServices.CACHE_SERVICE);
if (providerService != null)
{
address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");
username = providerService.Properties.Get("CACHE_PROVIDER_USER");
password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD");
if (!string.IsNullOrEmpty(password))
{
string ret = string.Empty;
if (CryptoImpl.Decrypt(ref ret, password))
{
password = ret;
}
}
}
}

#if NETCORE
var loggerFactory = new Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory();
MemcachedClientConfiguration config = new MemcachedClientConfiguration(loggerFactory, new MemcachedClientOptions());
MemcachedClientOptions options = new MemcachedClientOptions();
if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password))
{
options.AddPlainTextAuthenticator(string.Empty, username, password);
}
MemcachedClientConfiguration config = new MemcachedClientConfiguration(loggerFactory, options);
#else

MemcachedClientConfiguration config = new MemcachedClientConfiguration();
if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password))
{
config.Authentication.Type = typeof(PlainTextAuthenticator);
config.Authentication.Parameters["userName"] = username;
config.Authentication.Parameters["password"] = password;
config.Authentication.Parameters["zone"] = string.Empty;
}
#endif
if (!String.IsNullOrEmpty(address))
{
Expand Down
9 changes: 9 additions & 0 deletions dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using GeneXus.Encryption;
using GeneXus.Services;
using GeneXus.Utils;
using StackExchange.Redis;
Expand Down Expand Up @@ -38,6 +39,14 @@ public Redis()
string address, password;
address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");
password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD");
if (!string.IsNullOrEmpty(password))
{
string ret = string.Empty;
if (CryptoImpl.Decrypt(ref ret, password))
{
password = ret;
}
}

if (string.IsNullOrEmpty(address))
address = String.Format("localhost:{0}", REDIS_DEFAULT_PORT);
Expand Down
Loading