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.provider; 019 020import static org.junit.Assert.assertNotNull; 021 022import java.util.Arrays; 023import java.util.Collections; 024import java.util.HashSet; 025import java.util.Set; 026import org.apache.hadoop.conf.Configuration; 027import org.apache.hadoop.hbase.HBaseClassTestRule; 028import org.apache.hadoop.hbase.testclassification.SmallTests; 029import org.junit.Before; 030import org.junit.ClassRule; 031import org.junit.Test; 032import org.junit.experimental.categories.Category; 033 034@Category({ SmallTests.class }) 035public class TestDefaultProviderSelector { 036 037 @ClassRule 038 public static final HBaseClassTestRule CLASS_RULE = 039 HBaseClassTestRule.forClass(TestDefaultProviderSelector.class); 040 041 BuiltInProviderSelector selector; 042 043 @Before 044 public void setup() { 045 selector = new BuiltInProviderSelector(); 046 } 047 048 @Test(expected = IllegalStateException.class) 049 public void testExceptionOnMissingProviders() { 050 selector.configure(new Configuration(false), Collections.emptySet()); 051 } 052 053 @Test(expected = NullPointerException.class) 054 public void testNullConfiguration() { 055 selector.configure(null, Collections.emptySet()); 056 } 057 058 @Test(expected = NullPointerException.class) 059 public void testNullProviderMap() { 060 selector.configure(new Configuration(false), null); 061 } 062 063 @Test(expected = IllegalStateException.class) 064 public void testDuplicateProviders() { 065 Set<SaslClientAuthenticationProvider> providers = new HashSet<>(); 066 providers.add(new SimpleSaslClientAuthenticationProvider()); 067 providers.add(new SimpleSaslClientAuthenticationProvider()); 068 selector.configure(new Configuration(false), providers); 069 } 070 071 @Test 072 public void testExpectedProviders() { 073 HashSet<SaslClientAuthenticationProvider> providers = 074 new HashSet<>(Arrays.asList(new SimpleSaslClientAuthenticationProvider(), 075 new GssSaslClientAuthenticationProvider(), new DigestSaslClientAuthenticationProvider())); 076 077 selector.configure(new Configuration(false), providers); 078 079 assertNotNull("Simple provider was null", selector.simpleAuth); 080 assertNotNull("Kerberos provider was null", selector.krbAuth); 081 assertNotNull("Digest provider was null", selector.digestAuth); 082 } 083}