using System.ServiceModel.Channels;
using System.Xml;

namespace BeWo.Security
{
    // TODO: Make it namespace-conform (type Attributes, prefixes, etc)
    // ns: 
    public class SecurityHeader : MessageHeader
    {
        private string mPassword;

        private string mUsername;

        public override bool MustUnderstand
        {
            get
            {
                return false;
            }
        }

        public override string Name
        {
            get
            {
                return "Security";
            }
        }

        public override string Namespace
        {
            get
            {
                return "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
            }
        }

        public string Password
        {
            get
            {
                return this.mPassword;
            }

            set
            {
                this.mPassword = value;
            }
        }

        public string Username
        {
            get
            {
                return this.mUsername;
            }

            set
            {
                this.mUsername = value;
            }
        }

        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
        {
            writer.WriteStartElement("UsernameToken");
            writer.WriteElementString("Username", this.mUsername);
            writer.WriteStartElement("Password");
            writer.WriteAttributeString("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
            writer.WriteValue(this.mPassword);
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
    }
}