public virtual void TestGetAuthenticationMethod() { Configuration conf = new Configuration(); // default is simple conf.Unset(CommonConfigurationKeysPublic.HadoopSecurityAuthentication); Assert.Equal(UserGroupInformation.AuthenticationMethod.Simple, SecurityUtil.GetAuthenticationMethod(conf)); // simple conf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthentication, "simple"); Assert.Equal(UserGroupInformation.AuthenticationMethod.Simple, SecurityUtil.GetAuthenticationMethod(conf)); // kerberos conf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthentication, "kerberos"); Assert.Equal(UserGroupInformation.AuthenticationMethod.Kerberos , SecurityUtil.GetAuthenticationMethod(conf)); // bad value conf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthentication, "kaboom"); string error = null; try { SecurityUtil.GetAuthenticationMethod(conf); } catch (Exception e) { error = e.ToString(); } Assert.Equal("java.lang.IllegalArgumentException: " + "Invalid attribute value for " + CommonConfigurationKeysPublic.HadoopSecurityAuthentication + " of kaboom", error ); }
/// <summary>Set the static configuration to get the rules.</summary> /// <remarks> /// Set the static configuration to get the rules. /// <p/> /// IMPORTANT: This method does a NOP if the rules have been set already. /// If there is a need to reset the rules, the /// <see cref="Org.Apache.Hadoop.Security.Authentication.Util.KerberosName.SetRules(string) /// "/> /// method should be invoked directly. /// </remarks> /// <param name="conf">the new configuration</param> /// <exception cref="System.IO.IOException"/> public static void SetConfiguration(Configuration conf) { string defaultRule; switch (SecurityUtil.GetAuthenticationMethod(conf)) { case UserGroupInformation.AuthenticationMethod.Kerberos: case UserGroupInformation.AuthenticationMethod.KerberosSsl: { try { KerberosUtil.GetDefaultRealm(); } catch (Exception ke) { throw new ArgumentException("Can't get Kerberos realm", ke); } defaultRule = "DEFAULT"; break; } default: { // just extract the simple user name defaultRule = "RULE:[1:$1] RULE:[2:$1]"; break; } } string ruleString = conf.Get(CommonConfigurationKeysPublic.HadoopSecurityAuthToLocal , defaultRule); SetRules(ruleString); }