@@ -104,7 +104,9 @@ public static void tearDown() {
104104 */
105105 @ Test
106106 public void testAuthenticationWithProxyUser () throws Exception {
107- Configuration spengoConf = getSpengoConf (new Configuration ());
107+ Configuration spnegoConf = getSpnegoConf (new Configuration ());
108+ spnegoConf .set (HttpServer2 .FILTER_INITIALIZER_PROPERTY ,
109+ ProxyUserAuthenticationFilterInitializer .class .getName ());
108110
109111 //setup logs dir
110112 System .setProperty ("hadoop.log.dir" , testRootDir .getAbsolutePath ());
@@ -118,15 +120,15 @@ public void testAuthenticationWithProxyUser() throws Exception {
118120 new String []{"groupC" });
119121
120122 // Make userA impersonate users in groupB
121- spengoConf .set ("hadoop.proxyuser.userA.hosts" , "*" );
122- spengoConf .set ("hadoop.proxyuser.userA.groups" , "groupB" );
123- ProxyUsers .refreshSuperUserGroupsConfiguration (spengoConf );
123+ spnegoConf .set ("hadoop.proxyuser.userA.hosts" , "*" );
124+ spnegoConf .set ("hadoop.proxyuser.userA.groups" , "groupB" );
125+ ProxyUsers .refreshSuperUserGroupsConfiguration (spnegoConf );
124126
125127 HttpServer2 httpServer = null ;
126128 try {
127129 // Create http server to test.
128130 httpServer = getCommonBuilder ()
129- .setConf (spengoConf )
131+ .setConf (spnegoConf )
130132 .setACL (new AccessControlList ("userA groupA" ))
131133 .build ();
132134 httpServer .start ();
@@ -191,6 +193,61 @@ public void testAuthenticationWithProxyUser() throws Exception {
191193 }
192194 }
193195
196+ @ Test
197+ public void testAuthenticationToAllowList () throws Exception {
198+ Configuration spnegoConf = getSpnegoConf (new Configuration ());
199+ String [] allowList = new String [] {
200+ "/jmx" ,
201+ "/prom"
202+ };
203+ String [] denyList = new String [] {
204+ "/conf" ,
205+ "/stacks" ,
206+ "/logLevel"
207+ };
208+ spnegoConf .set (PREFIX + "kerberos.endpoint.whitelist" , String .join ("," , allowList ));
209+ spnegoConf .set ("hadoop.prometheus.endpoint.enabled" , "true" );
210+ spnegoConf .set ("hadoop.http.filter.initializers" ,
211+ "org.apache.hadoop.security.AuthenticationFilterInitializer" );
212+
213+ //setup logs dir
214+ System .setProperty ("hadoop.log.dir" , testRootDir .getAbsolutePath ());
215+
216+ HttpServer2 httpServer = null ;
217+ try {
218+ // Create http server to test.
219+ httpServer = getCommonBuilder ()
220+ .setConf (spnegoConf )
221+ .setSecurityEnabled (true )
222+ .setUsernameConfKey (PREFIX + "kerberos.principal" )
223+ .setKeytabConfKey (PREFIX + "kerberos.keytab" )
224+ .build ();
225+ httpServer .start ();
226+
227+ String serverURL = "http://" +
228+ NetUtils .getHostPortString (httpServer .getConnectorAddress (0 ));
229+
230+ // endpoints in whitelist should not require Kerberos authentication
231+ for (String endpoint :
232+ allowList ) {
233+ HttpURLConnection conn = (HttpURLConnection ) new URL (serverURL + endpoint ).openConnection ();
234+ Assert .assertEquals (HttpURLConnection .HTTP_OK , conn .getResponseCode ());
235+ }
236+
237+ // endpoints not in whitelist should require Kerberos authentication
238+ for (String endpoint :
239+ denyList ) {
240+ HttpURLConnection conn = (HttpURLConnection ) new URL (serverURL + endpoint ).openConnection ();
241+ Assert .assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
242+ }
243+
244+ } finally {
245+ if (httpServer != null ) {
246+ httpServer .stop ();
247+ }
248+ }
249+ }
250+
194251 private AuthenticatedURL .Token getEncryptedAuthToken (Signer signer ,
195252 String user ) throws Exception {
196253 AuthenticationToken token =
@@ -209,10 +266,8 @@ private Signer getSignerToEncrypt() throws Exception {
209266 return new Signer (secretProvider );
210267 }
211268
212- private Configuration getSpengoConf (Configuration conf ) {
269+ private Configuration getSpnegoConf (Configuration conf ) {
213270 conf = new Configuration ();
214- conf .set (HttpServer2 .FILTER_INITIALIZER_PROPERTY ,
215- ProxyUserAuthenticationFilterInitializer .class .getName ());
216271 conf .set (PREFIX + "type" , "kerberos" );
217272 conf .setBoolean (PREFIX + "simple.anonymous.allowed" , false );
218273 conf .set (PREFIX + "signature.secret.file" ,
0 commit comments