Example #1
0
        public IMessageProperty CreateCopy()
        {
            ThrowIfDisposed();
            SecurityMessageProperty result = new SecurityMessageProperty();

            if (HasOutgoingSupportingTokens)
            {
                for (int i = 0; i < outgoingSupportingTokens.Count; ++i)
                {
                    result.OutgoingSupportingTokens.Add(outgoingSupportingTokens[i]);
                }
            }

            if (HasIncomingSupportingTokens)
            {
                for (int i = 0; i < incomingSupportingTokens.Count; ++i)
                {
                    result.IncomingSupportingTokens.Add(incomingSupportingTokens[i]);
                }
            }

            result.securityContext = securityContext;
            result.externalAuthorizationPolicies = externalAuthorizationPolicies;
            result.senderIdPrefix = senderIdPrefix;

            result.protectionToken = protectionToken;
            result.initiatorToken  = initiatorToken;
            result.recipientToken  = recipientToken;
            result.transportToken  = transportToken;

            return(result);
        }
Example #2
0
        //public string SenderIdPrefix
        //{
        //    get
        //    {
        //        return this.senderIdPrefix;
        //    }
        //    set
        //    {
        //        XmlHelper.ValidateIdPrefix(value);
        //        this.senderIdPrefix = value;
        //    }
        //}

        //public bool HasIncomingSupportingTokens
        //{
        //    get
        //    {
        //        ThrowIfDisposed();
        //        return ((this.incomingSupportingTokens != null) && (this.incomingSupportingTokens.Count > 0));
        //    }
        //}

        //public Collection<SupportingTokenSpecification> IncomingSupportingTokens
        //{
        //    get
        //    {
        //        ThrowIfDisposed();
        //        if (this.incomingSupportingTokens == null)
        //        {
        //            this.incomingSupportingTokens = new Collection<SupportingTokenSpecification>();
        //        }
        //        return this.incomingSupportingTokens;
        //    }
        //}

        //public Collection<SupportingTokenSpecification> OutgoingSupportingTokens
        //{
        //    get
        //    {
        //        if (this.outgoingSupportingTokens == null)
        //        {
        //            this.outgoingSupportingTokens = new Collection<SupportingTokenSpecification>();
        //        }
        //        return this.outgoingSupportingTokens;
        //    }
        //}

        //internal bool HasOutgoingSupportingTokens
        //{
        //    get
        //    {
        //        return ((this.outgoingSupportingTokens != null) && (this.outgoingSupportingTokens.Count > 0));
        //    }
        //}

        public IMessageProperty CreateCopy()
        {
            ThrowIfDisposed();
            SecurityMessageProperty result = new SecurityMessageProperty();

            //    if (this.HasOutgoingSupportingTokens)
            //    {
            //        for (int i = 0; i < this.outgoingSupportingTokens.Count; ++i)
            //        {
            //            result.OutgoingSupportingTokens.Add(this.outgoingSupportingTokens[i]);
            //        }
            //    }

            //    if (this.HasIncomingSupportingTokens)
            //    {
            //        for (int i = 0; i < this.incomingSupportingTokens.Count; ++i)
            //        {
            //            result.IncomingSupportingTokens.Add(this.incomingSupportingTokens[i]);
            //        }
            //    }

            result.securityContext = securityContext;
            //    result.externalAuthorizationPolicies = this.externalAuthorizationPolicies;
            //    result.senderIdPrefix = this.senderIdPrefix;

            //    result.protectionToken = this.protectionToken;
            //    result.initiatorToken = this.initiatorToken;
            //    result.recipientToken = this.recipientToken;
            result.transportToken = transportToken;

            return(result);
        }
        public IMessageProperty CreateCopy()
        {
            ThrowIfDisposed();
            SecurityMessageProperty result = new SecurityMessageProperty();

            if (HasOutgoingSupportingTokens)
            {
                for (int i = 0; i < _outgoingSupportingTokens.Count; ++i)
                {
                    result.OutgoingSupportingTokens.Add(_outgoingSupportingTokens[i]);
                }
            }

            if (HasIncomingSupportingTokens)
            {
                for (int i = 0; i < _incomingSupportingTokens.Count; ++i)
                {
                    result.IncomingSupportingTokens.Add(_incomingSupportingTokens[i]);
                }
            }

            result._securityContext = _securityContext;
            result.ExternalAuthorizationPolicies = ExternalAuthorizationPolicies;
            result.SenderIdPrefix = SenderIdPrefix;

            result._protectionToken = _protectionToken;
            result._initiatorToken  = _initiatorToken;
            result._recipientToken  = _recipientToken;
            result._transportToken  = _transportToken;

            return(result);
        }
Example #4
0
 protected void AddSupportingTokenSpecification(SecurityMessageProperty security, IList <SecurityToken> basicTokens, IList <SecurityToken> endorsingTokens, IList <SecurityToken> signedEndorsingTokens, IList <SecurityToken> signedTokens, IDictionary <SecurityToken, ReadOnlyCollection <IAuthorizationPolicy> > tokenPoliciesMapping)
 {
     AddSupportingTokenSpecification(security, basicTokens, SecurityTokenAttachmentMode.SignedEncrypted, tokenPoliciesMapping);
     AddSupportingTokenSpecification(security, endorsingTokens, SecurityTokenAttachmentMode.Endorsing, tokenPoliciesMapping);
     AddSupportingTokenSpecification(security, signedEndorsingTokens, SecurityTokenAttachmentMode.SignedEndorsing, tokenPoliciesMapping);
     AddSupportingTokenSpecification(security, signedTokens, SecurityTokenAttachmentMode.Signed, tokenPoliciesMapping);
 }
Example #5
0
        protected void AttachRecipientSecurityProperty(Message message, IList <SecurityToken> basicTokens, IList <SecurityToken> endorsingTokens,
                                                       IList <SecurityToken> signedEndorsingTokens, IList <SecurityToken> signedTokens, Dictionary <SecurityToken, ReadOnlyCollection <IAuthorizationPolicy> > tokenPoliciesMapping)
        {
            SecurityMessageProperty security = SecurityMessageProperty.GetOrCreate(message);

            AddSupportingTokenSpecification(security, basicTokens, endorsingTokens, signedEndorsingTokens, signedTokens, tokenPoliciesMapping);
            security.ServiceSecurityContext = new ServiceSecurityContext(security.GetInitiatorTokenAuthorizationPolicies());
        }
Example #6
0
        //public virtual async Task OnCloseAsync(CancellationToken token)
        //{
        //    if (SecurityProtocolFactory.ActAsInitiator)
        //    {
        //        /*
        //        TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
        //        foreach (SupportingTokenProviderSpecification spec in ChannelSupportingTokenProviderSpecification)
        //        {
        //            await SecurityUtils.CloseTokenProviderIfRequiredAsync(spec.TokenProvider, timeoutHelper.RemainingTime());
        //        }

        //        foreach (string action in ScopedSupportingTokenProviderSpecification.Keys)
        //        {
        //            ICollection<SupportingTokenProviderSpecification> supportingProviders = ScopedSupportingTokenProviderSpecification[action];
        //            foreach (SupportingTokenProviderSpecification spec in supportingProviders)
        //            {
        //                await SecurityUtils.CloseTokenProviderIfRequiredAsync(spec.TokenProvider, timeoutHelper.RemainingTime());
        //            }
        //        }*/
        //    }
        //}

        private static void SetSecurityHeaderId(SendSecurityHeader securityHeader, Message message)
        {
            SecurityMessageProperty messageProperty = message.Properties.Security;

            if (messageProperty != null)
            {
                securityHeader.IdPrefix = messageProperty.SenderIdPrefix;
            }
        }
Example #7
0
        private void AddSupportingTokenSpecification(SecurityMessageProperty security, IList <SecurityToken> tokens, SecurityTokenAttachmentMode attachmentMode, IDictionary <SecurityToken, ReadOnlyCollection <IAuthorizationPolicy> > tokenPoliciesMapping)
        {
            if (tokens == null || tokens.Count == 0)
            {
                return;
            }

            for (int i = 0; i < tokens.Count; ++i)
            {
                security.IncomingSupportingTokens.Add(new SupportingTokenSpecification(tokens[i], tokenPoliciesMapping[tokens[i]], attachmentMode));
            }
        }
Example #8
0
        public static SecurityMessageProperty GetOrCreate(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
            }

            SecurityMessageProperty result = null;

            if (message.Properties != null)
            {
                result = message.Properties.Security;
            }

            if (result == null)
            {
                result = new SecurityMessageProperty();
                message.Properties.Security = result;
            }

            return(result);
        }
Example #9
0
        internal void AddMessageSupportingTokens(Message message, ref IList <SupportingTokenSpecification> supportingTokens)
        {
            SecurityMessageProperty supportingTokensProperty = message.Properties.Security;

            if (supportingTokensProperty != null && supportingTokensProperty.HasOutgoingSupportingTokens)
            {
                if (supportingTokens == null)
                {
                    supportingTokens = new Collection <SupportingTokenSpecification>();
                }

                for (int i = 0; i < supportingTokensProperty.OutgoingSupportingTokens.Count; ++i)
                {
                    SupportingTokenSpecification spec = supportingTokensProperty.OutgoingSupportingTokens[i];
                    if (spec.SecurityTokenParameters == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.SenderSideSupportingTokensMustSpecifySecurityTokenParameters));
                    }
                    supportingTokens.Add(spec);
                }
            }
        }