Repository: hbase-site Updated Branches: refs/heads/asf-site 55f2f138d -> 5fd895c68
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/5fd895c6/testdevapidocs/src-html/org/apache/hadoop/hbase/security/HBaseKerberosUtils.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/security/HBaseKerberosUtils.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/security/HBaseKerberosUtils.html index f0e0faf..3e37614 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/security/HBaseKerberosUtils.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/security/HBaseKerberosUtils.html @@ -27,93 +27,112 @@ <span class="sourceLineNo">019</span><a name="line.19"></a> <span class="sourceLineNo">020</span>import org.apache.hadoop.conf.Configuration;<a name="line.20"></a> <span class="sourceLineNo">021</span>import org.apache.hadoop.fs.CommonConfigurationKeys;<a name="line.21"></a> -<span class="sourceLineNo">022</span>import org.apache.hadoop.hbase.HBaseConfiguration;<a name="line.22"></a> -<span class="sourceLineNo">023</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.23"></a> -<span class="sourceLineNo">024</span>import org.slf4j.Logger;<a name="line.24"></a> -<span class="sourceLineNo">025</span>import org.slf4j.LoggerFactory;<a name="line.25"></a> -<span class="sourceLineNo">026</span>import org.apache.hbase.thirdparty.com.google.common.base.Strings;<a name="line.26"></a> -<span class="sourceLineNo">027</span>import org.apache.hadoop.security.UserGroupInformation;<a name="line.27"></a> -<span class="sourceLineNo">028</span><a name="line.28"></a> -<span class="sourceLineNo">029</span>import java.io.IOException;<a name="line.29"></a> -<span class="sourceLineNo">030</span>import java.net.InetAddress;<a name="line.30"></a> -<span class="sourceLineNo">031</span><a name="line.31"></a> -<span class="sourceLineNo">032</span>@InterfaceAudience.Private<a name="line.32"></a> -<span class="sourceLineNo">033</span>public class HBaseKerberosUtils {<a name="line.33"></a> -<span class="sourceLineNo">034</span> private static final Logger LOG = LoggerFactory.getLogger(HBaseKerberosUtils.class);<a name="line.34"></a> -<span class="sourceLineNo">035</span><a name="line.35"></a> -<span class="sourceLineNo">036</span> public static final String KRB_PRINCIPAL = "hbase.regionserver.kerberos.principal";<a name="line.36"></a> -<span class="sourceLineNo">037</span> public static final String MASTER_KRB_PRINCIPAL = "hbase.master.kerberos.principal";<a name="line.37"></a> -<span class="sourceLineNo">038</span> public static final String KRB_KEYTAB_FILE = "hbase.regionserver.keytab.file";<a name="line.38"></a> -<span class="sourceLineNo">039</span><a name="line.39"></a> -<span class="sourceLineNo">040</span> public static boolean isKerberosPropertySetted() {<a name="line.40"></a> -<span class="sourceLineNo">041</span> String krbPrincipal = System.getProperty(KRB_PRINCIPAL);<a name="line.41"></a> -<span class="sourceLineNo">042</span> String krbKeytab = System.getProperty(KRB_KEYTAB_FILE);<a name="line.42"></a> -<span class="sourceLineNo">043</span> if (Strings.isNullOrEmpty(krbPrincipal) || Strings.isNullOrEmpty(krbKeytab)) {<a name="line.43"></a> -<span class="sourceLineNo">044</span> return false;<a name="line.44"></a> -<span class="sourceLineNo">045</span> }<a name="line.45"></a> -<span class="sourceLineNo">046</span> return true;<a name="line.46"></a> -<span class="sourceLineNo">047</span> }<a name="line.47"></a> -<span class="sourceLineNo">048</span><a name="line.48"></a> -<span class="sourceLineNo">049</span> public static void setPrincipalForTesting(String principal) {<a name="line.49"></a> -<span class="sourceLineNo">050</span> setSystemProperty(KRB_PRINCIPAL, principal);<a name="line.50"></a> -<span class="sourceLineNo">051</span> }<a name="line.51"></a> -<span class="sourceLineNo">052</span><a name="line.52"></a> -<span class="sourceLineNo">053</span> public static void setKeytabFileForTesting(String keytabFile) {<a name="line.53"></a> -<span class="sourceLineNo">054</span> setSystemProperty(KRB_KEYTAB_FILE, keytabFile);<a name="line.54"></a> -<span class="sourceLineNo">055</span> }<a name="line.55"></a> -<span class="sourceLineNo">056</span><a name="line.56"></a> -<span class="sourceLineNo">057</span> public static void setSystemProperty(String propertyName, String propertyValue) {<a name="line.57"></a> -<span class="sourceLineNo">058</span> System.setProperty(propertyName, propertyValue);<a name="line.58"></a> -<span class="sourceLineNo">059</span> }<a name="line.59"></a> -<span class="sourceLineNo">060</span><a name="line.60"></a> -<span class="sourceLineNo">061</span> public static String getKeytabFileForTesting() {<a name="line.61"></a> -<span class="sourceLineNo">062</span> return System.getProperty(KRB_KEYTAB_FILE);<a name="line.62"></a> -<span class="sourceLineNo">063</span> }<a name="line.63"></a> -<span class="sourceLineNo">064</span><a name="line.64"></a> -<span class="sourceLineNo">065</span> public static String getPrincipalForTesting() {<a name="line.65"></a> -<span class="sourceLineNo">066</span> return System.getProperty(KRB_PRINCIPAL);<a name="line.66"></a> -<span class="sourceLineNo">067</span> }<a name="line.67"></a> -<span class="sourceLineNo">068</span><a name="line.68"></a> -<span class="sourceLineNo">069</span> public static Configuration getConfigurationWoPrincipal() {<a name="line.69"></a> -<span class="sourceLineNo">070</span> Configuration conf = HBaseConfiguration.create();<a name="line.70"></a> -<span class="sourceLineNo">071</span> conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");<a name="line.71"></a> -<span class="sourceLineNo">072</span> conf.set(User.HBASE_SECURITY_CONF_KEY, "kerberos");<a name="line.72"></a> -<span class="sourceLineNo">073</span> conf.setBoolean(User.HBASE_SECURITY_AUTHORIZATION_CONF_KEY, true);<a name="line.73"></a> -<span class="sourceLineNo">074</span> return conf;<a name="line.74"></a> -<span class="sourceLineNo">075</span> }<a name="line.75"></a> -<span class="sourceLineNo">076</span><a name="line.76"></a> -<span class="sourceLineNo">077</span> public static Configuration getSecuredConfiguration() {<a name="line.77"></a> -<span class="sourceLineNo">078</span> Configuration conf = HBaseConfiguration.create();<a name="line.78"></a> -<span class="sourceLineNo">079</span> setSecuredConfiguration(conf);<a name="line.79"></a> -<span class="sourceLineNo">080</span> return conf;<a name="line.80"></a> -<span class="sourceLineNo">081</span> }<a name="line.81"></a> -<span class="sourceLineNo">082</span><a name="line.82"></a> -<span class="sourceLineNo">083</span> public static void setSecuredConfiguration(Configuration conf) {<a name="line.83"></a> -<span class="sourceLineNo">084</span> conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");<a name="line.84"></a> -<span class="sourceLineNo">085</span> conf.set(User.HBASE_SECURITY_CONF_KEY, "kerberos");<a name="line.85"></a> -<span class="sourceLineNo">086</span> conf.setBoolean(User.HBASE_SECURITY_AUTHORIZATION_CONF_KEY, true);<a name="line.86"></a> -<span class="sourceLineNo">087</span> conf.set(KRB_KEYTAB_FILE, System.getProperty(KRB_KEYTAB_FILE));<a name="line.87"></a> -<span class="sourceLineNo">088</span> conf.set(KRB_PRINCIPAL, System.getProperty(KRB_PRINCIPAL));<a name="line.88"></a> -<span class="sourceLineNo">089</span> conf.set(MASTER_KRB_PRINCIPAL, System.getProperty(KRB_PRINCIPAL));<a name="line.89"></a> -<span class="sourceLineNo">090</span> }<a name="line.90"></a> -<span class="sourceLineNo">091</span><a name="line.91"></a> -<span class="sourceLineNo">092</span> public static UserGroupInformation loginAndReturnUGI(Configuration conf, String username)<a name="line.92"></a> -<span class="sourceLineNo">093</span> throws IOException {<a name="line.93"></a> -<span class="sourceLineNo">094</span> String hostname = InetAddress.getLocalHost().getHostName();<a name="line.94"></a> -<span class="sourceLineNo">095</span> String keyTabFileConfKey = "hbase." + username + ".keytab.file";<a name="line.95"></a> -<span class="sourceLineNo">096</span> String keyTabFileLocation = conf.get(keyTabFileConfKey);<a name="line.96"></a> -<span class="sourceLineNo">097</span> String principalConfKey = "hbase." + username + ".kerberos.principal";<a name="line.97"></a> -<span class="sourceLineNo">098</span> String principal = org.apache.hadoop.security.SecurityUtil<a name="line.98"></a> -<span class="sourceLineNo">099</span> .getServerPrincipal(conf.get(principalConfKey), hostname);<a name="line.99"></a> -<span class="sourceLineNo">100</span> if (keyTabFileLocation == null || principal == null) {<a name="line.100"></a> -<span class="sourceLineNo">101</span> LOG.warn("Principal or key tab file null for : " + principalConfKey + ", "<a name="line.101"></a> -<span class="sourceLineNo">102</span> + keyTabFileConfKey);<a name="line.102"></a> -<span class="sourceLineNo">103</span> }<a name="line.103"></a> -<span class="sourceLineNo">104</span> UserGroupInformation ugi =<a name="line.104"></a> -<span class="sourceLineNo">105</span> UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keyTabFileLocation);<a name="line.105"></a> -<span class="sourceLineNo">106</span> return ugi;<a name="line.106"></a> -<span class="sourceLineNo">107</span> }<a name="line.107"></a> -<span class="sourceLineNo">108</span>}<a name="line.108"></a> +<span class="sourceLineNo">022</span>import org.apache.hadoop.hbase.AuthUtil;<a name="line.22"></a> +<span class="sourceLineNo">023</span>import org.apache.hadoop.hbase.HBaseConfiguration;<a name="line.23"></a> +<span class="sourceLineNo">024</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.24"></a> +<span class="sourceLineNo">025</span>import org.slf4j.Logger;<a name="line.25"></a> +<span class="sourceLineNo">026</span>import org.slf4j.LoggerFactory;<a name="line.26"></a> +<span class="sourceLineNo">027</span>import org.apache.hbase.thirdparty.com.google.common.base.Strings;<a name="line.27"></a> +<span class="sourceLineNo">028</span>import org.apache.hadoop.security.UserGroupInformation;<a name="line.28"></a> +<span class="sourceLineNo">029</span><a name="line.29"></a> +<span class="sourceLineNo">030</span>import java.io.IOException;<a name="line.30"></a> +<span class="sourceLineNo">031</span>import java.net.InetAddress;<a name="line.31"></a> +<span class="sourceLineNo">032</span><a name="line.32"></a> +<span class="sourceLineNo">033</span>@InterfaceAudience.Private<a name="line.33"></a> +<span class="sourceLineNo">034</span>public class HBaseKerberosUtils {<a name="line.34"></a> +<span class="sourceLineNo">035</span> private static final Logger LOG = LoggerFactory.getLogger(HBaseKerberosUtils.class);<a name="line.35"></a> +<span class="sourceLineNo">036</span><a name="line.36"></a> +<span class="sourceLineNo">037</span> public static final String KRB_PRINCIPAL = "hbase.regionserver.kerberos.principal";<a name="line.37"></a> +<span class="sourceLineNo">038</span> public static final String MASTER_KRB_PRINCIPAL = "hbase.master.kerberos.principal";<a name="line.38"></a> +<span class="sourceLineNo">039</span> public static final String KRB_KEYTAB_FILE = "hbase.regionserver.keytab.file";<a name="line.39"></a> +<span class="sourceLineNo">040</span> public static final String CLIENT_PRINCIPAL = AuthUtil.HBASE_CLIENT_KERBEROS_PRINCIPAL;<a name="line.40"></a> +<span class="sourceLineNo">041</span> public static final String CLIENT_KEYTAB = AuthUtil.HBASE_CLIENT_KEYTAB_FILE;<a name="line.41"></a> +<span class="sourceLineNo">042</span><a name="line.42"></a> +<span class="sourceLineNo">043</span> public static boolean isKerberosPropertySetted() {<a name="line.43"></a> +<span class="sourceLineNo">044</span> String krbPrincipal = System.getProperty(KRB_PRINCIPAL);<a name="line.44"></a> +<span class="sourceLineNo">045</span> String krbKeytab = System.getProperty(KRB_KEYTAB_FILE);<a name="line.45"></a> +<span class="sourceLineNo">046</span> if (Strings.isNullOrEmpty(krbPrincipal) || Strings.isNullOrEmpty(krbKeytab)) {<a name="line.46"></a> +<span class="sourceLineNo">047</span> return false;<a name="line.47"></a> +<span class="sourceLineNo">048</span> }<a name="line.48"></a> +<span class="sourceLineNo">049</span> return true;<a name="line.49"></a> +<span class="sourceLineNo">050</span> }<a name="line.50"></a> +<span class="sourceLineNo">051</span><a name="line.51"></a> +<span class="sourceLineNo">052</span> public static void setPrincipalForTesting(String principal) {<a name="line.52"></a> +<span class="sourceLineNo">053</span> setSystemProperty(KRB_PRINCIPAL, principal);<a name="line.53"></a> +<span class="sourceLineNo">054</span> }<a name="line.54"></a> +<span class="sourceLineNo">055</span><a name="line.55"></a> +<span class="sourceLineNo">056</span> public static void setKeytabFileForTesting(String keytabFile) {<a name="line.56"></a> +<span class="sourceLineNo">057</span> setSystemProperty(KRB_KEYTAB_FILE, keytabFile);<a name="line.57"></a> +<span class="sourceLineNo">058</span> }<a name="line.58"></a> +<span class="sourceLineNo">059</span><a name="line.59"></a> +<span class="sourceLineNo">060</span> public static void setClientPrincipalForTesting(String clientPrincipal) {<a name="line.60"></a> +<span class="sourceLineNo">061</span> setSystemProperty(CLIENT_PRINCIPAL, clientPrincipal);<a name="line.61"></a> +<span class="sourceLineNo">062</span> }<a name="line.62"></a> +<span class="sourceLineNo">063</span><a name="line.63"></a> +<span class="sourceLineNo">064</span> public static void setClientKeytabForTesting(String clientKeytab) {<a name="line.64"></a> +<span class="sourceLineNo">065</span> setSystemProperty(CLIENT_KEYTAB, clientKeytab);<a name="line.65"></a> +<span class="sourceLineNo">066</span> }<a name="line.66"></a> +<span class="sourceLineNo">067</span><a name="line.67"></a> +<span class="sourceLineNo">068</span> public static void setSystemProperty(String propertyName, String propertyValue) {<a name="line.68"></a> +<span class="sourceLineNo">069</span> System.setProperty(propertyName, propertyValue);<a name="line.69"></a> +<span class="sourceLineNo">070</span> }<a name="line.70"></a> +<span class="sourceLineNo">071</span><a name="line.71"></a> +<span class="sourceLineNo">072</span> public static String getKeytabFileForTesting() {<a name="line.72"></a> +<span class="sourceLineNo">073</span> return System.getProperty(KRB_KEYTAB_FILE);<a name="line.73"></a> +<span class="sourceLineNo">074</span> }<a name="line.74"></a> +<span class="sourceLineNo">075</span><a name="line.75"></a> +<span class="sourceLineNo">076</span> public static String getPrincipalForTesting() {<a name="line.76"></a> +<span class="sourceLineNo">077</span> return System.getProperty(KRB_PRINCIPAL);<a name="line.77"></a> +<span class="sourceLineNo">078</span> }<a name="line.78"></a> +<span class="sourceLineNo">079</span><a name="line.79"></a> +<span class="sourceLineNo">080</span> public static String getClientPrincipalForTesting() {<a name="line.80"></a> +<span class="sourceLineNo">081</span> return System.getProperty(CLIENT_PRINCIPAL);<a name="line.81"></a> +<span class="sourceLineNo">082</span> }<a name="line.82"></a> +<span class="sourceLineNo">083</span><a name="line.83"></a> +<span class="sourceLineNo">084</span> public static String getClientKeytabForTesting() {<a name="line.84"></a> +<span class="sourceLineNo">085</span> return System.getProperty(CLIENT_KEYTAB);<a name="line.85"></a> +<span class="sourceLineNo">086</span> }<a name="line.86"></a> +<span class="sourceLineNo">087</span><a name="line.87"></a> +<span class="sourceLineNo">088</span> public static Configuration getConfigurationWoPrincipal() {<a name="line.88"></a> +<span class="sourceLineNo">089</span> Configuration conf = HBaseConfiguration.create();<a name="line.89"></a> +<span class="sourceLineNo">090</span> conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");<a name="line.90"></a> +<span class="sourceLineNo">091</span> conf.set(User.HBASE_SECURITY_CONF_KEY, "kerberos");<a name="line.91"></a> +<span class="sourceLineNo">092</span> conf.setBoolean(User.HBASE_SECURITY_AUTHORIZATION_CONF_KEY, true);<a name="line.92"></a> +<span class="sourceLineNo">093</span> return conf;<a name="line.93"></a> +<span class="sourceLineNo">094</span> }<a name="line.94"></a> +<span class="sourceLineNo">095</span><a name="line.95"></a> +<span class="sourceLineNo">096</span> public static Configuration getSecuredConfiguration() {<a name="line.96"></a> +<span class="sourceLineNo">097</span> Configuration conf = HBaseConfiguration.create();<a name="line.97"></a> +<span class="sourceLineNo">098</span> setSecuredConfiguration(conf);<a name="line.98"></a> +<span class="sourceLineNo">099</span> return conf;<a name="line.99"></a> +<span class="sourceLineNo">100</span> }<a name="line.100"></a> +<span class="sourceLineNo">101</span><a name="line.101"></a> +<span class="sourceLineNo">102</span> public static void setSecuredConfiguration(Configuration conf) {<a name="line.102"></a> +<span class="sourceLineNo">103</span> conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");<a name="line.103"></a> +<span class="sourceLineNo">104</span> conf.set(User.HBASE_SECURITY_CONF_KEY, "kerberos");<a name="line.104"></a> +<span class="sourceLineNo">105</span> conf.setBoolean(User.HBASE_SECURITY_AUTHORIZATION_CONF_KEY, true);<a name="line.105"></a> +<span class="sourceLineNo">106</span> conf.set(KRB_KEYTAB_FILE, System.getProperty(KRB_KEYTAB_FILE));<a name="line.106"></a> +<span class="sourceLineNo">107</span> conf.set(KRB_PRINCIPAL, System.getProperty(KRB_PRINCIPAL));<a name="line.107"></a> +<span class="sourceLineNo">108</span> conf.set(MASTER_KRB_PRINCIPAL, System.getProperty(KRB_PRINCIPAL));<a name="line.108"></a> +<span class="sourceLineNo">109</span> }<a name="line.109"></a> +<span class="sourceLineNo">110</span><a name="line.110"></a> +<span class="sourceLineNo">111</span> public static UserGroupInformation loginAndReturnUGI(Configuration conf, String username)<a name="line.111"></a> +<span class="sourceLineNo">112</span> throws IOException {<a name="line.112"></a> +<span class="sourceLineNo">113</span> String hostname = InetAddress.getLocalHost().getHostName();<a name="line.113"></a> +<span class="sourceLineNo">114</span> String keyTabFileConfKey = "hbase." + username + ".keytab.file";<a name="line.114"></a> +<span class="sourceLineNo">115</span> String keyTabFileLocation = conf.get(keyTabFileConfKey);<a name="line.115"></a> +<span class="sourceLineNo">116</span> String principalConfKey = "hbase." + username + ".kerberos.principal";<a name="line.116"></a> +<span class="sourceLineNo">117</span> String principal = org.apache.hadoop.security.SecurityUtil<a name="line.117"></a> +<span class="sourceLineNo">118</span> .getServerPrincipal(conf.get(principalConfKey), hostname);<a name="line.118"></a> +<span class="sourceLineNo">119</span> if (keyTabFileLocation == null || principal == null) {<a name="line.119"></a> +<span class="sourceLineNo">120</span> LOG.warn("Principal or key tab file null for : " + principalConfKey + ", "<a name="line.120"></a> +<span class="sourceLineNo">121</span> + keyTabFileConfKey);<a name="line.121"></a> +<span class="sourceLineNo">122</span> }<a name="line.122"></a> +<span class="sourceLineNo">123</span> UserGroupInformation ugi =<a name="line.123"></a> +<span class="sourceLineNo">124</span> UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keyTabFileLocation);<a name="line.124"></a> +<span class="sourceLineNo">125</span> return ugi;<a name="line.125"></a> +<span class="sourceLineNo">126</span> }<a name="line.126"></a> +<span class="sourceLineNo">127</span>}<a name="line.127"></a> http://git-wip-us.apache.org/repos/asf/hbase-site/blob/5fd895c6/testdevapidocs/src-html/org/apache/hadoop/hbase/security/TestUsersOperationsWithSecureHadoop.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/security/TestUsersOperationsWithSecureHadoop.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/security/TestUsersOperationsWithSecureHadoop.html index 969f244..cf5821c 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/security/TestUsersOperationsWithSecureHadoop.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/security/TestUsersOperationsWithSecureHadoop.html @@ -25,97 +25,138 @@ <span class="sourceLineNo">017</span> */<a name="line.17"></a> <span class="sourceLineNo">018</span>package org.apache.hadoop.hbase.security;<a name="line.18"></a> <span class="sourceLineNo">019</span><a name="line.19"></a> -<span class="sourceLineNo">020</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getConfigurationWoPrincipal;<a name="line.20"></a> -<span class="sourceLineNo">021</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getKeytabFileForTesting;<a name="line.21"></a> -<span class="sourceLineNo">022</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getPrincipalForTesting;<a name="line.22"></a> -<span class="sourceLineNo">023</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getSecuredConfiguration;<a name="line.23"></a> -<span class="sourceLineNo">024</span>import static org.junit.Assert.assertFalse;<a name="line.24"></a> -<span class="sourceLineNo">025</span>import static org.junit.Assert.assertNotNull;<a name="line.25"></a> -<span class="sourceLineNo">026</span>import static org.junit.Assert.assertTrue;<a name="line.26"></a> -<span class="sourceLineNo">027</span><a name="line.27"></a> -<span class="sourceLineNo">028</span>import java.io.File;<a name="line.28"></a> -<span class="sourceLineNo">029</span>import java.io.IOException;<a name="line.29"></a> -<span class="sourceLineNo">030</span>import org.apache.hadoop.conf.Configuration;<a name="line.30"></a> -<span class="sourceLineNo">031</span>import org.apache.hadoop.hbase.HBaseClassTestRule;<a name="line.31"></a> -<span class="sourceLineNo">032</span>import org.apache.hadoop.hbase.HBaseTestingUtility;<a name="line.32"></a> -<span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.testclassification.SecurityTests;<a name="line.33"></a> -<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.testclassification.SmallTests;<a name="line.34"></a> -<span class="sourceLineNo">035</span>import org.apache.hadoop.minikdc.MiniKdc;<a name="line.35"></a> -<span class="sourceLineNo">036</span>import org.apache.hadoop.security.UserGroupInformation;<a name="line.36"></a> -<span class="sourceLineNo">037</span>import org.junit.AfterClass;<a name="line.37"></a> -<span class="sourceLineNo">038</span>import org.junit.BeforeClass;<a name="line.38"></a> -<span class="sourceLineNo">039</span>import org.junit.ClassRule;<a name="line.39"></a> -<span class="sourceLineNo">040</span>import org.junit.Test;<a name="line.40"></a> -<span class="sourceLineNo">041</span>import org.junit.experimental.categories.Category;<a name="line.41"></a> -<span class="sourceLineNo">042</span><a name="line.42"></a> -<span class="sourceLineNo">043</span>@Category({ SecurityTests.class, SmallTests.class })<a name="line.43"></a> -<span class="sourceLineNo">044</span>public class TestUsersOperationsWithSecureHadoop {<a name="line.44"></a> -<span class="sourceLineNo">045</span><a name="line.45"></a> -<span class="sourceLineNo">046</span> @ClassRule<a name="line.46"></a> -<span class="sourceLineNo">047</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.47"></a> -<span class="sourceLineNo">048</span> HBaseClassTestRule.forClass(TestUsersOperationsWithSecureHadoop.class);<a name="line.48"></a> +<span class="sourceLineNo">020</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getClientKeytabForTesting;<a name="line.20"></a> +<span class="sourceLineNo">021</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getClientPrincipalForTesting;<a name="line.21"></a> +<span class="sourceLineNo">022</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getKeytabFileForTesting;<a name="line.22"></a> +<span class="sourceLineNo">023</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getPrincipalForTesting;<a name="line.23"></a> +<span class="sourceLineNo">024</span>import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.getSecuredConfiguration;<a name="line.24"></a> +<span class="sourceLineNo">025</span>import static org.junit.Assert.assertEquals;<a name="line.25"></a> +<span class="sourceLineNo">026</span>import static org.junit.Assert.assertFalse;<a name="line.26"></a> +<span class="sourceLineNo">027</span>import static org.junit.Assert.assertNotNull;<a name="line.27"></a> +<span class="sourceLineNo">028</span>import static org.junit.Assert.assertTrue;<a name="line.28"></a> +<span class="sourceLineNo">029</span><a name="line.29"></a> +<span class="sourceLineNo">030</span>import java.io.File;<a name="line.30"></a> +<span class="sourceLineNo">031</span>import java.io.IOException;<a name="line.31"></a> +<span class="sourceLineNo">032</span><a name="line.32"></a> +<span class="sourceLineNo">033</span>import org.apache.hadoop.conf.Configuration;<a name="line.33"></a> +<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.AuthUtil;<a name="line.34"></a> +<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.HBaseClassTestRule;<a name="line.35"></a> +<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.HBaseTestingUtility;<a name="line.36"></a> +<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.testclassification.SecurityTests;<a name="line.37"></a> +<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.testclassification.SmallTests;<a name="line.38"></a> +<span class="sourceLineNo">039</span>import org.apache.hadoop.minikdc.MiniKdc;<a name="line.39"></a> +<span class="sourceLineNo">040</span>import org.apache.hadoop.security.UserGroupInformation;<a name="line.40"></a> +<span class="sourceLineNo">041</span>import org.junit.AfterClass;<a name="line.41"></a> +<span class="sourceLineNo">042</span>import org.junit.BeforeClass;<a name="line.42"></a> +<span class="sourceLineNo">043</span>import org.junit.ClassRule;<a name="line.43"></a> +<span class="sourceLineNo">044</span>import org.junit.Test;<a name="line.44"></a> +<span class="sourceLineNo">045</span>import org.junit.experimental.categories.Category;<a name="line.45"></a> +<span class="sourceLineNo">046</span><a name="line.46"></a> +<span class="sourceLineNo">047</span>@Category({ SecurityTests.class, SmallTests.class })<a name="line.47"></a> +<span class="sourceLineNo">048</span>public class TestUsersOperationsWithSecureHadoop {<a name="line.48"></a> <span class="sourceLineNo">049</span><a name="line.49"></a> -<span class="sourceLineNo">050</span> private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.50"></a> -<span class="sourceLineNo">051</span> private static final File KEYTAB_FILE = new File(TEST_UTIL.getDataTestDir("keytab").toUri()<a name="line.51"></a> -<span class="sourceLineNo">052</span> .getPath());<a name="line.52"></a> +<span class="sourceLineNo">050</span> @ClassRule<a name="line.50"></a> +<span class="sourceLineNo">051</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.51"></a> +<span class="sourceLineNo">052</span> HBaseClassTestRule.forClass(TestUsersOperationsWithSecureHadoop.class);<a name="line.52"></a> <span class="sourceLineNo">053</span><a name="line.53"></a> -<span class="sourceLineNo">054</span> private static MiniKdc KDC;<a name="line.54"></a> -<span class="sourceLineNo">055</span><a name="line.55"></a> -<span class="sourceLineNo">056</span> private static String HOST = "localhost";<a name="line.56"></a> +<span class="sourceLineNo">054</span> private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.54"></a> +<span class="sourceLineNo">055</span> private static final File KEYTAB_FILE = new File(TEST_UTIL.getDataTestDir("keytab").toUri()<a name="line.55"></a> +<span class="sourceLineNo">056</span> .getPath());<a name="line.56"></a> <span class="sourceLineNo">057</span><a name="line.57"></a> -<span class="sourceLineNo">058</span> private static String PRINCIPAL;<a name="line.58"></a> +<span class="sourceLineNo">058</span> private static MiniKdc KDC;<a name="line.58"></a> <span class="sourceLineNo">059</span><a name="line.59"></a> -<span class="sourceLineNo">060</span> @BeforeClass<a name="line.60"></a> -<span class="sourceLineNo">061</span> public static void setUp() throws Exception {<a name="line.61"></a> -<span class="sourceLineNo">062</span> KDC = TEST_UTIL.setupMiniKdc(KEYTAB_FILE);<a name="line.62"></a> -<span class="sourceLineNo">063</span> PRINCIPAL = "hbase/" + HOST;<a name="line.63"></a> -<span class="sourceLineNo">064</span> KDC.createPrincipal(KEYTAB_FILE, PRINCIPAL);<a name="line.64"></a> -<span class="sourceLineNo">065</span> HBaseKerberosUtils.setPrincipalForTesting(PRINCIPAL + "@" + KDC.getRealm());<a name="line.65"></a> -<span class="sourceLineNo">066</span> }<a name="line.66"></a> -<span class="sourceLineNo">067</span><a name="line.67"></a> -<span class="sourceLineNo">068</span> @AfterClass<a name="line.68"></a> -<span class="sourceLineNo">069</span> public static void tearDown() throws IOException {<a name="line.69"></a> -<span class="sourceLineNo">070</span> if (KDC != null) {<a name="line.70"></a> -<span class="sourceLineNo">071</span> KDC.stop();<a name="line.71"></a> -<span class="sourceLineNo">072</span> }<a name="line.72"></a> -<span class="sourceLineNo">073</span> TEST_UTIL.cleanupTestDir();<a name="line.73"></a> -<span class="sourceLineNo">074</span> }<a name="line.74"></a> -<span class="sourceLineNo">075</span><a name="line.75"></a> -<span class="sourceLineNo">076</span> /**<a name="line.76"></a> -<span class="sourceLineNo">077</span> * test login with security enabled configuration To run this test, we must specify the following<a name="line.77"></a> -<span class="sourceLineNo">078</span> * system properties:<a name="line.78"></a> -<span class="sourceLineNo">079</span> * <p><a name="line.79"></a> -<span class="sourceLineNo">080</span> * <b> hbase.regionserver.kerberos.principal </b><a name="line.80"></a> -<span class="sourceLineNo">081</span> * <p><a name="line.81"></a> -<span class="sourceLineNo">082</span> * <b> hbase.regionserver.keytab.file </b><a name="line.82"></a> -<span class="sourceLineNo">083</span> * @throws IOException<a name="line.83"></a> -<span class="sourceLineNo">084</span> */<a name="line.84"></a> -<span class="sourceLineNo">085</span> @Test<a name="line.85"></a> -<span class="sourceLineNo">086</span> public void testUserLoginInSecureHadoop() throws Exception {<a name="line.86"></a> -<span class="sourceLineNo">087</span> UserGroupInformation defaultLogin = UserGroupInformation.getLoginUser();<a name="line.87"></a> -<span class="sourceLineNo">088</span> Configuration conf = getConfigurationWoPrincipal();<a name="line.88"></a> -<span class="sourceLineNo">089</span> User.login(conf, HBaseKerberosUtils.KRB_KEYTAB_FILE, HBaseKerberosUtils.KRB_PRINCIPAL,<a name="line.89"></a> -<span class="sourceLineNo">090</span> "localhost");<a name="line.90"></a> -<span class="sourceLineNo">091</span><a name="line.91"></a> -<span class="sourceLineNo">092</span> UserGroupInformation failLogin = UserGroupInformation.getLoginUser();<a name="line.92"></a> -<span class="sourceLineNo">093</span> assertTrue("ugi should be the same in case fail login", defaultLogin.equals(failLogin));<a name="line.93"></a> -<span class="sourceLineNo">094</span><a name="line.94"></a> -<span class="sourceLineNo">095</span> String nnKeyTab = getKeytabFileForTesting();<a name="line.95"></a> -<span class="sourceLineNo">096</span> String dnPrincipal = getPrincipalForTesting();<a name="line.96"></a> -<span class="sourceLineNo">097</span><a name="line.97"></a> -<span class="sourceLineNo">098</span> assertNotNull("KerberosKeytab was not specified", nnKeyTab);<a name="line.98"></a> -<span class="sourceLineNo">099</span> assertNotNull("KerberosPrincipal was not specified", dnPrincipal);<a name="line.99"></a> -<span class="sourceLineNo">100</span><a name="line.100"></a> -<span class="sourceLineNo">101</span> conf = getSecuredConfiguration();<a name="line.101"></a> -<span class="sourceLineNo">102</span> UserGroupInformation.setConfiguration(conf);<a name="line.102"></a> -<span class="sourceLineNo">103</span><a name="line.103"></a> -<span class="sourceLineNo">104</span> User.login(conf, HBaseKerberosUtils.KRB_KEYTAB_FILE, HBaseKerberosUtils.KRB_PRINCIPAL,<a name="line.104"></a> -<span class="sourceLineNo">105</span> "localhost");<a name="line.105"></a> -<span class="sourceLineNo">106</span> UserGroupInformation successLogin = UserGroupInformation.getLoginUser();<a name="line.106"></a> -<span class="sourceLineNo">107</span> assertFalse("ugi should be different in in case success login",<a name="line.107"></a> -<span class="sourceLineNo">108</span> defaultLogin.equals(successLogin));<a name="line.108"></a> -<span class="sourceLineNo">109</span> }<a name="line.109"></a> -<span class="sourceLineNo">110</span>}<a name="line.110"></a> +<span class="sourceLineNo">060</span> private static String HOST = "localhost";<a name="line.60"></a> +<span class="sourceLineNo">061</span><a name="line.61"></a> +<span class="sourceLineNo">062</span> private static String PRINCIPAL;<a name="line.62"></a> +<span class="sourceLineNo">063</span><a name="line.63"></a> +<span class="sourceLineNo">064</span> private static String CLIENT_NAME;<a name="line.64"></a> +<span class="sourceLineNo">065</span><a name="line.65"></a> +<span class="sourceLineNo">066</span> @BeforeClass<a name="line.66"></a> +<span class="sourceLineNo">067</span> public static void setUp() throws Exception {<a name="line.67"></a> +<span class="sourceLineNo">068</span> KDC = TEST_UTIL.setupMiniKdc(KEYTAB_FILE);<a name="line.68"></a> +<span class="sourceLineNo">069</span> PRINCIPAL = "hbase/" + HOST;<a name="line.69"></a> +<span class="sourceLineNo">070</span> CLIENT_NAME = "foo";<a name="line.70"></a> +<span class="sourceLineNo">071</span> KDC.createPrincipal(KEYTAB_FILE, PRINCIPAL, CLIENT_NAME);<a name="line.71"></a> +<span class="sourceLineNo">072</span> HBaseKerberosUtils.setPrincipalForTesting(PRINCIPAL + "@" + KDC.getRealm());<a name="line.72"></a> +<span class="sourceLineNo">073</span> HBaseKerberosUtils.setKeytabFileForTesting(KEYTAB_FILE.getAbsolutePath());<a name="line.73"></a> +<span class="sourceLineNo">074</span> HBaseKerberosUtils.setClientPrincipalForTesting(CLIENT_NAME + "@" + KDC.getRealm());<a name="line.74"></a> +<span class="sourceLineNo">075</span> HBaseKerberosUtils.setClientKeytabForTesting(KEYTAB_FILE.getAbsolutePath());<a name="line.75"></a> +<span class="sourceLineNo">076</span> }<a name="line.76"></a> +<span class="sourceLineNo">077</span><a name="line.77"></a> +<span class="sourceLineNo">078</span> @AfterClass<a name="line.78"></a> +<span class="sourceLineNo">079</span> public static void tearDown() throws IOException {<a name="line.79"></a> +<span class="sourceLineNo">080</span> if (KDC != null) {<a name="line.80"></a> +<span class="sourceLineNo">081</span> KDC.stop();<a name="line.81"></a> +<span class="sourceLineNo">082</span> }<a name="line.82"></a> +<span class="sourceLineNo">083</span> TEST_UTIL.cleanupTestDir();<a name="line.83"></a> +<span class="sourceLineNo">084</span> }<a name="line.84"></a> +<span class="sourceLineNo">085</span><a name="line.85"></a> +<span class="sourceLineNo">086</span> /**<a name="line.86"></a> +<span class="sourceLineNo">087</span> * test login with security enabled configuration To run this test, we must specify the following<a name="line.87"></a> +<span class="sourceLineNo">088</span> * system properties:<a name="line.88"></a> +<span class="sourceLineNo">089</span> * <p><a name="line.89"></a> +<span class="sourceLineNo">090</span> * <b> hbase.regionserver.kerberos.principal </b><a name="line.90"></a> +<span class="sourceLineNo">091</span> * <p><a name="line.91"></a> +<span class="sourceLineNo">092</span> * <b> hbase.regionserver.keytab.file </b><a name="line.92"></a> +<span class="sourceLineNo">093</span> * @throws IOException<a name="line.93"></a> +<span class="sourceLineNo">094</span> */<a name="line.94"></a> +<span class="sourceLineNo">095</span> @Test<a name="line.95"></a> +<span class="sourceLineNo">096</span> public void testUserLoginInSecureHadoop() throws Exception {<a name="line.96"></a> +<span class="sourceLineNo">097</span> // Default login is system user.<a name="line.97"></a> +<span class="sourceLineNo">098</span> UserGroupInformation defaultLogin = UserGroupInformation.getCurrentUser();<a name="line.98"></a> +<span class="sourceLineNo">099</span><a name="line.99"></a> +<span class="sourceLineNo">100</span> String nnKeyTab = getKeytabFileForTesting();<a name="line.100"></a> +<span class="sourceLineNo">101</span> String dnPrincipal = getPrincipalForTesting();<a name="line.101"></a> +<span class="sourceLineNo">102</span><a name="line.102"></a> +<span class="sourceLineNo">103</span> assertNotNull("KerberosKeytab was not specified", nnKeyTab);<a name="line.103"></a> +<span class="sourceLineNo">104</span> assertNotNull("KerberosPrincipal was not specified", dnPrincipal);<a name="line.104"></a> +<span class="sourceLineNo">105</span><a name="line.105"></a> +<span class="sourceLineNo">106</span> Configuration conf = getSecuredConfiguration();<a name="line.106"></a> +<span class="sourceLineNo">107</span> UserGroupInformation.setConfiguration(conf);<a name="line.107"></a> +<span class="sourceLineNo">108</span><a name="line.108"></a> +<span class="sourceLineNo">109</span> User.login(conf, HBaseKerberosUtils.KRB_KEYTAB_FILE, HBaseKerberosUtils.KRB_PRINCIPAL,<a name="line.109"></a> +<span class="sourceLineNo">110</span> "localhost");<a name="line.110"></a> +<span class="sourceLineNo">111</span> UserGroupInformation successLogin = UserGroupInformation.getLoginUser();<a name="line.111"></a> +<span class="sourceLineNo">112</span> assertFalse("ugi should be different in in case success login",<a name="line.112"></a> +<span class="sourceLineNo">113</span> defaultLogin.equals(successLogin));<a name="line.113"></a> +<span class="sourceLineNo">114</span> }<a name="line.114"></a> +<span class="sourceLineNo">115</span><a name="line.115"></a> +<span class="sourceLineNo">116</span> @Test<a name="line.116"></a> +<span class="sourceLineNo">117</span> public void testLoginWithUserKeytabAndPrincipal() throws Exception {<a name="line.117"></a> +<span class="sourceLineNo">118</span> String clientKeytab = getClientKeytabForTesting();<a name="line.118"></a> +<span class="sourceLineNo">119</span> String clientPrincipal = getClientPrincipalForTesting();<a name="line.119"></a> +<span class="sourceLineNo">120</span> assertNotNull("Path for client keytab is not specified.", clientKeytab);<a name="line.120"></a> +<span class="sourceLineNo">121</span> assertNotNull("Client principal is not specified.", clientPrincipal);<a name="line.121"></a> +<span class="sourceLineNo">122</span><a name="line.122"></a> +<span class="sourceLineNo">123</span> Configuration conf = getSecuredConfiguration();<a name="line.123"></a> +<span class="sourceLineNo">124</span> conf.set(AuthUtil.HBASE_CLIENT_KEYTAB_FILE, clientKeytab);<a name="line.124"></a> +<span class="sourceLineNo">125</span> conf.set(AuthUtil.HBASE_CLIENT_KERBEROS_PRINCIPAL, clientPrincipal);<a name="line.125"></a> +<span class="sourceLineNo">126</span> UserGroupInformation.setConfiguration(conf);<a name="line.126"></a> +<span class="sourceLineNo">127</span><a name="line.127"></a> +<span class="sourceLineNo">128</span> UserProvider provider = UserProvider.instantiate(conf);<a name="line.128"></a> +<span class="sourceLineNo">129</span> assertTrue("Client principal or keytab is empty", provider.shouldLoginFromKeytab());<a name="line.129"></a> +<span class="sourceLineNo">130</span><a name="line.130"></a> +<span class="sourceLineNo">131</span> provider.login(AuthUtil.HBASE_CLIENT_KEYTAB_FILE, AuthUtil.HBASE_CLIENT_KERBEROS_PRINCIPAL);<a name="line.131"></a> +<span class="sourceLineNo">132</span> User loginUser = provider.getCurrent();<a name="line.132"></a> +<span class="sourceLineNo">133</span> assertEquals(CLIENT_NAME, loginUser.getShortName());<a name="line.133"></a> +<span class="sourceLineNo">134</span> assertEquals(getClientPrincipalForTesting(), loginUser.getName());<a name="line.134"></a> +<span class="sourceLineNo">135</span> }<a name="line.135"></a> +<span class="sourceLineNo">136</span><a name="line.136"></a> +<span class="sourceLineNo">137</span> @Test<a name="line.137"></a> +<span class="sourceLineNo">138</span> public void testAuthUtilLogin() throws Exception {<a name="line.138"></a> +<span class="sourceLineNo">139</span> String clientKeytab = getClientKeytabForTesting();<a name="line.139"></a> +<span class="sourceLineNo">140</span> String clientPrincipal = getClientPrincipalForTesting();<a name="line.140"></a> +<span class="sourceLineNo">141</span> Configuration conf = getSecuredConfiguration();<a name="line.141"></a> +<span class="sourceLineNo">142</span> conf.set(AuthUtil.HBASE_CLIENT_KEYTAB_FILE, clientKeytab);<a name="line.142"></a> +<span class="sourceLineNo">143</span> conf.set(AuthUtil.HBASE_CLIENT_KERBEROS_PRINCIPAL, clientPrincipal);<a name="line.143"></a> +<span class="sourceLineNo">144</span> UserGroupInformation.setConfiguration(conf);<a name="line.144"></a> +<span class="sourceLineNo">145</span><a name="line.145"></a> +<span class="sourceLineNo">146</span> User user = AuthUtil.loginClient(conf);<a name="line.146"></a> +<span class="sourceLineNo">147</span> assertTrue(user.isLoginFromKeytab());<a name="line.147"></a> +<span class="sourceLineNo">148</span> assertEquals(CLIENT_NAME, user.getShortName());<a name="line.148"></a> +<span class="sourceLineNo">149</span> assertEquals(getClientPrincipalForTesting(), user.getName());<a name="line.149"></a> +<span class="sourceLineNo">150</span> }<a name="line.150"></a> +<span class="sourceLineNo">151</span>}<a name="line.151"></a>