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.security; 019 020import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.loginKerberosPrincipal; 021import static org.apache.hadoop.hbase.security.HBaseKerberosUtils.setSecuredConfiguration; 022 023import java.io.File; 024import java.util.Collections; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl; 028import org.apache.hadoop.hbase.testclassification.MediumTests; 029import org.apache.hadoop.hbase.testclassification.SecurityTests; 030import org.apache.hadoop.minikdc.MiniKdc; 031import org.apache.hadoop.security.UserGroupInformation; 032import org.junit.AfterClass; 033import org.junit.BeforeClass; 034import org.junit.ClassRule; 035import org.junit.experimental.categories.Category; 036import org.junit.runner.RunWith; 037import org.junit.runners.Parameterized; 038import org.mockito.Mockito; 039 040import org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface; 041 042@RunWith(Parameterized.class) 043@Category({ SecurityTests.class, MediumTests.class }) 044public class TestSaslTlsIPCRejectPlainText extends AbstractTestTlsRejectPlainText { 045 046 @ClassRule 047 public static final HBaseClassTestRule CLASS_RULE = 048 HBaseClassTestRule.forClass(TestSaslTlsIPCRejectPlainText.class); 049 050 private static File KEYTAB_FILE; 051 052 private static MiniKdc KDC; 053 private static String HOST = "localhost"; 054 private static String PRINCIPAL; 055 private static UserGroupInformation UGI; 056 057 @BeforeClass 058 public static void setUpBeforeClass() throws Exception { 059 HBaseTestingUtil util = new HBaseTestingUtil(); 060 UTIL = util; 061 initialize(); 062 KEYTAB_FILE = new File(util.getDataTestDir("keytab").toUri().getPath()); 063 KDC = util.setupMiniKdc(KEYTAB_FILE); 064 PRINCIPAL = "hbase/" + HOST; 065 KDC.createPrincipal(KEYTAB_FILE, PRINCIPAL); 066 HBaseKerberosUtils.setPrincipalForTesting(PRINCIPAL + "@" + KDC.getRealm()); 067 UGI = loginKerberosPrincipal(KEYTAB_FILE.getCanonicalPath(), PRINCIPAL); 068 setSecuredConfiguration(util.getConfiguration()); 069 SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class); 070 Mockito.when(securityInfoMock.getServerPrincipals()) 071 .thenReturn(Collections.singletonList(HBaseKerberosUtils.KRB_PRINCIPAL)); 072 SecurityInfo.addInfo("TestProtobufRpcProto", securityInfoMock); 073 } 074 075 @AfterClass 076 public static void tearDownAfterClass() { 077 if (KDC != null) { 078 KDC.stop(); 079 } 080 cleanUp(); 081 } 082 083 @Override 084 protected BlockingInterface createStub() throws Exception { 085 return TestProtobufRpcServiceImpl.newBlockingStub(rpcClient, rpcServer.getListenerAddress(), 086 User.create(UGI)); 087 } 088}