/// <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)
            {
            }
        }
        // dynamic configuration of HTTP principals
        /// <exception cref="System.Exception"/>
        public virtual void TestDynamicPrincipalDiscovery()
        {
            string[] keytabUsers = new string[] { "HTTP/host1", "HTTP/host2", "HTTP2/host1",
                                                  "XHTTP/host" };
            string keytab = KerberosTestUtils.GetKeytabFile();

            GetKdc().CreatePrincipal(new FilePath(keytab), keytabUsers);
            // destroy handler created in setUp()
            handler.Destroy();
            Properties props = new Properties();

            props.SetProperty(KerberosAuthenticationHandler.Keytab, keytab);
            props.SetProperty(KerberosAuthenticationHandler.Principal, "*");
            handler = GetNewAuthenticationHandler();
            handler.Init(props);
            Assert.Equal(KerberosTestUtils.GetKeytabFile(), handler.GetKeytab
                             ());
            ICollection <KerberosPrincipal> loginPrincipals = handler.GetPrincipals();

            foreach (string user in keytabUsers)
            {
                Principal principal = new KerberosPrincipal(user + "@" + KerberosTestUtils.GetRealm
                                                                ());
                bool expected = user.StartsWith("HTTP/");
                Assert.Equal("checking for " + user, expected, loginPrincipals
                             .Contains(principal));
            }
        }
Exemple #3
0
 public virtual void TestRules()
 {
     CheckTranslation("omalley@" + KerberosTestUtils.GetRealm(), "omalley");
     CheckTranslation("hdfs/10.0.0.1@" + KerberosTestUtils.GetRealm(), "hdfs");
     CheckTranslation("*****@*****.**", "oom");
     CheckTranslation("johndoe/[email protected]", "guest");
     CheckTranslation("joe/[email protected]", "joe");
     CheckTranslation("joe/[email protected]", "root");
 }
Exemple #4
0
        public virtual void SetUp()
        {
            Runtime.SetProperty("java.security.krb5.realm", KerberosTestUtils.GetRealm());
            Runtime.SetProperty("java.security.krb5.kdc", "localhost:88");
            string rules = "RULE:[1:$1@$0](.*@YAHOO\\.COM)s/@.*//\n" + "RULE:[2:$1](johndoe)s/^.*$/guest/\n"
                           + "RULE:[2:$1;$2](^.*;admin$)s/;admin$//\n" + "RULE:[2:$2](root)\n" + "DEFAULT";

            KerberosName.SetRules(rules);
            KerberosName.PrintRules();
        }
        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);
        }