/// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (AssetUrl != null)
         {
             hashCode = hashCode * 59 + AssetUrl.GetHashCode();
         }
         if (ClientApiUrl != null)
         {
             hashCode = hashCode * 59 + ClientApiUrl.GetHashCode();
         }
         if (ClientSessionId != null)
         {
             hashCode = hashCode * 59 + ClientSessionId.GetHashCode();
         }
         if (CustomerId != null)
         {
             hashCode = hashCode * 59 + CustomerId.GetHashCode();
         }
         if (InvalidTokens != null)
         {
             hashCode = hashCode * 59 + InvalidTokens.GetHashCode();
         }
         if (Region != null)
         {
             hashCode = hashCode * 59 + Region.GetHashCode();
         }
         return(hashCode);
     }
 }
        private IEnumerator <WaitCommand> RegisterPlayerInternal(
            ConnectionId connectionId,
            ApprovalSecret approvalSecret,
            Action <ApprovalSecret> approve,
            Action <ApprovalSecret> deny)
        {
            while (!_natFacilitatorConnection.ExternalEndpoint.IsResultAvailable)
            {
                yield return(WaitCommand.WaitForNextFrame);
            }

            var externalEndpoint = _natFacilitatorConnection.ExternalEndpoint.Result;

            var playerSessionResult = new AsyncResult <Maybe <PlayerSessionInfo> >();
            var clientSessionId     = new ClientSessionId(approvalSecret.Value);

            _masterServerClient.Client.GetPlayerInfo(externalEndpoint, clientSessionId,
                                                     (statusCode, p) => {
                if (statusCode == HttpStatusCode.OK)
                {
                    playerSessionResult.SetResult(Maybe.Just(p));
                }
                else
                {
                    playerSessionResult.SetResult(Maybe.Nothing <PlayerSessionInfo>());
                }
            });

            while (!playerSessionResult.IsResultAvailable)
            {
                yield return(WaitCommand.WaitForNextFrame);
            }

            var playerSessionInfo = playerSessionResult.Result;

            if (playerSessionInfo.IsJust && !_clientSessions.Values.Contains(clientSessionId))
            {
                var playerInfo = playerSessionInfo.Value.PlayerInfo;
                Debug.Log("'" + playerInfo.Name + "' connected");
                // TODO:
                // Store player info and use it to enhance the replicated pilot so
                // that players can see who's flying that pilot
                _connectedClients[connectionId] = playerInfo;
                _clientSessions[connectionId]   = clientSessionId;
                approve(approvalSecret);
            }
            else
            {
                Debug.Log("Player never registered at the master server, or player was already registered. Denying connection");
                deny(approvalSecret);
            }
        }
        /// <summary>
        /// Returns true if SessionResponse instances are equal
        /// </summary>
        /// <param name="other">Instance of SessionResponse to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(SessionResponse other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     AssetUrl == other.AssetUrl ||
                     AssetUrl != null &&
                     AssetUrl.Equals(other.AssetUrl)
                     ) &&
                 (
                     ClientApiUrl == other.ClientApiUrl ||
                     ClientApiUrl != null &&
                     ClientApiUrl.Equals(other.ClientApiUrl)
                 ) &&
                 (
                     ClientSessionId == other.ClientSessionId ||
                     ClientSessionId != null &&
                     ClientSessionId.Equals(other.ClientSessionId)
                 ) &&
                 (
                     CustomerId == other.CustomerId ||
                     CustomerId != null &&
                     CustomerId.Equals(other.CustomerId)
                 ) &&
                 (
                     InvalidTokens == other.InvalidTokens ||
                     InvalidTokens != null &&
                     InvalidTokens.SequenceEqual(other.InvalidTokens)
                 ) &&
                 (
                     Region == other.Region ||
                     Region != null &&
                     Region.Equals(other.Region)
                 ));
        }
Beispiel #4
0
        public bool Authorize(IDBOperation operation, bool isInitializeCall)
        {
            if (_nodeContext.StatusLatch.IsAnyBitsSet(NodeStatus.Initializing))
            {
                _nodeContext.StatusLatch.WaitForAny(NodeStatus.Running);
            }

            bool isInitialized = true;

            if (!isInitializeCall)
            //This portion is to verify if database is initialized or not, it has nothing to do with security (authorization or authentication)
            {
                ClientSessionId clientSessionId = operation.SessionId as ClientSessionId;
                if (!(initializedDatabases != null && initializedDatabases.ContainsKey(operation.Database) && (initializedDatabases[operation.Database].Contains(operation.SessionId) || (clientSessionId != null && initializedDatabases[operation.Database].Contains(clientSessionId.RouterSessionId)))))
                {
                    isInitialized = false;
                }
                //throw new DistributorException(ErrorCodes.Distributor.DATABASE_NOT_INITIALIZED, new[] {operation.Database});
            }
            //Authorization
            bool       isAuthorized = false;
            ISessionId sessionId    = operation.SessionId;
            Permission permission   = null;

            switch (operation.OperationType)
            {
            case DatabaseOperationType.Get:
            case DatabaseOperationType.GetChunk:
            case DatabaseOperationType.ReadQuery:
            case DatabaseOperationType.DisposeReader:
                permission = Permission.Read;
                break;

            case DatabaseOperationType.Insert:
            case DatabaseOperationType.Delete:
            case DatabaseOperationType.Replace:
            case DatabaseOperationType.Update:
            case DatabaseOperationType.WriteQuery:

                permission = Permission.Write;
                break;

            case DatabaseOperationType.Init:
                permission = Permission.Init;
                break;
            }

            //if(LoggerManager.Instance.SecurityLogger != null && LoggerManager.Instance.SecurityLogger.IsInfoEnabled)
            //{
            //    LoggerManager.Instance.SecurityLogger.Info("DataBaseEngine.Authorize", "Operation: " + operation.OperationType);
            //}

            if (permission != null)
            {
                ResourceId resourceId;
                ResourceId superResourceId;
                Security.Impl.SecurityManager.GetSecurityInformation(permission, operation.Database, out resourceId, out superResourceId, null);
                isAuthorized = SecurityManager.Authorize(_nodeContext.LocalShardName, sessionId, resourceId, superResourceId, permission);
                _nodeContext.TopologyImpl.IsOpertionAllow(operation.Database);
            }

            if (isAuthorized && !isInitialized)
            {
                this.InitializeDatabase(new InitDatabaseOperation()
                {
                    Database = operation.Database, SessionId = operation.SessionId
                });
            }

            return(isAuthorized);
        }