http://git-wip-us.apache.org/repos/asf/hbase-site/blob/db523e4d/apidocs/src-html/org/apache/hadoop/hbase/io/crypto/KeyStoreKeyProvider.html ---------------------------------------------------------------------- diff --git a/apidocs/src-html/org/apache/hadoop/hbase/io/crypto/KeyStoreKeyProvider.html b/apidocs/src-html/org/apache/hadoop/hbase/io/crypto/KeyStoreKeyProvider.html index 0e9ca1e..f20dd6d 100644 --- a/apidocs/src-html/org/apache/hadoop/hbase/io/crypto/KeyStoreKeyProvider.html +++ b/apidocs/src-html/org/apache/hadoop/hbase/io/crypto/KeyStoreKeyProvider.html @@ -38,166 +38,167 @@ <span class="sourceLineNo">030</span>import java.security.NoSuchAlgorithmException;<a name="line.30"></a> <span class="sourceLineNo">031</span>import java.security.UnrecoverableKeyException;<a name="line.31"></a> <span class="sourceLineNo">032</span>import java.security.cert.CertificateException;<a name="line.32"></a> -<span class="sourceLineNo">033</span>import java.util.Properties;<a name="line.33"></a> -<span class="sourceLineNo">034</span><a name="line.34"></a> -<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.35"></a> -<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.classification.InterfaceStability;<a name="line.36"></a> -<span class="sourceLineNo">037</span><a name="line.37"></a> -<span class="sourceLineNo">038</span>/**<a name="line.38"></a> -<span class="sourceLineNo">039</span> * A basic KeyProvider that can resolve keys from a protected KeyStore file<a name="line.39"></a> -<span class="sourceLineNo">040</span> * on the local filesystem. It is configured with a URI passed in as a String<a name="line.40"></a> -<span class="sourceLineNo">041</span> * to init(). The URI should have the form:<a name="line.41"></a> -<span class="sourceLineNo">042</span> * <p><a name="line.42"></a> -<span class="sourceLineNo">043</span> * <pre> scheme://path?option1=value1&amp;option2=value2</pre><a name="line.43"></a> -<span class="sourceLineNo">044</span> * <p><a name="line.44"></a> -<span class="sourceLineNo">045</span> * <i>scheme</i> can be either "jks" or "jceks", specifying the file based<a name="line.45"></a> -<span class="sourceLineNo">046</span> * providers shipped with every JRE. The latter is the certificate store for<a name="line.46"></a> -<span class="sourceLineNo">047</span> * the SunJCE cryptography extension, or PKCS #12, and is capable of storing<a name="line.47"></a> -<span class="sourceLineNo">048</span> * SecretKeys.<a name="line.48"></a> -<span class="sourceLineNo">049</span> * <p><a name="line.49"></a> -<span class="sourceLineNo">050</span> * <i>path</i> is the location of the keystore in the filesystem namespace.<a name="line.50"></a> -<span class="sourceLineNo">051</span> * <p><a name="line.51"></a> -<span class="sourceLineNo">052</span> * Options can be specified as query parameters.<a name="line.52"></a> -<span class="sourceLineNo">053</span> * <p><a name="line.53"></a> -<span class="sourceLineNo">054</span> * If the store was created with a password, the password can be specified<a name="line.54"></a> -<span class="sourceLineNo">055</span> * using the option 'password'.<a name="line.55"></a> -<span class="sourceLineNo">056</span> * <p><a name="line.56"></a> -<span class="sourceLineNo">057</span> * For example:<a name="line.57"></a> -<span class="sourceLineNo">058</span> * <p><a name="line.58"></a> -<span class="sourceLineNo">059</span> * <pre> jceks:///var/tmp/example.ks?password=foobar</pre><a name="line.59"></a> -<span class="sourceLineNo">060</span> * <p><a name="line.60"></a> -<span class="sourceLineNo">061</span> * It is assumed that all keys in the store are protected with the same<a name="line.61"></a> -<span class="sourceLineNo">062</span> * password.<a name="line.62"></a> -<span class="sourceLineNo">063</span> * <p><a name="line.63"></a> -<span class="sourceLineNo">064</span> * Alternatively, a properties file can be specified containing passwords for<a name="line.64"></a> -<span class="sourceLineNo">065</span> * keys in the keystore.<a name="line.65"></a> -<span class="sourceLineNo">066</span> * <pre> jceks:///var/tmp/example.ks?passwordFile=/var/tmp/example.pw</pre><a name="line.66"></a> -<span class="sourceLineNo">067</span> * <p><a name="line.67"></a> -<span class="sourceLineNo">068</span> * Subclasses for supporting KeyStores that are not file based can extend the<a name="line.68"></a> -<span class="sourceLineNo">069</span> * protected methods of this class to specify the appropriate<a name="line.69"></a> -<span class="sourceLineNo">070</span> * LoadStoreParameters.<a name="line.70"></a> -<span class="sourceLineNo">071</span> */<a name="line.71"></a> -<span class="sourceLineNo">072</span>@InterfaceAudience.Public<a name="line.72"></a> -<span class="sourceLineNo">073</span>@InterfaceStability.Evolving<a name="line.73"></a> -<span class="sourceLineNo">074</span>public class KeyStoreKeyProvider implements KeyProvider {<a name="line.74"></a> -<span class="sourceLineNo">075</span><a name="line.75"></a> -<span class="sourceLineNo">076</span> protected KeyStore store;<a name="line.76"></a> -<span class="sourceLineNo">077</span> protected char[] password; // can be null if no password<a name="line.77"></a> -<span class="sourceLineNo">078</span> protected Properties passwordFile; // can be null if no file provided<a name="line.78"></a> -<span class="sourceLineNo">079</span><a name="line.79"></a> -<span class="sourceLineNo">080</span> protected void processParameter(String name, String value) throws IOException {<a name="line.80"></a> -<span class="sourceLineNo">081</span> if (name.equalsIgnoreCase(KeyProvider.PASSWORD)) {<a name="line.81"></a> -<span class="sourceLineNo">082</span> password = value.toCharArray();<a name="line.82"></a> -<span class="sourceLineNo">083</span> }<a name="line.83"></a> -<span class="sourceLineNo">084</span> if (name.equalsIgnoreCase(KeyProvider.PASSWORDFILE)) {<a name="line.84"></a> -<span class="sourceLineNo">085</span> Properties p = new Properties();<a name="line.85"></a> -<span class="sourceLineNo">086</span> InputStream in = new BufferedInputStream(new FileInputStream(new File(value)));<a name="line.86"></a> -<span class="sourceLineNo">087</span> try {<a name="line.87"></a> -<span class="sourceLineNo">088</span> p.load(in);<a name="line.88"></a> -<span class="sourceLineNo">089</span> passwordFile = p;<a name="line.89"></a> -<span class="sourceLineNo">090</span> } finally {<a name="line.90"></a> -<span class="sourceLineNo">091</span> in.close();<a name="line.91"></a> -<span class="sourceLineNo">092</span> }<a name="line.92"></a> -<span class="sourceLineNo">093</span> }<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> protected void processParameters(URI uri) throws IOException {<a name="line.96"></a> -<span class="sourceLineNo">097</span> String params = uri.getQuery();<a name="line.97"></a> -<span class="sourceLineNo">098</span> if (params == null || params.isEmpty()) {<a name="line.98"></a> -<span class="sourceLineNo">099</span> return;<a name="line.99"></a> -<span class="sourceLineNo">100</span> }<a name="line.100"></a> -<span class="sourceLineNo">101</span> do {<a name="line.101"></a> -<span class="sourceLineNo">102</span> int nameStart = 0;<a name="line.102"></a> -<span class="sourceLineNo">103</span> int nameEnd = params.indexOf('=');<a name="line.103"></a> -<span class="sourceLineNo">104</span> if (nameEnd == -1) {<a name="line.104"></a> -<span class="sourceLineNo">105</span> throw new RuntimeException("Invalid parameters: '" + params + "'");<a name="line.105"></a> -<span class="sourceLineNo">106</span> }<a name="line.106"></a> -<span class="sourceLineNo">107</span> int valueStart = nameEnd + 1;<a name="line.107"></a> -<span class="sourceLineNo">108</span> int valueEnd = params.indexOf('&');<a name="line.108"></a> -<span class="sourceLineNo">109</span> if (valueEnd == -1) {<a name="line.109"></a> -<span class="sourceLineNo">110</span> valueEnd = params.length();<a name="line.110"></a> -<span class="sourceLineNo">111</span> }<a name="line.111"></a> -<span class="sourceLineNo">112</span> String name = URLDecoder.decode(params.substring(nameStart, nameEnd), "UTF-8");<a name="line.112"></a> -<span class="sourceLineNo">113</span> String value = URLDecoder.decode(params.substring(valueStart, valueEnd), "UTF-8");<a name="line.113"></a> -<span class="sourceLineNo">114</span> processParameter(name, value);<a name="line.114"></a> -<span class="sourceLineNo">115</span> params = params.substring(valueEnd, params.length());<a name="line.115"></a> -<span class="sourceLineNo">116</span> } while (!params.isEmpty());<a name="line.116"></a> -<span class="sourceLineNo">117</span> }<a name="line.117"></a> -<span class="sourceLineNo">118</span><a name="line.118"></a> -<span class="sourceLineNo">119</span> protected void load(URI uri) throws IOException {<a name="line.119"></a> -<span class="sourceLineNo">120</span> String path = uri.getPath();<a name="line.120"></a> -<span class="sourceLineNo">121</span> if (path == null || path.isEmpty()) {<a name="line.121"></a> -<span class="sourceLineNo">122</span> throw new RuntimeException("KeyProvider parameters should specify a path");<a name="line.122"></a> -<span class="sourceLineNo">123</span> }<a name="line.123"></a> -<span class="sourceLineNo">124</span> InputStream is = new FileInputStream(new File(path));<a name="line.124"></a> -<span class="sourceLineNo">125</span> try {<a name="line.125"></a> -<span class="sourceLineNo">126</span> store.load(is, password);<a name="line.126"></a> -<span class="sourceLineNo">127</span> } catch (NoSuchAlgorithmException e) {<a name="line.127"></a> -<span class="sourceLineNo">128</span> throw new RuntimeException(e);<a name="line.128"></a> -<span class="sourceLineNo">129</span> } catch (CertificateException e) {<a name="line.129"></a> -<span class="sourceLineNo">130</span> throw new RuntimeException(e);<a name="line.130"></a> -<span class="sourceLineNo">131</span> } finally {<a name="line.131"></a> -<span class="sourceLineNo">132</span> is.close();<a name="line.132"></a> -<span class="sourceLineNo">133</span> }<a name="line.133"></a> -<span class="sourceLineNo">134</span> }<a name="line.134"></a> -<span class="sourceLineNo">135</span><a name="line.135"></a> -<span class="sourceLineNo">136</span> @Override<a name="line.136"></a> -<span class="sourceLineNo">137</span> public void init(String params) {<a name="line.137"></a> -<span class="sourceLineNo">138</span> try {<a name="line.138"></a> -<span class="sourceLineNo">139</span> URI uri = new URI(params);<a name="line.139"></a> -<span class="sourceLineNo">140</span> String storeType = uri.getScheme();<a name="line.140"></a> -<span class="sourceLineNo">141</span> if (storeType == null || storeType.isEmpty()) {<a name="line.141"></a> -<span class="sourceLineNo">142</span> throw new RuntimeException("KeyProvider scheme should specify KeyStore type");<a name="line.142"></a> -<span class="sourceLineNo">143</span> }<a name="line.143"></a> -<span class="sourceLineNo">144</span> // KeyStore expects instance type specifications in uppercase<a name="line.144"></a> -<span class="sourceLineNo">145</span> store = KeyStore.getInstance(storeType.toUpperCase());<a name="line.145"></a> -<span class="sourceLineNo">146</span> processParameters(uri);<a name="line.146"></a> -<span class="sourceLineNo">147</span> load(uri);<a name="line.147"></a> -<span class="sourceLineNo">148</span> } catch (URISyntaxException e) {<a name="line.148"></a> -<span class="sourceLineNo">149</span> throw new RuntimeException(e);<a name="line.149"></a> -<span class="sourceLineNo">150</span> } catch (KeyStoreException e) {<a name="line.150"></a> -<span class="sourceLineNo">151</span> throw new RuntimeException(e);<a name="line.151"></a> -<span class="sourceLineNo">152</span> } catch (IOException e) {<a name="line.152"></a> -<span class="sourceLineNo">153</span> throw new RuntimeException(e);<a name="line.153"></a> -<span class="sourceLineNo">154</span> }<a name="line.154"></a> -<span class="sourceLineNo">155</span> }<a name="line.155"></a> -<span class="sourceLineNo">156</span><a name="line.156"></a> -<span class="sourceLineNo">157</span> protected char[] getAliasPassword(String alias) {<a name="line.157"></a> -<span class="sourceLineNo">158</span> if (password != null) {<a name="line.158"></a> -<span class="sourceLineNo">159</span> return password;<a name="line.159"></a> -<span class="sourceLineNo">160</span> }<a name="line.160"></a> -<span class="sourceLineNo">161</span> if (passwordFile != null) {<a name="line.161"></a> -<span class="sourceLineNo">162</span> String p = passwordFile.getProperty(alias);<a name="line.162"></a> -<span class="sourceLineNo">163</span> if (p != null) {<a name="line.163"></a> -<span class="sourceLineNo">164</span> return p.toCharArray();<a name="line.164"></a> -<span class="sourceLineNo">165</span> }<a name="line.165"></a> -<span class="sourceLineNo">166</span> }<a name="line.166"></a> -<span class="sourceLineNo">167</span> return null;<a name="line.167"></a> -<span class="sourceLineNo">168</span> }<a name="line.168"></a> -<span class="sourceLineNo">169</span><a name="line.169"></a> -<span class="sourceLineNo">170</span> @Override<a name="line.170"></a> -<span class="sourceLineNo">171</span> public Key getKey(String alias) {<a name="line.171"></a> -<span class="sourceLineNo">172</span> try {<a name="line.172"></a> -<span class="sourceLineNo">173</span> return store.getKey(alias, getAliasPassword(alias));<a name="line.173"></a> -<span class="sourceLineNo">174</span> } catch (UnrecoverableKeyException e) {<a name="line.174"></a> -<span class="sourceLineNo">175</span> throw new RuntimeException(e);<a name="line.175"></a> -<span class="sourceLineNo">176</span> } catch (KeyStoreException e) {<a name="line.176"></a> -<span class="sourceLineNo">177</span> throw new RuntimeException(e);<a name="line.177"></a> -<span class="sourceLineNo">178</span> } catch (NoSuchAlgorithmException e) {<a name="line.178"></a> -<span class="sourceLineNo">179</span> throw new RuntimeException(e);<a name="line.179"></a> -<span class="sourceLineNo">180</span> }<a name="line.180"></a> -<span class="sourceLineNo">181</span> }<a name="line.181"></a> -<span class="sourceLineNo">182</span><a name="line.182"></a> -<span class="sourceLineNo">183</span> @Override<a name="line.183"></a> -<span class="sourceLineNo">184</span> public Key[] getKeys(String[] aliases) {<a name="line.184"></a> -<span class="sourceLineNo">185</span> Key[] result = new Key[aliases.length];<a name="line.185"></a> -<span class="sourceLineNo">186</span> for (int i = 0; i < aliases.length; i++) {<a name="line.186"></a> -<span class="sourceLineNo">187</span> result[i] = getKey(aliases[i]);<a name="line.187"></a> -<span class="sourceLineNo">188</span> }<a name="line.188"></a> -<span class="sourceLineNo">189</span> return result;<a name="line.189"></a> -<span class="sourceLineNo">190</span> }<a name="line.190"></a> -<span class="sourceLineNo">191</span><a name="line.191"></a> -<span class="sourceLineNo">192</span>}<a name="line.192"></a> +<span class="sourceLineNo">033</span>import java.util.Locale;<a name="line.33"></a> +<span class="sourceLineNo">034</span>import java.util.Properties;<a name="line.34"></a> +<span class="sourceLineNo">035</span><a name="line.35"></a> +<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.36"></a> +<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.classification.InterfaceStability;<a name="line.37"></a> +<span class="sourceLineNo">038</span><a name="line.38"></a> +<span class="sourceLineNo">039</span>/**<a name="line.39"></a> +<span class="sourceLineNo">040</span> * A basic KeyProvider that can resolve keys from a protected KeyStore file<a name="line.40"></a> +<span class="sourceLineNo">041</span> * on the local filesystem. It is configured with a URI passed in as a String<a name="line.41"></a> +<span class="sourceLineNo">042</span> * to init(). The URI should have the form:<a name="line.42"></a> +<span class="sourceLineNo">043</span> * <p><a name="line.43"></a> +<span class="sourceLineNo">044</span> * <pre> scheme://path?option1=value1&amp;option2=value2</pre><a name="line.44"></a> +<span class="sourceLineNo">045</span> * <p><a name="line.45"></a> +<span class="sourceLineNo">046</span> * <i>scheme</i> can be either "jks" or "jceks", specifying the file based<a name="line.46"></a> +<span class="sourceLineNo">047</span> * providers shipped with every JRE. The latter is the certificate store for<a name="line.47"></a> +<span class="sourceLineNo">048</span> * the SunJCE cryptography extension, or PKCS #12, and is capable of storing<a name="line.48"></a> +<span class="sourceLineNo">049</span> * SecretKeys.<a name="line.49"></a> +<span class="sourceLineNo">050</span> * <p><a name="line.50"></a> +<span class="sourceLineNo">051</span> * <i>path</i> is the location of the keystore in the filesystem namespace.<a name="line.51"></a> +<span class="sourceLineNo">052</span> * <p><a name="line.52"></a> +<span class="sourceLineNo">053</span> * Options can be specified as query parameters.<a name="line.53"></a> +<span class="sourceLineNo">054</span> * <p><a name="line.54"></a> +<span class="sourceLineNo">055</span> * If the store was created with a password, the password can be specified<a name="line.55"></a> +<span class="sourceLineNo">056</span> * using the option 'password'.<a name="line.56"></a> +<span class="sourceLineNo">057</span> * <p><a name="line.57"></a> +<span class="sourceLineNo">058</span> * For example:<a name="line.58"></a> +<span class="sourceLineNo">059</span> * <p><a name="line.59"></a> +<span class="sourceLineNo">060</span> * <pre> jceks:///var/tmp/example.ks?password=foobar</pre><a name="line.60"></a> +<span class="sourceLineNo">061</span> * <p><a name="line.61"></a> +<span class="sourceLineNo">062</span> * It is assumed that all keys in the store are protected with the same<a name="line.62"></a> +<span class="sourceLineNo">063</span> * password.<a name="line.63"></a> +<span class="sourceLineNo">064</span> * <p><a name="line.64"></a> +<span class="sourceLineNo">065</span> * Alternatively, a properties file can be specified containing passwords for<a name="line.65"></a> +<span class="sourceLineNo">066</span> * keys in the keystore.<a name="line.66"></a> +<span class="sourceLineNo">067</span> * <pre> jceks:///var/tmp/example.ks?passwordFile=/var/tmp/example.pw</pre><a name="line.67"></a> +<span class="sourceLineNo">068</span> * <p><a name="line.68"></a> +<span class="sourceLineNo">069</span> * Subclasses for supporting KeyStores that are not file based can extend the<a name="line.69"></a> +<span class="sourceLineNo">070</span> * protected methods of this class to specify the appropriate<a name="line.70"></a> +<span class="sourceLineNo">071</span> * LoadStoreParameters.<a name="line.71"></a> +<span class="sourceLineNo">072</span> */<a name="line.72"></a> +<span class="sourceLineNo">073</span>@InterfaceAudience.Public<a name="line.73"></a> +<span class="sourceLineNo">074</span>@InterfaceStability.Evolving<a name="line.74"></a> +<span class="sourceLineNo">075</span>public class KeyStoreKeyProvider implements KeyProvider {<a name="line.75"></a> +<span class="sourceLineNo">076</span><a name="line.76"></a> +<span class="sourceLineNo">077</span> protected KeyStore store;<a name="line.77"></a> +<span class="sourceLineNo">078</span> protected char[] password; // can be null if no password<a name="line.78"></a> +<span class="sourceLineNo">079</span> protected Properties passwordFile; // can be null if no file provided<a name="line.79"></a> +<span class="sourceLineNo">080</span><a name="line.80"></a> +<span class="sourceLineNo">081</span> protected void processParameter(String name, String value) throws IOException {<a name="line.81"></a> +<span class="sourceLineNo">082</span> if (name.equalsIgnoreCase(KeyProvider.PASSWORD)) {<a name="line.82"></a> +<span class="sourceLineNo">083</span> password = value.toCharArray();<a name="line.83"></a> +<span class="sourceLineNo">084</span> }<a name="line.84"></a> +<span class="sourceLineNo">085</span> if (name.equalsIgnoreCase(KeyProvider.PASSWORDFILE)) {<a name="line.85"></a> +<span class="sourceLineNo">086</span> Properties p = new Properties();<a name="line.86"></a> +<span class="sourceLineNo">087</span> InputStream in = new BufferedInputStream(new FileInputStream(new File(value)));<a name="line.87"></a> +<span class="sourceLineNo">088</span> try {<a name="line.88"></a> +<span class="sourceLineNo">089</span> p.load(in);<a name="line.89"></a> +<span class="sourceLineNo">090</span> passwordFile = p;<a name="line.90"></a> +<span class="sourceLineNo">091</span> } finally {<a name="line.91"></a> +<span class="sourceLineNo">092</span> in.close();<a name="line.92"></a> +<span class="sourceLineNo">093</span> }<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><a name="line.96"></a> +<span class="sourceLineNo">097</span> protected void processParameters(URI uri) throws IOException {<a name="line.97"></a> +<span class="sourceLineNo">098</span> String params = uri.getQuery();<a name="line.98"></a> +<span class="sourceLineNo">099</span> if (params == null || params.isEmpty()) {<a name="line.99"></a> +<span class="sourceLineNo">100</span> return;<a name="line.100"></a> +<span class="sourceLineNo">101</span> }<a name="line.101"></a> +<span class="sourceLineNo">102</span> do {<a name="line.102"></a> +<span class="sourceLineNo">103</span> int nameStart = 0;<a name="line.103"></a> +<span class="sourceLineNo">104</span> int nameEnd = params.indexOf('=');<a name="line.104"></a> +<span class="sourceLineNo">105</span> if (nameEnd == -1) {<a name="line.105"></a> +<span class="sourceLineNo">106</span> throw new RuntimeException("Invalid parameters: '" + params + "'");<a name="line.106"></a> +<span class="sourceLineNo">107</span> }<a name="line.107"></a> +<span class="sourceLineNo">108</span> int valueStart = nameEnd + 1;<a name="line.108"></a> +<span class="sourceLineNo">109</span> int valueEnd = params.indexOf('&');<a name="line.109"></a> +<span class="sourceLineNo">110</span> if (valueEnd == -1) {<a name="line.110"></a> +<span class="sourceLineNo">111</span> valueEnd = params.length();<a name="line.111"></a> +<span class="sourceLineNo">112</span> }<a name="line.112"></a> +<span class="sourceLineNo">113</span> String name = URLDecoder.decode(params.substring(nameStart, nameEnd), "UTF-8");<a name="line.113"></a> +<span class="sourceLineNo">114</span> String value = URLDecoder.decode(params.substring(valueStart, valueEnd), "UTF-8");<a name="line.114"></a> +<span class="sourceLineNo">115</span> processParameter(name, value);<a name="line.115"></a> +<span class="sourceLineNo">116</span> params = params.substring(valueEnd, params.length());<a name="line.116"></a> +<span class="sourceLineNo">117</span> } while (!params.isEmpty());<a name="line.117"></a> +<span class="sourceLineNo">118</span> }<a name="line.118"></a> +<span class="sourceLineNo">119</span><a name="line.119"></a> +<span class="sourceLineNo">120</span> protected void load(URI uri) throws IOException {<a name="line.120"></a> +<span class="sourceLineNo">121</span> String path = uri.getPath();<a name="line.121"></a> +<span class="sourceLineNo">122</span> if (path == null || path.isEmpty()) {<a name="line.122"></a> +<span class="sourceLineNo">123</span> throw new RuntimeException("KeyProvider parameters should specify a path");<a name="line.123"></a> +<span class="sourceLineNo">124</span> }<a name="line.124"></a> +<span class="sourceLineNo">125</span> InputStream is = new FileInputStream(new File(path));<a name="line.125"></a> +<span class="sourceLineNo">126</span> try {<a name="line.126"></a> +<span class="sourceLineNo">127</span> store.load(is, password);<a name="line.127"></a> +<span class="sourceLineNo">128</span> } catch (NoSuchAlgorithmException e) {<a name="line.128"></a> +<span class="sourceLineNo">129</span> throw new RuntimeException(e);<a name="line.129"></a> +<span class="sourceLineNo">130</span> } catch (CertificateException e) {<a name="line.130"></a> +<span class="sourceLineNo">131</span> throw new RuntimeException(e);<a name="line.131"></a> +<span class="sourceLineNo">132</span> } finally {<a name="line.132"></a> +<span class="sourceLineNo">133</span> is.close();<a name="line.133"></a> +<span class="sourceLineNo">134</span> }<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> @Override<a name="line.137"></a> +<span class="sourceLineNo">138</span> public void init(String params) {<a name="line.138"></a> +<span class="sourceLineNo">139</span> try {<a name="line.139"></a> +<span class="sourceLineNo">140</span> URI uri = new URI(params);<a name="line.140"></a> +<span class="sourceLineNo">141</span> String storeType = uri.getScheme();<a name="line.141"></a> +<span class="sourceLineNo">142</span> if (storeType == null || storeType.isEmpty()) {<a name="line.142"></a> +<span class="sourceLineNo">143</span> throw new RuntimeException("KeyProvider scheme should specify KeyStore type");<a name="line.143"></a> +<span class="sourceLineNo">144</span> }<a name="line.144"></a> +<span class="sourceLineNo">145</span> // KeyStore expects instance type specifications in uppercase<a name="line.145"></a> +<span class="sourceLineNo">146</span> store = KeyStore.getInstance(storeType.toUpperCase(Locale.ROOT));<a name="line.146"></a> +<span class="sourceLineNo">147</span> processParameters(uri);<a name="line.147"></a> +<span class="sourceLineNo">148</span> load(uri);<a name="line.148"></a> +<span class="sourceLineNo">149</span> } catch (URISyntaxException e) {<a name="line.149"></a> +<span class="sourceLineNo">150</span> throw new RuntimeException(e);<a name="line.150"></a> +<span class="sourceLineNo">151</span> } catch (KeyStoreException e) {<a name="line.151"></a> +<span class="sourceLineNo">152</span> throw new RuntimeException(e);<a name="line.152"></a> +<span class="sourceLineNo">153</span> } catch (IOException e) {<a name="line.153"></a> +<span class="sourceLineNo">154</span> throw new RuntimeException(e);<a name="line.154"></a> +<span class="sourceLineNo">155</span> }<a name="line.155"></a> +<span class="sourceLineNo">156</span> }<a name="line.156"></a> +<span class="sourceLineNo">157</span><a name="line.157"></a> +<span class="sourceLineNo">158</span> protected char[] getAliasPassword(String alias) {<a name="line.158"></a> +<span class="sourceLineNo">159</span> if (password != null) {<a name="line.159"></a> +<span class="sourceLineNo">160</span> return password;<a name="line.160"></a> +<span class="sourceLineNo">161</span> }<a name="line.161"></a> +<span class="sourceLineNo">162</span> if (passwordFile != null) {<a name="line.162"></a> +<span class="sourceLineNo">163</span> String p = passwordFile.getProperty(alias);<a name="line.163"></a> +<span class="sourceLineNo">164</span> if (p != null) {<a name="line.164"></a> +<span class="sourceLineNo">165</span> return p.toCharArray();<a name="line.165"></a> +<span class="sourceLineNo">166</span> }<a name="line.166"></a> +<span class="sourceLineNo">167</span> }<a name="line.167"></a> +<span class="sourceLineNo">168</span> return null;<a name="line.168"></a> +<span class="sourceLineNo">169</span> }<a name="line.169"></a> +<span class="sourceLineNo">170</span><a name="line.170"></a> +<span class="sourceLineNo">171</span> @Override<a name="line.171"></a> +<span class="sourceLineNo">172</span> public Key getKey(String alias) {<a name="line.172"></a> +<span class="sourceLineNo">173</span> try {<a name="line.173"></a> +<span class="sourceLineNo">174</span> return store.getKey(alias, getAliasPassword(alias));<a name="line.174"></a> +<span class="sourceLineNo">175</span> } catch (UnrecoverableKeyException e) {<a name="line.175"></a> +<span class="sourceLineNo">176</span> throw new RuntimeException(e);<a name="line.176"></a> +<span class="sourceLineNo">177</span> } catch (KeyStoreException e) {<a name="line.177"></a> +<span class="sourceLineNo">178</span> throw new RuntimeException(e);<a name="line.178"></a> +<span class="sourceLineNo">179</span> } catch (NoSuchAlgorithmException e) {<a name="line.179"></a> +<span class="sourceLineNo">180</span> throw new RuntimeException(e);<a name="line.180"></a> +<span class="sourceLineNo">181</span> }<a name="line.181"></a> +<span class="sourceLineNo">182</span> }<a name="line.182"></a> +<span class="sourceLineNo">183</span><a name="line.183"></a> +<span class="sourceLineNo">184</span> @Override<a name="line.184"></a> +<span class="sourceLineNo">185</span> public Key[] getKeys(String[] aliases) {<a name="line.185"></a> +<span class="sourceLineNo">186</span> Key[] result = new Key[aliases.length];<a name="line.186"></a> +<span class="sourceLineNo">187</span> for (int i = 0; i < aliases.length; i++) {<a name="line.187"></a> +<span class="sourceLineNo">188</span> result[i] = getKey(aliases[i]);<a name="line.188"></a> +<span class="sourceLineNo">189</span> }<a name="line.189"></a> +<span class="sourceLineNo">190</span> return result;<a name="line.190"></a> +<span class="sourceLineNo">191</span> }<a name="line.191"></a> +<span class="sourceLineNo">192</span><a name="line.192"></a> +<span class="sourceLineNo">193</span>}<a name="line.193"></a>
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/db523e4d/apidocs/src-html/org/apache/hadoop/hbase/ipc/SyncCoprocessorRpcChannel.html ---------------------------------------------------------------------- diff --git a/apidocs/src-html/org/apache/hadoop/hbase/ipc/SyncCoprocessorRpcChannel.html b/apidocs/src-html/org/apache/hadoop/hbase/ipc/SyncCoprocessorRpcChannel.html index d18e9eb..d19b294 100644 --- a/apidocs/src-html/org/apache/hadoop/hbase/ipc/SyncCoprocessorRpcChannel.html +++ b/apidocs/src-html/org/apache/hadoop/hbase/ipc/SyncCoprocessorRpcChannel.html @@ -43,7 +43,7 @@ <span class="sourceLineNo">035</span> * Base class which provides clients with an RPC connection to<a name="line.35"></a> <span class="sourceLineNo">036</span> * call coprocessor endpoint {@link com.google.protobuf.Service}s.<a name="line.36"></a> <span class="sourceLineNo">037</span> * Note that clients should not use this class directly, except through<a name="line.37"></a> -<span class="sourceLineNo">038</span> * {@link org.apache.hadoop.hbase.client.HTableInterface#coprocessorService(byte[])}.<a name="line.38"></a> +<span class="sourceLineNo">038</span> * {@link org.apache.hadoop.hbase.client.Table#coprocessorService(byte[])}.<a name="line.38"></a> <span class="sourceLineNo">039</span> */<a name="line.39"></a> <span class="sourceLineNo">040</span>@InterfaceAudience.Public<a name="line.40"></a> <span class="sourceLineNo">041</span>@InterfaceStability.Evolving<a name="line.41"></a>