コード例 #1
0
        /// <summary>
        /// Override the ValidateRequest method to validate the custom element
        /// </summary>
        /// <param name="request">The security token request.</param>
        protected override void ValidateRequest(RequestSecurityToken request)
        {
            base.ValidateRequest(request);

            //
            // here we validate the custom element
            //
            string customElementValue            = null;
            CustomRequestSecurityToken customRST = request as CustomRequestSecurityToken;

            if (null != customRST)
            {
                customElementValue = customRST.CustomElement;
            }

            if (string.IsNullOrEmpty(customElementValue))
            {
                throw new InvalidRequestException("The custom element is missing");
            }

            if (customElementValue != CustomElementConstants.DefaultElementValue)
            {
                throw new InvalidRequestException(string.Format("The custom element's value is not expected. The value received is \'{0}\', but expected value is \'{1}\'.", customElementValue, CustomElementConstants.DefaultElementValue));
            }

            Console.WriteLine("The STS received the custom element. \n");
        }
コード例 #2
0
        /// <summary>
        /// Override ReadXml method to deserialize the custom element inside the RST.
        /// </summary>
        /// <param name="reader">The xml reader to read from</param>
        /// <param name="rst">The rst object that is going to be populated with the new custom element</param>
        /// <param name="serializer">The token serializer to serialize the token related elements</param>
        public override void ReadXmlElement(System.Xml.XmlReader reader, RequestSecurityToken rst, WSTrustSerializationContext context)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (rst == null)
            {
                throw new ArgumentNullException("rst");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (reader.IsStartElement(CustomElementConstants.LocalName, CustomElementConstants.Namespace))
            {
                if (rst is CustomRequestSecurityToken)
                {
                    CustomRequestSecurityToken customRST = rst as CustomRequestSecurityToken;
                    if (customRST != null)
                    {
                        //
                        // reading the custom element in the RST
                        //
                        customRST.CustomElement = reader.ReadElementContentAsString();
                    }
                }
            }
            else
            {
                //
                // The rest is just normal thing
                //
                base.ReadXmlElement(reader, rst, context);
            }
        }