Example usage for org.springframework.security.acls.model MutableAcl deleteAce

List of usage examples for org.springframework.security.acls.model MutableAcl deleteAce

Introduction

In this page you can find the example usage for org.springframework.security.acls.model MutableAcl deleteAce.

Prototype

void deleteAce(int aceIndex) throws NotFoundException;

Source Link

Usage

From source file:com.cedac.security.acls.mongo.MongoMutableAclServiceTests.java

@Test
@ShouldMatchDataSet//  w w  w .j  a v  a  2s  .  c  om
public void updateAcl_deleteEntries() {
    MutableAcl acl = (MutableAcl) fixture
            .readAclById(new ObjectIdentityImpl("com.cedac.smartresidence.profile.domain.Home", "1"));
    acl.deleteAce(5);

    fixture.updateAcl(acl);
}

From source file:sample.contact.service.impl.ContactServiceImpl.java

public void deletePermission(Contact contact, Sid recipient, Permission permission) {
    ObjectIdentity oid = new ObjectIdentityImpl(Contact.class, contact.getId());
    MutableAcl acl = (MutableAcl) mutableAclService.readAclById(oid);

    // Remove all permissions associated with this particular recipient (string
    // equality to KISS)
    List<AccessControlEntry> entries = acl.getEntries();

    for (int i = 0; i < entries.size(); i++) {
        if (entries.get(i).getSid().equals(recipient) && entries.get(i).getPermission().equals(permission)) {
            acl.deleteAce(i);
        }/*from  w  ww.  j a  v a2s  . c o  m*/
    }

    mutableAclService.updateAcl(acl);

    if (logger.isDebugEnabled()) {
        logger.debug("Deleted contact " + contact + " ACL permissions for recipient " + recipient);
    }
}

From source file:sample.contact.service.impl.MenuServiceImpl.java

public void deletePermission(Menu menu, Sid recipient, Permission permission) {
    ObjectIdentity oid = new ObjectIdentityImpl(Menu.class, menu.getId());
    MutableAcl acl = (MutableAcl) mutableAclService.readAclById(oid);

    // Remove all permissions associated with this particular recipient (string
    // equality to KISS)
    List<AccessControlEntry> entries = acl.getEntries();

    for (int i = 0; i < entries.size(); i++) {
        if (entries.get(i).getSid().equals(recipient) && entries.get(i).getPermission().equals(permission)) {
            acl.deleteAce(i);
        }/*from w ww .j  a  va2s  .com*/
    }

    mutableAclService.updateAcl(acl);

    if (logger.isDebugEnabled()) {
        logger.debug("Deleted menu " + menu + " ACL permissions for recipient " + recipient);
    }
}

From source file:com.sshdemo.common.security.acl.service.EwcmsAclService.java

@Override
public void removePermission(Object object, String name) {
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(object);
    MutableAcl acl = (MutableAcl) readAclById(objectIdentity);

    if (acl.getEntries() == null || acl.getEntries().isEmpty()) {
        return;//  w w w.j  a va 2 s  . c  o m
    }

    for (int i = 0; i < acl.getEntries().size(); i++) {
        AccessControlEntry entry = acl.getEntries().get(i);
        if (entry.getSid().equals(getSid(name))) {
            acl.deleteAce(i);
            updateAcl(acl);
            break;
        }
    }
}

From source file:sample.contact.ContactManagerBackend.java

public void deletePermission(Contact contact, Sid recipient, Permission permission) {
    ObjectIdentity oid = new ObjectIdentityImpl(Contact.class, contact.getId());
    MutableAcl acl = (MutableAcl) mutableAclService.readAclById(oid);

    // Remove all permissions associated with this particular recipient (string equality to KISS)
    List<AccessControlEntry> entries = acl.getEntries();

    for (int i = 0; i < entries.size(); i++) {
        if (entries.get(i).getSid().equals(recipient) && entries.get(i).getPermission().equals(permission)) {
            acl.deleteAce(i);
        }/*from  w ww  .  j  a  v a  2 s . c o  m*/
    }

    mutableAclService.updateAcl(acl);

    if (logger.isDebugEnabled()) {
        logger.debug("Deleted contact " + contact + " ACL permissions for recipient " + recipient);
    }
}

From source file:org.createnet.raptor.auth.service.services.AclManagerService.java

@Override
public <T> void removePermission(Class<T> clazz, Serializable identifier, Sid sid, Permission permission) {
    ObjectIdentity identity = new ObjectIdentityImpl(clazz.getCanonicalName(), identifier);
    MutableAcl acl = (MutableAcl) aclService.readAclById(identity);

    AccessControlEntry[] entries = acl.getEntries().toArray(new AccessControlEntry[acl.getEntries().size()]);

    for (int i = 0; i < acl.getEntries().size(); i++) {
        if (entries[i].getSid().equals(sid) && entries[i].getPermission().equals(permission)) {
            acl.deleteAce(i);
        }/*from w w w  . j a va  2s .  co  m*/
    }

    aclService.updateAcl(acl);
}

From source file:org.jtalks.common.service.security.AclManagerImpl.java

/**
 * Delete permissions from {@code acl} for every sid.
 * @param acl           provided acl/*from   w  w  w . j a  va2  s  .co m*/
 * @param sids          list of sids
 * @param permissions   list of permissions
 */
private void deletePermissionsFromAcl(MutableAcl acl, List<Sid> sids, List<Permission> permissions) {
    List<AccessControlEntry> entries = acl.getEntries(); // it's copy
    int i = 0;
    // search for sid-permission pair
    for (AccessControlEntry entry : entries) {
        for (Sid recipient : sids) {
            for (Permission permission : permissions) {
                if (entry.getSid().equals(recipient) && entry.getPermission().equals(permission)) {
                    acl.deleteAce(i); // delete from original list
                    i--; // because list item deleted in original list
                }
            }
        }
        i++;
    }
}

From source file:com.trailmagic.image.security.SpringSecurityImageSecurityService.java

public void effectPermissions(MutableAcl acl, Sid recipient, Set<Permission> newPermissions, boolean additive) {
    Set<Permission> existingPermissions = findExistingPermissions(acl, recipient);

    if (!additive) {
        Set<Permission> permsToRemove = new HashSet<Permission>();
        permsToRemove.addAll(existingPermissions);
        permsToRemove.removeAll(newPermissions);
        for (Permission perm : permsToRemove) {
            acl.deleteAce(indexOf(recipient, perm, acl));
            if (log.isDebugEnabled()) {
                log.debug("Removed ACE for permission " + perm + ", recipient " + recipient + ", on object "
                        + acl.getObjectIdentity());
            }/*  www. j av a  2 s.co m*/

        }
    }

    Set<Permission> permsToAdd = new HashSet<Permission>();
    permsToAdd.addAll(newPermissions);
    permsToAdd.removeAll(existingPermissions);
    for (Permission perm : permsToAdd) {
        acl.insertAce(acl.getEntries().size(), perm, recipient, true);
        if (log.isDebugEnabled()) {
            log.debug("Added ACE for permission " + perm + ", recipient " + recipient + ", on object "
                    + acl.getObjectIdentity());
        }

    }
    aclService.updateAcl(acl);
}

From source file:es.ucm.fdi.dalgs.acl.service.AclObjectService.java

public void removePermissionToAnObjectCollection_READ(Collection<User> users, Long id_object,
        String name_class) {

    // Create or update the relevant ACL
    MutableAcl acl = null;
    // Prepare the information we'd like in our access control entry (ACE)
    ObjectIdentity oi = new ObjectIdentityImpl(name_class, id_object);

    Sid sid = null;//w  ww.jav a  2  s.co  m

    for (User u : users) {
        sid = new PrincipalSid(u.getUsername());
        Permission p = BasePermission.READ;

        try {
            acl = (MutableAcl) mutableAclService.readAclById(oi);
        } catch (NotFoundException nfe) {
            acl = mutableAclService.createAcl(oi);
        }

        int aceIndex = 0;
        for (AccessControlEntry ace : acl.getEntries()) {
            if ((ace.getSid().equals(sid)) && (ace.getPermission().equals(p))) {
                acl.deleteAce(aceIndex);
                break;
            } else
                aceIndex++;
        }
    }

    // Now grant some permissions via an access control entry (ACE)
    if (acl != null)
        mutableAclService.updateAcl(acl);

}

From source file:es.ucm.fdi.dalgs.acl.service.AclObjectService.java

public void removePermissionToAnObject_READ(User user, Long id_object, String name_class) {
    if (user != null) {

        // Create or update the relevant ACL
        MutableAcl acl = null;
        // Prepare the information we'd like in our access control entry
        // (ACE)//from w ww. j  a v  a 2s .c  o  m
        ObjectIdentity oi = new ObjectIdentityImpl(name_class, id_object);

        Sid sid = null;

        sid = new PrincipalSid(user.getUsername());
        Permission p = BasePermission.READ;

        try {
            acl = (MutableAcl) mutableAclService.readAclById(oi);
        } catch (NotFoundException nfe) {
            acl = mutableAclService.createAcl(oi);
        }

        Integer aceIndex = 0;
        for (AccessControlEntry ace : acl.getEntries()) {
            if ((ace.getSid().equals(sid)) && (ace.getPermission().equals(p))) {
                acl.deleteAce(aceIndex);
                break;
            } else
                aceIndex++;
        }

        // Now grant some permissions via an access control entry (ACE)
        if (acl != null)
            mutableAclService.updateAcl(acl);
    }
}