@@ -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,48 @@ 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 [] {"/jmx" , "/prom" };
200+ String [] denyList = new String [] {"/conf" , "/stacks" , "/logLevel" };
201+ spnegoConf .set (PREFIX + "kerberos.endpoint.whitelist" , String .join ("," , allowList ));
202+ spnegoConf .set ("hadoop.prometheus.endpoint.enabled" , "true" );
203+ spnegoConf .set ("hadoop.http.filter.initializers" ,
204+ "org.apache.hadoop.security.AuthenticationFilterInitializer" );
205+
206+ //setup logs dir
207+ System .setProperty ("hadoop.log.dir" , testRootDir .getAbsolutePath ());
208+
209+ HttpServer2 httpServer = null ;
210+ try {
211+ // Create http server to test.
212+ httpServer = getCommonBuilder ().setConf (spnegoConf ).setSecurityEnabled (true )
213+ .setUsernameConfKey (PREFIX + "kerberos.principal" )
214+ .setKeytabConfKey (PREFIX + "kerberos.keytab" ).build ();
215+ httpServer .start ();
216+
217+ String serverURL = "http://" + NetUtils .getHostPortString (httpServer .getConnectorAddress (0 ));
218+
219+ // endpoints in whitelist should not require Kerberos authentication
220+ for (String endpoint : allowList ) {
221+ HttpURLConnection conn = (HttpURLConnection ) new URL (serverURL + endpoint ).openConnection ();
222+ Assert .assertEquals (HttpURLConnection .HTTP_OK , conn .getResponseCode ());
223+ }
224+
225+ // endpoints not in whitelist should require Kerberos authentication
226+ for (String endpoint : denyList ) {
227+ HttpURLConnection conn = (HttpURLConnection ) new URL (serverURL + endpoint ).openConnection ();
228+ Assert .assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
229+ }
230+
231+ } finally {
232+ if (httpServer != null ) {
233+ httpServer .stop ();
234+ }
235+ }
236+ }
237+
194238 private AuthenticatedURL .Token getEncryptedAuthToken (Signer signer ,
195239 String user ) throws Exception {
196240 AuthenticationToken token =
@@ -209,10 +253,8 @@ private Signer getSignerToEncrypt() throws Exception {
209253 return new Signer (secretProvider );
210254 }
211255
212- private Configuration getSpengoConf (Configuration conf ) {
256+ private Configuration getSpnegoConf (Configuration conf ) {
213257 conf = new Configuration ();
214- conf .set (HttpServer2 .FILTER_INITIALIZER_PROPERTY ,
215- ProxyUserAuthenticationFilterInitializer .class .getName ());
216258 conf .set (PREFIX + "type" , "kerberos" );
217259 conf .setBoolean (PREFIX + "simple.anonymous.allowed" , false );
218260 conf .set (PREFIX + "signature.secret.file" ,
0 commit comments