Example #1
0
 /**
  * Get existing ACL for identity. If ACL does not exist it will be created.
  *
  * @param oid object identity
  * @return ACL fro this object identity
  */
 private MutableAcl getAclFor(ObjectIdentity oid) {
   MutableAcl acl;
   try {
     acl = (MutableAcl) mutableAclService.readAclById(oid);
   } catch (NotFoundException nfe) {
     acl = mutableAclService.createAcl(oid);
   }
   return acl;
 }
 @Transactional
 @Secured("ROLE_USER")
 public synchronized void postMessage(Message message) {
   message.setId(System.currentTimeMillis());
   messages.put(message.getId(), message);
   ObjectIdentity oid = new ObjectIdentityImpl(Message.class, message.getId());
   MutableAcl acl = mutableAclService.createAcl(oid);
   acl.insertAce(0, BasePermission.ADMINISTRATION, new PrincipalSid(message.getAuthor()), true);
   acl.insertAce(1, BasePermission.DELETE, new GrantedAuthoritySid("ROLE_ADMIN"), true);
   acl.insertAce(2, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER"), true);
   mutableAclService.updateAcl(acl);
 }
  @Transactional
  public int createEvent(Event event) {
    int result = eventDao.createEvent(event);
    event.setId(result);

    MutableAcl acl = aclService.createAcl(new ObjectIdentityImpl(event));
    PrincipalSid sid = new PrincipalSid(userContext.getCurrentUser().getEmail());
    acl.setOwner(sid);
    acl.insertAce(0, BasePermission.READ, sid, true);
    aclService.updateAcl(acl);

    return result;
  }
  public void addPermission(BankingTx tx, Sid recipient, Permission permission) {
    MutableAcl acl;
    ObjectIdentity oid = new ObjectIdentityImpl(BankingTx.class, tx.getId());

    try {
      acl = (MutableAcl) mutableAclService.readAclById(oid);
    } catch (NotFoundException nfe) {
      System.out.println("oid=" + oid.toString());
      acl = mutableAclService.createAcl(oid);
    }

    acl.insertAce(acl.getEntries().size(), permission, recipient, true);
    mutableAclService.updateAcl(acl);
  }
  /** Grants permissions for the specified task to the specified user. */
  private void grantPermissionsForTask(String taskId, String username) {

    MutableAcl taskAcl = null;
    ObjectIdentity taskObjectIdentity = new ObjectIdentityImpl(TASK_PREFIX, taskId);

    try {
      taskAcl = (MutableAcl) mutableAclService.readAclById(taskObjectIdentity);
    } catch (NotFoundException e) {
      taskAcl = mutableAclService.createAcl(taskObjectIdentity);
    }
    Object obj = taskAcl.getEntries();
    taskAcl.insertAce(
        taskAcl.getEntries().size(), BasePermission.WRITE, new PrincipalSid(username), true);
    taskAcl.insertAce(
        taskAcl.getEntries().size(), BasePermission.READ, new PrincipalSid(username), true);

    mutableAclService.updateAcl(taskAcl);
  }