private void VerifySession(string userID, string sessionID) { if (!_cache.VerifySession(userID?.ToLower(), sessionID)) { throw new WebApiException(401, "Invalid session."); } }
protected override AuthenticationResult OnAuthenticationRequest(ISIPExtension extension, RequestAuthenticationInfo authInfo) { Console.WriteLine("Authentication request received from: " + authInfo.From.UserName); var success = _sessionCache.VerifySession(authInfo.From.UserName, authInfo.AuthName); if (success) { Console.WriteLine("Authentication accepted. UserName: "******"Authentication denied. UserName: " + extension.ExtensionID); } return(new AuthenticationResult(success)); }
public bool Verify(Connection con) { if (con == null || con.SessionID.IsNullOrWhitespace() || con.ConnectionID.IsNullOrWhitespace() || con.UserID.IsNullOrWhitespace()) { return(false); } lock (_connections) { _connections.RemoveAll(c => c.SessionID.ToLower() == con.SessionID.ToLower() || c.ConnectionID.ToLower() == con.ConnectionID.ToLower() || c.UserID.ToLower() == con.UserID.ToLower()); if (!_sessions.VerifySession(con.UserID.ToLower(), con.SessionID.ToLower())) { return(false); } _connections.Add(con); return(true); } }