private IIdentity AuthenticateWithValidToken(IHttpRequestDescriptor request, Token currentToken) { var currentExpire = currentToken.Expire.ToUniversalTime(); Token token; if (IsProlongable(request)) { token = TokenService.Prolongate(currentToken); } else { token = currentToken; } var resultExpire = token.Expire.ToUniversalTime(); if (Logg.IsForDebug()) { Logg.Debug( new { request = request.Uri.ToString(), token = "upgrade", from = currentExpire, to = resultExpire } .stringify()); } var result = BuildIdentity(token); return(result); }
private void LogStart(string username, SecureLogonInfo info, IScope context, string opid) { if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, salt = info.Salt, sign = info.Sign, context }.stringify()); } }
private void LogStart(string username, string password, IScope context, string opid) { if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, pass = password.GetMd5(), context }.stringify()); } }
private IIdentity ResolveByExtensions(string username, string password, string opid, IScope context) { var extensions = Extensions.OfType <IPasswordLogon>().ToArray(); IIdentity bestresult = null; foreach (var passwordLogon in extensions) { if (Logg.IsForDebug()) { Logg.Debug(new { opid, ext = passwordLogon.GetType().Name, message = "enter" }.stringify()); } var subresult = passwordLogon.Logon(username, password, context); if (Logg.IsForDebug()) { Logg.Debug(new { opid, ext = passwordLogon.GetType().Name, message = null != subresult && subresult.IsAuthenticated }.stringify()); } if (null != subresult && UserActivityState.None != ((Identity)subresult).State) { bestresult = subresult; } if (null != subresult && subresult.IsAuthenticated) { return(subresult); } } return(bestresult); }
public string GetSalt(string username, IScope context = null) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentException("username"); } var opid = GETSALTOPID + Interlocked.Increment(ref logonid); if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, context }); } string result = null; var securelogon = Extensions.OfType <ISecureLogon>().FirstOrDefault(); if (null == securelogon) { if (Logg.IsForError()) { Logg.Error(new { opid, message = "not secure login confugured" }.stringify()); } } else { result = securelogon.GetSalt(username); } if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, salt = result }.stringify()); } return(result); }
public IIdentity Logon(string username, string password, IScope context = null) { if (null == UserService) { if (Logg.IsForDebug()) { Logg.Debug("No user service"); } return(null); } var user = UserService.GetUser(username); if (null == user && Logg.IsForDebug()) { Logg.Debug("user is null"); } if (!StateChecker.IsPasswordLogable(user)) { Logg.Debug("user not logable"); return(null); } var result = new Identity { Name = username, AuthenticationType = "hash" }; var state = StateChecker.GetActivityState(user); if (state != UserActivityState.Ok) { Logg.Debug("user is in invalid state " + state); result.State = state; result.IsError = true; result.Error = new SecurityException(state.ToStr()); } else { if (PasswordManager.MatchPassword(user, password)) { Logg.Debug("pass matched"); result.IsAuthenticated = true; result.IsAdmin = user.IsAdmin; result.User = user; } else { Logg.Debug("pass not matched"); result.IsError = true; result.Error = new SecurityException("invalid hash"); } } return(result); }
public IIdentity GetUserIdentity(IHttpRequestDescriptor request) { var currentToken = TokenService.Extract(request); if (Logg.IsForDebug()) { Logg.Debug(new { request = request.Uri.ToString(), action = "extract", token = currentToken }.stringify()); } if (currentToken != null && TokenService.IsValid(request, currentToken)) { return(AuthenticateWithValidToken(request, currentToken)); } var result = (Identity)DefaultIdentitySource.GetUserIdentity(request); result.DisabledToken = currentToken; return(result); }