@@ -39,6 +39,7 @@ import org.apache.spark.{SparkConf, SparkFunSuite}
3939import org .apache .spark .internal .Logging
4040import org .apache .spark .io ._
4141import org .apache .spark .scheduler ._
42+ import org .apache .spark .security .GroupMappingServiceProvider
4243import org .apache .spark .util .{Clock , JsonProtocol , ManualClock , Utils }
4344
4445class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matchers with Logging {
@@ -474,6 +475,48 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
474475 }
475476 }
476477
478+
479+ test(" support history server ui admin acls" ) {
480+ val conf = createTestConf()
481+ .set(" spark.history.ui.acls.enable" , " true" )
482+ .set(" spark.history.ui.admin.acls" , " user1,user2" )
483+ .set(" spark.history.ui.admin.acls.groups" , " group1" )
484+ .set(" spark.user.groups.mapping" , classOf [TestGroupsMappingProvider ].getName)
485+
486+ val provider = new FsHistoryProvider (conf)
487+
488+ val log = newLogFile(" app1" , Some (" attempt1" ), inProgress = false )
489+ writeFile(log, true , None ,
490+ SparkListenerApplicationStart (" app1" , Some (" app1" ), System .currentTimeMillis(),
491+ " test" , Some (" attempt1" )),
492+ SparkListenerEnvironmentUpdate (Map (
493+ " Spark Properties" -> Seq (
494+ (" spark.admin.acls" , " user" ),
495+ (" spark.admin.acls.groups" , " group" )),
496+ " JVM Information" -> Seq .empty,
497+ " System Properties" -> Seq .empty,
498+ " Classpath Entries" -> Seq .empty
499+ )),
500+ SparkListenerApplicationEnd (System .currentTimeMillis()))
501+
502+ provider.checkForLogs()
503+ val appUi = provider.getAppUI(" app1" , Some (" attempt1" ))
504+
505+ assert (appUi.nonEmpty)
506+ val securityManager = appUi.get.ui.securityManager
507+
508+ // Test whether user has permission to access UI.
509+ securityManager.checkUIViewPermissions(" user1" ) should be (true )
510+ securityManager.checkUIViewPermissions(" user2" ) should be (true )
511+ securityManager.checkUIViewPermissions(" user" ) should be (true )
512+ securityManager.checkUIViewPermissions(" abc" ) should be (false )
513+
514+ // Test whether user with admin group has permission to access UI.
515+ securityManager.checkUIViewPermissions(" user3" ) should be (true )
516+ securityManager.checkUIViewPermissions(" user4" ) should be (true )
517+ securityManager.checkUIViewPermissions(" user5" ) should be (false )
518+ }
519+
477520 /**
478521 * Asks the provider to check for logs and calls a function to perform checks on the updated
479522 * app list. Example:
@@ -532,3 +575,14 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
532575 }
533576
534577}
578+
579+ class TestGroupsMappingProvider extends GroupMappingServiceProvider {
580+ private val mappings = Map (
581+ " user3" -> " group1" ,
582+ " user4" -> " group1" )
583+
584+ override def getGroups (username : String ): Set [String ] = {
585+ mappings.get(username).map(Set (_)).getOrElse(Set .empty)
586+ }
587+ }
588+
0 commit comments