提交 99234927 编写于 作者: cdy816's avatar cdy816

更新接口安全信息

上级 8f110b08
......@@ -33,6 +33,11 @@ namespace Cdy.Tag
#region ... Properties ...
/// <summary>
///
/// </summary>
int TimeOut { get; }
#endregion ...Properties...
#region ... Methods ...
......
......@@ -70,6 +70,15 @@ namespace DBGrpcApi
}
}
/// <summary>
/// 超时时间
/// </summary>
public int TimeOut { get; set; }
/// <summary>
///
/// </summary>
public DateTime LoginTime { get; set; }
#endregion ...Properties...
......@@ -95,8 +104,6 @@ namespace DBGrpcApi
mSecurityClient = new Security.SecurityClient(grpcChannel);
}
catch (Exception ex)
{
......@@ -118,7 +125,10 @@ namespace DBGrpcApi
{
try
{
mLoginId = mSecurityClient.Login(new LoginRequest() { Name = username, Password = password }).Token;
var re = mSecurityClient.Login(new LoginRequest() { Name = username, Password = password });
TimeOut = re.Timeout;
LoginTime = DateTime.FromBinary(re.Time).ToLocalTime();
mLoginId = re.Token;
}
catch
{
......
......@@ -23,10 +23,13 @@ message LoginRequest {
// The response message containing the greetings.
message LoginReply {
string Token = 1;
int64 Time=2;
int32 Timeout=3;
}
message HartRequest {
string Token = 1;
int64 Time=2;
}
......
......@@ -23,10 +23,13 @@ message LoginRequest {
// The response message containing the greetings.
message LoginReply {
string Token = 1;
int64 Time=2;
int32 Timeout=3;
}
message HartRequest {
string Token = 1;
int64 Time=2;
}
......
......@@ -24,7 +24,7 @@ namespace DBGrpcApi
public override Task<LoginReply> Login(LoginRequest request, ServerCallContext context)
{
string Token = Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().Login(request.Name, request.Password);
return Task.FromResult(new LoginReply() { Token = Token });
return Task.FromResult(new LoginReply() { Token = Token, Time = DateTime.UtcNow.ToBinary(), Timeout = Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().TimeOut });
}
......@@ -49,6 +49,13 @@ namespace DBGrpcApi
/// <returns></returns>
public override Task<HartReply> Hart(HartRequest request, ServerCallContext context)
{
var dt = DateTime.FromBinary(request.Time);
if ((DateTime.UtcNow - dt).TotalSeconds > Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().TimeOut)
{
return Task.FromResult(new HartReply() { Result = false });
}
Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().FreshUserId(request.Token);
return Task.FromResult(new HartReply() { Result = true });
}
......
......@@ -16,9 +16,9 @@ namespace DbInRunWebApi.Controllers
[HttpPost("TryLogin")]
public LoginResponse Login([FromBody] LoginUser user)
{
string Token = Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().Login(user.UserName, user.Password);
//return null;
return new LoginResponse() { Token = Token,Result = !string.IsNullOrEmpty(Token), Time=DateTime.Now };
var service = Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>();
string Token = service.Login(user.UserName, user.Password);
return new LoginResponse() { Token = Token, Result = !string.IsNullOrEmpty(Token), LoginTime = DateTime.UtcNow.ToBinary(),TimeOut = service.TimeOut };
}
/// <summary>
......@@ -29,7 +29,17 @@ namespace DbInRunWebApi.Controllers
[HttpPost("Hart")]
public bool Hart([FromBody] Requestbase token)
{
// return true;
if (string.IsNullOrEmpty(token.Time))
{
return false;
}
long ltmp = long.Parse(token.Time);
if ((DateTime.UtcNow - DateTime.FromBinary(ltmp)).TotalSeconds > Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().TimeOut)
{
return false;
}
return Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().FreshUserId(token.Token);
}
......@@ -41,7 +51,6 @@ namespace DbInRunWebApi.Controllers
[HttpPost("Logout")]
public bool Logout([FromBody] Requestbase token)
{
//return true;
return Cdy.Tag.ServiceLocator.Locator.Resolve<Cdy.Tag.IRuntimeSecurity>().Logout(token.Token);
}
......
......@@ -53,10 +53,16 @@ namespace DbInRunWebApi.Model
#endregion ...Constructor...
#region ... Properties ...
/// <summary>
///
/// </summary>
public DateTime Time { get; set; }
public long LoginTime { get; set; }
/// <summary>
/// 超时时间
/// </summary>
public long TimeOut { get; set; }
/// <summary>
/// 结果
......@@ -101,6 +107,11 @@ namespace DbInRunWebApi.Model
/// </summary>
public string Token { get; set; }
/// <summary>
///
/// </summary>
public string Time { get; set; }
#endregion ...Properties...
#region ... Methods ...
......
......@@ -31,9 +31,10 @@ namespace Cdy.Tag
private Dictionary<long, DateTime> mLastLogin2 = new Dictionary<long, DateTime>();
private Dictionary<long, string> mUseIdMap2 = new Dictionary<long, string>();
public const int Timeout = 10;
public int mTimeout = 10;
private bool mIsClosed = false;
......@@ -67,9 +68,22 @@ namespace Cdy.Tag
}
}
/// <summary>
///
/// </summary>
public int TimeOut
{
get
{
return mTimeout;
}
}
#endregion ...Properties...
#region ... Methods ...
/// <summary>
///
/// </summary>
......@@ -86,7 +100,6 @@ namespace Cdy.Tag
public void Stop()
{
mIsClosed = true;
}
/// <summary>
......@@ -103,7 +116,7 @@ namespace Cdy.Tag
{
foreach (var vv in mLastLogin)
{
if ((dt - vv.Value).TotalMinutes >= Timeout)
if ((dt - vv.Value).TotalMinutes >= mTimeout)
{
ltmp.Add(vv.Key);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册