1

I have the following method places in a grails 2.4.5 Service.

   @PreAuthorize("hasRole('ROLE_ADMIN')")
   @Transactional
   void addPermission(Company company, String username, Permission permission) {


     if (AclClass.findByClassName(Company.class.name)) {
       def acl = aclUtilService.readAcl(company)
       Sid sidObject = new PrincipalSid(username)

       acl.entries.eachWithIndex { entry, i ->
          println("adddd")
          if (entry.sid.equals(sidObject) && entry.permission.equals(permission)) 
            return
          }
       }
     }
     aclUtilService.addPermission company, username, permission
   }

The problem is that the return statement in the if block does not quite the method addPermission. It just quits the eachWithIndex closure.

How can I exit the addPermission function at the place where I put the return statement?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
Michael
  • 32,527
  • 49
  • 210
  • 370

0 Answers0