public virtual void Setup()
        {
            // create keytab
            FilePath keytabFile      = new FilePath(KerberosTestUtils.GetKeytabFile());
            string   clientPrincipal = KerberosTestUtils.GetClientPrincipal();
            string   serverPrincipal = KerberosTestUtils.GetServerPrincipal();

            clientPrincipal = Runtime.Substring(clientPrincipal, 0, clientPrincipal.LastIndexOf
                                                    ("@"));
            serverPrincipal = Runtime.Substring(serverPrincipal, 0, serverPrincipal.LastIndexOf
                                                    ("@"));
            GetKdc().CreatePrincipal(keytabFile, clientPrincipal, serverPrincipal);
            // handler
            handler = GetNewAuthenticationHandler();
            Properties props = GetDefaultProperties();

            try
            {
                handler.Init(props);
            }
            catch (Exception ex)
            {
                handler = null;
                throw;
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestNameRules()
        {
            KerberosName kn = new KerberosName(KerberosTestUtils.GetServerPrincipal());

            Assert.Equal(KerberosTestUtils.GetRealm(), kn.GetRealm());
            //destroy handler created in setUp()
            handler.Destroy();
            KerberosName.SetRules("RULE:[1:$1@$0](.*@FOO)s/@.*//\nDEFAULT");
            handler = GetNewAuthenticationHandler();
            Properties props = GetDefaultProperties();

            props.SetProperty(KerberosAuthenticationHandler.NameRules, "RULE:[1:$1@$0](.*@BAR)s/@.*//\nDEFAULT"
                              );
            try
            {
                handler.Init(props);
            }
            catch (Exception)
            {
            }
            kn = new KerberosName("bar@BAR");
            Assert.Equal("bar", kn.GetShortName());
            kn = new KerberosName("bar@FOO");
            try
            {
                kn.GetShortName();
                NUnit.Framework.Assert.Fail();
            }
            catch (Exception)
            {
            }
        }
            /// <exception cref="System.Exception"/>
            public string Call()
            {
                GSSManager gssManager = GSSManager.GetInstance();
                GSSContext gssContext = null;

                try
                {
                    string  servicePrincipal = KerberosTestUtils.GetServerPrincipal();
                    Oid     oid         = KerberosUtil.GetOidInstance("NT_GSS_KRB5_PRINCIPAL");
                    GSSName serviceName = gssManager.CreateName(servicePrincipal, oid);
                    oid        = KerberosUtil.GetOidInstance("GSS_KRB5_MECH_OID");
                    gssContext = gssManager.CreateContext(serviceName, oid, null, GSSContext.
                                                          DefaultLifetime);
                    gssContext.RequestCredDeleg(true);
                    gssContext.RequestMutualAuth(true);
                    byte[] inToken  = new byte[0];
                    byte[] outToken = gssContext.InitSecContext(inToken, 0, inToken.Length);
                    Base64 base64   = new Base64(0);
                    return(base64.EncodeToString(outToken));
                }
                finally
                {
                    if (gssContext != null)
                    {
                        gssContext.Dispose();
                    }
                }
            }
        /// <exception cref="System.Exception"/>
        public virtual void TestInit()
        {
            Assert.Equal(KerberosTestUtils.GetKeytabFile(), handler.GetKeytab
                             ());
            ICollection <KerberosPrincipal> principals = handler.GetPrincipals();
            Principal expectedPrincipal = new KerberosPrincipal(KerberosTestUtils.GetServerPrincipal
                                                                    ());

            Assert.True(principals.Contains(expectedPrincipal));
            Assert.Equal(1, principals.Count);
        }
        protected internal virtual Properties GetDefaultProperties()
        {
            Properties props = new Properties();

            props.SetProperty(KerberosAuthenticationHandler.Principal, KerberosTestUtils.GetServerPrincipal
                                  ());
            props.SetProperty(KerberosAuthenticationHandler.Keytab, KerberosTestUtils.GetKeytabFile
                                  ());
            props.SetProperty(KerberosAuthenticationHandler.NameRules, "RULE:[1:$1@$0](.*@" +
                              KerberosTestUtils.GetRealm() + ")s/@.*//\n");
            return(props);
        }
        private Properties GetAuthenticationHandlerConfiguration()
        {
            Properties props = new Properties();

            props.SetProperty(AuthenticationFilter.AuthType, "kerberos");
            props.SetProperty(KerberosAuthenticationHandler.Principal, KerberosTestUtils.GetServerPrincipal
                                  ());
            props.SetProperty(KerberosAuthenticationHandler.Keytab, KerberosTestUtils.GetKeytabFile
                                  ());
            props.SetProperty(KerberosAuthenticationHandler.NameRules, "RULE:[1:$1@$0](.*@" +
                              KerberosTestUtils.GetRealm() + ")s/@.*//\n");
            return(props);
        }
        public virtual void Setup()
        {
            // create keytab
            FilePath keytabFile      = new FilePath(KerberosTestUtils.GetKeytabFile());
            string   clientPrincipal = KerberosTestUtils.GetClientPrincipal();
            string   serverPrincipal = KerberosTestUtils.GetServerPrincipal();

            clientPrincipal = Runtime.Substring(clientPrincipal, 0, clientPrincipal.LastIndexOf
                                                    ("@"));
            serverPrincipal = Runtime.Substring(serverPrincipal, 0, serverPrincipal.LastIndexOf
                                                    ("@"));
            GetKdc().CreatePrincipal(keytabFile, clientPrincipal, serverPrincipal);
        }