Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RunWith(classOf[JUnitRunner])
- class JRSuperUserSpec extends WordSpec with ShouldMatchers with LoggingTrait{
- val superuser = "admin"
- var password = admin
- val tmpFolder = new File("tmp" + File.separator + UUID.randomUUID.toString)
- tmpFolder.mkdirs
- def inSession[T](repository:TransientRepository,username:String,password:String)(block: JackrabbitSession => T) : T = {
- val session = repository.login(new SimpleCredentials(username,password.toCharArray)).asInstanceOf[JackrabbitSession]
- try{
- block(session)
- }finally{
- session.logout
- }
- }
- val repository = new TransientRepository(new File("src/test/resources/repository.xml"),tmpFolder)
- "The super user" when {
- "managing groups" should {
- "be able to create the administrators group and give its members full rights" in{
- inSession(repository,superuser,password){session =>
- val um = session.getUserManager
- val acm = session.getAccessControlManager
- val group = um.createGroup(SecurityConstants.ADMINISTRATORS_NAME)
- val policies = acm.getPolicies(session.getRootNode.getPath)
- policies.foreach { policy =>
- policy match{
- case acl : AccessControlList =>
- acl.addAccessControlEntry(group.getPrincipal,Array( acm.privilegeFromName(Privilege.JCR_ALL)))
- acm.setPolicy(session.getRootNode.getPath,policy)
- case _ => fail("Unable to give rights to the administrators group")
- }
- }
- session.save
- }
- }
- "be able to create a new administrator. The new admin can also create users" in {
- inSession(repository,superuser,password){session =>
- val um = session.getUserManager
- val group = um.getAuthorizable(SecurityConstants.ADMINISTRATORS_NAME).asInstanceOf[Group]
- val newadmin = "newadmin"
- val user = um.createUser(newadmin,newadmin)
- group.addMember(user)
- inSession(repository,newadmin,newadmin){ usersession =>
- usersession.getUserManager.createUser("foo","bar")
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment