mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-06-13 14:38:43 +00:00
auth
This commit is contained in:
@@ -32,6 +32,7 @@ public class AsyncException : Exception
|
||||
{
|
||||
public readonly ErrorType Type;
|
||||
public readonly ExceptionCode Code;
|
||||
//public readonly string Message;
|
||||
|
||||
public AsyncException(Exception exception) : base(exception.Message, exception)
|
||||
{
|
||||
@@ -42,7 +43,8 @@ public class AsyncException : Exception
|
||||
public override string StackTrace => InnerException != null && Type == ErrorType.Exception ? InnerException.StackTrace : base.StackTrace;
|
||||
|
||||
public AsyncException(ErrorType type, ushort code, string message)
|
||||
: base(type == ErrorType.Management ? ((ExceptionCode)code).ToString() : message)
|
||||
//: base(type == ErrorType.Management ? ((ExceptionCode)code).ToString() : message)
|
||||
: base(message)
|
||||
{
|
||||
this.Type = type;
|
||||
this.Code = (ExceptionCode)code;
|
||||
|
||||
@@ -99,11 +99,11 @@ public class EpAuthPacket : Packet
|
||||
set;
|
||||
}
|
||||
|
||||
public string Message
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
//public string Message
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
public byte[] SessionId
|
||||
{
|
||||
|
||||
@@ -714,6 +714,14 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
|
||||
if (_authPacket.AuthMode == AuthenticationMode.None)
|
||||
{
|
||||
if (!(Server?.AllowUnauthorizedAccess ?? false))
|
||||
{
|
||||
SendAuth(EpAuthPacketMethod.ErrorTerminate);
|
||||
_invalidCredentials = true;
|
||||
//Close();
|
||||
return offset;
|
||||
}
|
||||
|
||||
//@TODO: check if allowed, pass for testing
|
||||
SendAuthHeaders(EpAuthPacketMethod.SessionEstablished, localHeaders);
|
||||
AuthenticatonCompleted(null, "guest");
|
||||
@@ -772,7 +780,6 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
SendAuthHeaders(EpAuthPacketMethod.SessionEstablished, localHeaders);
|
||||
AuthenticatonCompleted(authResult.LocalIdentity, authResult.RemoteIdentity);
|
||||
}
|
||||
|
||||
}
|
||||
else if (_authPacket.Command == EpAuthPacketCommand.Acknowledge)
|
||||
{
|
||||
@@ -897,7 +904,9 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
|| _authPacket.Method == EpAuthPacketMethod.ErrorRetry)
|
||||
{
|
||||
_invalidCredentials = true;
|
||||
OnError?.Invoke(this, _authPacket.ErrorCode, _authPacket.Message ?? "Authentication error.");
|
||||
OnError?.Invoke(this, _authPacket.ErrorCode, "Authentication error.");
|
||||
_openReply?.TriggerError(new AsyncException(ErrorType.Management, _authPacket.ErrorCode, "Authentication error."));
|
||||
|
||||
Close();
|
||||
}
|
||||
else if (_authPacket.Method == EpAuthPacketMethod.IndicationEstablished)
|
||||
|
||||
@@ -53,6 +53,12 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public string[] AllowedAuthenticationProviders { get; set; }
|
||||
|
||||
[Attribute]
|
||||
public bool AllowUnauthorizedAccess { get; set; }
|
||||
|
||||
//IMembership membership;
|
||||
|
||||
//[Attribute]
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Security.Authority.Providers
|
||||
{
|
||||
internal class PasswordAuthenticationProvider : IAuthenticationProvider
|
||||
public class PasswordAuthenticationProvider : IAuthenticationProvider
|
||||
{
|
||||
public string DefaultName => "hash";
|
||||
|
||||
@@ -37,14 +37,14 @@ namespace Esiur.Security.Authority.Providers
|
||||
return null;
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Login(Session session)
|
||||
public virtual AsyncReply<bool> Login(Session session)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new AsyncReply<bool>(false);
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Logout(Session session)
|
||||
public virtual AsyncReply<bool> Logout(Session session)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new AsyncReply<bool>(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user