Skip to content

Commit b8bec5b

Browse files
Support memcached and redis encrypted password. (#1033)
* Support memcached and redis encrypted password. * Configure the Memcached client with the appropriate user and password for authentication * Set missing zone for Memcached. * Compatibility fix: Support encrypted and decrypted password at CloudServices.config for memcached and redis.
1 parent 2ee12bd commit b8bec5b

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

dotnet/src/dotnetframework/Providers/Cache/GxMemcached/GxMemcached.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.Linq;
44
using System.Security;
55
using System.Text.Json;
6-
using System.Text.Json.Serialization;
76
using Enyim.Caching;
87
using Enyim.Caching.Configuration;
98
using Enyim.Caching.Memcached;
9+
using GeneXus.Encryption;
1010
using GeneXus.Services;
1111
using GeneXus.Utils;
1212

@@ -26,21 +26,46 @@ public Memcached()
2626
MemcachedClient InitCache()
2727
{
2828
GXServices services = ServiceFactory.GetGXServices();
29-
String address = string.Empty;
29+
string address = string.Empty;
30+
string password = string.Empty;
31+
string username = string.Empty;
3032
if (services != null)
3133
{
3234
GXService providerService = ServiceFactory.GetGXServices()?.Get(GXServices.CACHE_SERVICE);
3335
if (providerService != null)
3436
{
3537
address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");
38+
username = providerService.Properties.Get("CACHE_PROVIDER_USER");
39+
password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD");
40+
if (!string.IsNullOrEmpty(password))
41+
{
42+
string ret = string.Empty;
43+
if (CryptoImpl.Decrypt(ref ret, password))
44+
{
45+
password = ret;
46+
}
47+
}
3648
}
3749
}
3850

3951
#if NETCORE
4052
var loggerFactory = new Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory();
41-
MemcachedClientConfiguration config = new MemcachedClientConfiguration(loggerFactory, new MemcachedClientOptions());
53+
MemcachedClientOptions options = new MemcachedClientOptions();
54+
if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password))
55+
{
56+
options.AddPlainTextAuthenticator(string.Empty, username, password);
57+
}
58+
MemcachedClientConfiguration config = new MemcachedClientConfiguration(loggerFactory, options);
4259
#else
60+
4361
MemcachedClientConfiguration config = new MemcachedClientConfiguration();
62+
if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password))
63+
{
64+
config.Authentication.Type = typeof(PlainTextAuthenticator);
65+
config.Authentication.Parameters["userName"] = username;
66+
config.Authentication.Parameters["password"] = password;
67+
config.Authentication.Parameters["zone"] = string.Empty;
68+
}
4469
#endif
4570
if (!String.IsNullOrEmpty(address))
4671
{

dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text.Json;
55
using System.Threading.Tasks;
6+
using GeneXus.Encryption;
67
using GeneXus.Services;
78
using GeneXus.Utils;
89
using StackExchange.Redis;
@@ -38,6 +39,14 @@ public Redis()
3839
string address, password;
3940
address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");
4041
password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD");
42+
if (!string.IsNullOrEmpty(password))
43+
{
44+
string ret = string.Empty;
45+
if (CryptoImpl.Decrypt(ref ret, password))
46+
{
47+
password = ret;
48+
}
49+
}
4150

4251
if (string.IsNullOrEmpty(address))
4352
address = String.Format("localhost:{0}", REDIS_DEFAULT_PORT);

0 commit comments

Comments
 (0)