Пример #1
0
        /// <summary>
        /// Create a new SASLProcessor, of the best type possible
        /// </summary>
        /// <param name="mechs">The mechanisms supported by the server</param>
        /// <param name="mt">The types the server implements</param>
        /// <param name="plaintextOK">Is it ok to select insecure types?</param>
        /// <param name="useClientCertificate">
        /// <c>true</c> if the connection have an associated local client certificate.
        /// </param>
        /// <param name="useAnonymous"></param>
        /// <returns></returns>
        public static SASLProcessor createProcessor(
            Mechanisms mechs,
            MechanismType mt,
            bool plaintextOK,
            bool useClientCertificate,
            bool useAnonymous)
        {
            if (useAnonymous && (mt & MechanismType.ANONYMOUS) == MechanismType.ANONYMOUS)
            {
                return(new AnonymousProcessor());
            }

            if (mt.HasAllFlags(MechanismType.EXTERNAL) && useClientCertificate)
            {
                return(new ExternalProcessor());
            }
            else if ((mt & MechanismType.GSSAPI) == MechanismType.GSSAPI)
            {
                string RemotePrincipal = "";
                foreach (Mechanism mechanism in mechs.GetMechanisms())
                {
                    if (mechanism.MechanismName == "GSSAPI")
                    {
                        RemotePrincipal = mechanism.GetAttribute("kerb:principal");
                        break;
                    }
                }
                return(new KerbProcessor(RemotePrincipal));
            }
            if ((mt & MechanismType.DIGEST_MD5) == MechanismType.DIGEST_MD5)
            {
                return(new MD5Processor());
            }
            else if (plaintextOK && ((mt & MechanismType.PLAIN) == MechanismType.PLAIN))
            {
                return(new PlainProcessor());
            }
            return(null);
        }