001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import java.io.File; 021import java.io.IOException; 022import java.net.URI; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.ipc.RpcClient; 025import org.apache.hadoop.hbase.testclassification.ClientTests; 026import org.apache.hadoop.hbase.testclassification.MediumTests; 027import org.apache.hadoop.minikdc.MiniKdc; 028import org.junit.jupiter.api.AfterAll; 029import org.junit.jupiter.api.BeforeAll; 030import org.junit.jupiter.api.Tag; 031 032/** 033 * Test basic read write operation with different {@link ConnectionRegistry} implementations when 034 * security is enabled. 035 */ 036@Tag(MediumTests.TAG) 037@Tag(ClientTests.TAG) 038public class TestSecureBasicReadWriteWithDifferentConnectionRegistries 039 extends BasicReadWriteWithDifferentConnectionRegistriesTestBase { 040 041 protected static final File KEYTAB_FILE = 042 new File(UTIL.getDataTestDir("keytab").toUri().getPath()); 043 044 private static MiniKdc KDC; 045 private static String HOST = "localhost"; 046 private static String PRINCIPAL; 047 private static String HTTP_PRINCIPAL; 048 049 protected static void stopKDC() { 050 if (KDC != null) { 051 KDC.stop(); 052 } 053 } 054 055 @BeforeAll 056 public static void setUpBeforeClass() throws Exception { 057 KDC = UTIL.setupMiniKdc(KEYTAB_FILE); 058 PRINCIPAL = "hbase/" + HOST; 059 HTTP_PRINCIPAL = "HTTP/" + HOST; 060 KDC.createPrincipal(KEYTAB_FILE, PRINCIPAL, HTTP_PRINCIPAL); 061 // set a smaller timeout and retry to speed up tests 062 UTIL.getConfiguration().setInt(RpcClient.SOCKET_TIMEOUT_READ, 2000); 063 UTIL.getConfiguration().setInt("hbase.security.relogin.maxretries", 1); 064 UTIL.getConfiguration().setInt("hbase.security.relogin.maxbackoff", 100); 065 UTIL.startSecureMiniCluster(KDC, PRINCIPAL, HTTP_PRINCIPAL); 066 } 067 068 @AfterAll 069 public static void tearDownAfterClass() throws Exception { 070 UTIL.shutdownMiniCluster(); 071 } 072 073 // for connecting to secure hbase cluster, we need to get some information from Configuration, so 074 // here we need to use UTIL.getConfiguration to get the security related information 075 @Override 076 protected Configuration getConf() { 077 return new Configuration(UTIL.getConfiguration()); 078 } 079 080 @Override 081 protected Connection createConn(URI uri) throws IOException { 082 return ConnectionFactory.createConnection(uri, UTIL.getConfiguration()); 083 } 084}