/// <summary>
        /// Specifies the security context used for all invocations made in the current thread.
        /// </summary>
        /// <param name="securitySessionParameters">Security Session parameters.</param>
        /// <returns>The name of the previous security context or null.</returns>
        public static SecuritySessionParameters SetCurrentSecurityContext(SecuritySessionParameters securitySessionParameters)
        {
            LocalDataStoreSlot localDataStoreSlot = Thread.GetNamedDataSlot(OccupiedThreadSlots.CurrentSecuritySessionParameters);

            object previousDataSlotValue = Thread.GetData(localDataStoreSlot);

            Thread.SetData(localDataStoreSlot, securitySessionParameters);

            return(previousDataSlotValue as SecuritySessionParameters);
        }
        /// <summary>
        /// Initiates establishing Security Session with specific remote host via specified IConnectionManager.
        /// </summary>
        /// <param name="securitySessionParameters">Security Session parameters.</param>
        public void InitiateEstablishingSecuritySession(SecuritySessionParameters securitySessionParameters)
        {
            BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;

            if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0)
            {
                binaryLogWriter.WriteEvent(LogCategory.Security, "SecuritySession.InitiateEstablishingSecuritySession",
                                           LogMessageType.SecuritySessionInitiated, null, null, this.Remote, null,
                                           GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, this,
                                           this.Name, -1, 0, 0, 0, this.GetType().Name, this.Name, null, null,
                                           "Security Session establishing is initiated.");
            }

            this.Failed.Reset();
            this._establishingSecuritySessionParameters = securitySessionParameters;
            GenuineThreadPool.QueueUserWorkItem(new WaitCallback(this.Internal_InitiateEstablishingSecuritySession), securitySessionParameters, false);
        }
Beispiel #3
0
 private void CheckState()
 {
     try
     {
         SecuritySessionParameters parameters = new SecuritySessionParameters(
             SecuritySessionServices.DefaultContext.Name,
             SecuritySessionAttributes.None, TimeSpan.FromSeconds(5));
         using (new SecurityContextKeeper(parameters))
         {
             while (true)
             {
                 try
                 {
                     if (ClientEnvironment.ServerStateService.CanInteract)
                     {
                         if (ClientEnvironment.ServerStateService.ServerReady)
                             SetState(ServerState.Ready);
                         else
                             SetState(ServerState.Starting);
                     }
                     else
                         SetState(ServerState.Starting);
                 }
                 catch (ThreadAbortException)
                 {
                     return;
                 }
                 catch(Exception ex)
                 {
                     SetState(ServerState.Unavailable);
                 }
                 if (_FinishChecking.WaitOne(1000, false))
                     return;
             }
         }
     }
     catch (ThreadAbortException)
     {
     }
 }
 /// <summary>
 /// Forces the specified security context to be used in all calls in
 /// the current thread until Dispose method is called.
 /// </summary>
 /// <param name="securitySessionParameters">Security Session parameters.</param>
 public SecurityContextKeeper(SecuritySessionParameters securitySessionParameters)
 {
     this._previousSecuritySessionParameters = SecuritySessionServices.SetCurrentSecurityContext(securitySessionParameters);
 }
Beispiel #5
0
 /// <summary>
 /// Forces the specified security context to be used in all calls in
 /// the current thread until Dispose method is called.
 /// </summary>
 /// <param name="securitySessionParameters">Security Session parameters.</param>
 public SecurityContextKeeper(SecuritySessionParameters securitySessionParameters)
 {
     this._previousSecuritySessionParameters = SecuritySessionServices.SetCurrentSecurityContext(securitySessionParameters);
 }
        /// <summary>
        /// Constructs the response to the specified message.
        /// </summary>
        /// <param name="sourceMessage">The source message.</param>
        /// <param name="iTransportHeaders">The transport headers.</param>
        /// <param name="stream">The message content.</param>
        public Message(Message sourceMessage, ITransportHeaders iTransportHeaders, Stream stream)
        {
            this.ITransportContext = sourceMessage.ITransportContext;
            this.ITransportHeaders = iTransportHeaders;
            //			this.Sender = sourceMessage.Recipient;
            this.Recipient = sourceMessage.Sender;
            this.ReplyToId = sourceMessage.MessageId;
            this.GenuineMessageType = sourceMessage.GenuineMessageType;
            this.Stream = stream;
            this.ConnectionName = sourceMessage.ConnectionName;
            this.SecuritySessionParameters = this.ITransportContext.FixSecuritySessionParameters(sourceMessage.SecuritySessionParameters);
            this.IsSynchronous = (this.SecuritySessionParameters.Attributes & SecuritySessionAttributes.ForceSync) != 0 ||
                ((bool) this.ITransportContext.IParameterProvider[GenuineParameter.SyncResponses] && (this.SecuritySessionParameters.Attributes & SecuritySessionAttributes.ForceAsync) == 0);

            if (this.ITransportHeaders != null)
                this.ITransportHeaders[TransportHeadersSenderEntryName] = this.Sender;

            this.MessageId = Interlocked.Increment(ref _currentMessageId);

            #if TRIAL
            if (this.MessageId > 3010)
                throw GenuineExceptions.Get_Channel_TrialConditionExceeded("The maximum number of messages restriction has been exceeded. You can not send more than 3000 messages using TRIAL version.");
            #endif
        }
        /// <summary>
        /// Returns an instance of the SecuritySessionParameters class brought to conformity with channels' settings.
        /// </summary>
        /// <param name="securitySessionParameters">Source parameters.</param>
        /// <returns>Fixed parameters.</returns>
        public SecuritySessionParameters FixSecuritySessionParameters(SecuritySessionParameters securitySessionParameters)
        {
            SecuritySessionAttributes fixedAttributes = (SecuritySessionAttributes) (
                ((int) securitySessionParameters.Attributes | (int) this.ForcedSecuritySessionAttributes)  &
                ~( (int) this.ProhibitedSecuritySessionAttributes) );

            return new SecuritySessionParameters(securitySessionParameters.Name, fixedAttributes, TimeSpan.MinValue, securitySessionParameters.GenuineConnectionType, securitySessionParameters.ConnectionName, TimeSpan.MinValue, securitySessionParameters.RemoteTransportUser);
        }
 /// <summary>
 /// Puts down Security Session Parameters.
 /// </summary>
 /// <param name="parameters">The Security Session Parameters.</param>
 private void WriteSecuritySessionParameters(SecuritySessionParameters parameters)
 {
     this.BinaryWriter.Write( (bool) (parameters != null));
     if (parameters != null)
     {
         this.WriteString( parameters.Name);
         this.BinaryWriter.Write( (int) parameters.GenuineConnectionType);
         this.WriteString( parameters.ConnectionName);
         this.BinaryWriter.Write( (long) parameters.Timeout.Ticks);
         this.BinaryWriter.Write( (int) parameters.Attributes );
         this.BinaryWriter.Write( (long) parameters.CloseAfterInactivity.Ticks );
     }
 }
        /// <summary>
        /// Puts down a record representing an event connected with the specified Security Session Parameters.
        /// </summary>
        /// <param name="author">The author.</param>
        /// <param name="type">The type of the event(Subcategory).</param>
        /// <param name="exception">The exception associated with the event.</param>
        /// <param name="message">The message associated with the event.</param>
        /// <param name="remote">The remote host participating in the event.</param>
        /// <param name="sourceThreadId">The id of the thread where the invocation was made.</param>
        /// <param name="sourceThreadName">The name of the thread.</param>
        /// <param name="securitySessionParameters">The Security Session Parameters.</param>
        /// <param name="description">The description of the event.</param>
        /// <param name="parameters">Parameters to the description.</param>
        public void WriteSecuritySessionParametersEvent(string author, LogMessageType type, Exception exception, 
            Message message, HostInformation remote, int sourceThreadId, string sourceThreadName,
            SecuritySessionParameters securitySessionParameters, string description, params object[] parameters)
        {
            if (message == null || securitySessionParameters == null)
            {
                this.WriteImplementationWarningEvent("BinaryLogWriter.WriteMessageCreatedEvent", LogMessageType.Error, null,
                    sourceThreadId, sourceThreadName, "The message or SSP is not provided. Stack trace: " + Environment.StackTrace);
                return ;
            }

            lock (this._streamLock)
            {
                this.WriteRecordHeader(BinaryRecordVersion.SecuritySessionParameters, LogCategory.Security, type, author);
                this.WriteException( exception );

                this.WriteMessageSeqNo(message);
                this.WriteHostInformationId(remote);

                this.BinaryWriter.Write( (int) sourceThreadId);
                this.WriteString( sourceThreadName );

                this.WriteSecuritySessionParameters( securitySessionParameters );
                this.WriteStringWithParameters( description, parameters);

                this.BinaryWriter.Flush();
            }
        }
        /// <summary>
        /// Initiates establishing Security Session with specific remote host via specified IConnectionManager.
        /// </summary>
        /// <param name="securitySessionParameters">Security Session parameters.</param>
        public void InitiateEstablishingSecuritySession(SecuritySessionParameters securitySessionParameters)
        {
            BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;
            if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0 )
                binaryLogWriter.WriteEvent(LogCategory.Security, "SecuritySession.InitiateEstablishingSecuritySession",
                    LogMessageType.SecuritySessionInitiated, null, null, this.Remote, null,
                    GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, this,
                    this.Name, -1, 0, 0, 0, this.GetType().Name, this.Name, null, null,
                    "Security Session establishing is initiated.");

            this.Failed.Reset();
            this._establishingSecuritySessionParameters = securitySessionParameters;
            GenuineThreadPool.QueueUserWorkItem(new WaitCallback(this.Internal_InitiateEstablishingSecuritySession), securitySessionParameters, false);
        }
        /// <summary>
        /// Specifies the security context used for all invocations made in the current thread.
        /// </summary>
        /// <param name="securitySessionParameters">Security Session parameters.</param>
        /// <returns>The name of the previous security context or null.</returns>
        public static SecuritySessionParameters SetCurrentSecurityContext(SecuritySessionParameters securitySessionParameters)
        {
            LocalDataStoreSlot localDataStoreSlot = Thread.GetNamedDataSlot(OccupiedThreadSlots.CurrentSecuritySessionParameters);

            object previousDataSlotValue = Thread.GetData(localDataStoreSlot);
            Thread.SetData(localDataStoreSlot, securitySessionParameters);

            return previousDataSlotValue as SecuritySessionParameters;
        }