Skip to content
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
4 changes: 1 addition & 3 deletions Enyim.Caching/EnyimMemcachedApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public static IApplicationBuilder UseEnyimMemcached(this IApplicationBuilder app
var logger = app.ApplicationServices.GetService<ILogger<IMemcachedClient>>();
try
{
var client = app.ApplicationServices.GetRequiredService<IMemcachedClient>();
client.GetValueAsync<string>("UseEnyimMemcached").Wait();
Console.WriteLine("EnyimMemcached connected memcached servers.");
var client = app.ApplicationServices.GetRequiredService<IMemcachedClient>();
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion Enyim.Caching/Memcached/IAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IAuthenticator
#region [ License information ]
/* ************************************************************
*
* Copyright (c) 2010 Attila Kisk�, enyim.com
* Copyright (c) 2010 Attila Kisk? enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 2 additions & 0 deletions Enyim.Caching/Memcached/MemcachedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ private async Task<PooledSocket> CreateSocketAsync()

return ps;
}

private PooledSocket CreateSocket()
{
var ps = this.ownerNode.CreateSocket();
Expand Down Expand Up @@ -767,6 +768,7 @@ protected internal virtual PooledSocket CreateSocket()
}

}

protected internal virtual async Task<PooledSocket> CreateSocketAsync()
{
try
Expand Down
43 changes: 42 additions & 1 deletion Enyim.Caching/Memcached/Protocol/Binary/BinaryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Enyim.Collections;
using System.Security;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;

namespace Enyim.Caching.Memcached.Protocol.Binary
{
Expand Down Expand Up @@ -36,7 +37,21 @@ protected internal override PooledSocket CreateSocket()
{
var retval = base.CreateSocket();

if (this.authenticationProvider != null && !this.Auth(retval))
if (this.authenticationProvider != null && !Auth(retval))
{
_logger.LogError("Authentication failed: " + this.EndPoint);

throw new SecurityException("auth failed: " + this.EndPoint);
}

return retval;
}

protected internal override async Task<PooledSocket> CreateSocketAsync()
{
var retval = await base.CreateSocketAsync();

if (this.authenticationProvider != null && !(await AuthAsync(retval)))
{
_logger.LogError("Authentication failed: " + this.EndPoint);

Expand Down Expand Up @@ -76,6 +91,32 @@ private bool Auth(PooledSocket socket)

return true;
}

private async Task<bool> AuthAsync(PooledSocket socket)
{
SaslStep currentStep = new SaslStart(this.authenticationProvider);

await socket.WriteAsync(currentStep.GetBuffer());

while (!(await currentStep.ReadResponseAsync(socket)).Success)
{
// challenge-response authentication
if (currentStep.StatusCode == 0x21)
{
currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data);
await socket.WriteAsync(currentStep.GetBuffer());
}
else
{
_logger.LogWarning("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode);

// invalid credentials or other error
return false;
}
}

return true;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Enyim.Caching/Memcached/Protocol/Binary/SaslContinue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override BinaryRequest Build()
#region [ License information ]
/* ************************************************************
*
* Copyright (c) 2010 Attila Kisk�, enyim.com
* Copyright (c) 2010 Attila Kisk? enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down