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

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

Introduction

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

Prototype

List<AccessControlEntry> getEntries();

Source Link

Document

Returns all of the entries represented by the present Acl.

Usage

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 av  a  2  s . c om*/
        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);
    }
}

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

public void removePermissionToAnObject_WRITE(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)/* w w w . ja  v a  2s .c  om*/
        ObjectIdentity oi = new ObjectIdentityImpl(name_class, id_object);

        Sid sid = null;

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

        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);
    }
}

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

public void removePermissionToAnObjectCollection_ADMINISTRATION(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;/* ww w.j  a v  a  2s .  co  m*/

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

        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_ADMINISTRATION(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  ww  w . j a v  a  2  s. co  m*/
        ObjectIdentity oi = new ObjectIdentityImpl(name_class, id_object);

        Sid sid = null;

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

        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);
    }
}

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

public void addPermissionToAnObjectCollection_READ(Collection<User> professors, 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 w  w.  j a va2s .  c  o  m*/
    for (User u : professors) {
        sid = new PrincipalSid(u.getUsername());
        Permission p = BasePermission.READ;

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

        // Now grant some permissions via an access control entry (ACE)
        if (!acl.getEntries().isEmpty())
            acl.insertAce(acl.getEntries().size(), p, sid, true);
        else
            acl.insertAce(2, p, sid, true);

        mutableAclService.updateAcl(acl);

    }

}

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

public void addPermissionToAnObject_WRITE(User coordinator, Long id_object, String name_class) {

    if (coordinator != null) {
        // Create or update the relevant ACL
        MutableAcl acl = null;
        // Prepare the information we'd like in our access control entry
        // (ACE)/*from   w w w  .j av a2 s. co  m*/
        ObjectIdentity oi = new ObjectIdentityImpl(name_class, id_object);

        Sid sid = null;

        sid = new PrincipalSid(coordinator.getUsername());
        Permission p = BasePermission.WRITE;

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

        // Now grant some permissions via an access control entry (ACE)
        if (!acl.getEntries().isEmpty())
            acl.insertAce(acl.getEntries().size(), p, sid, true);
        else
            acl.insertAce(2, p, sid, true);

        mutableAclService.updateAcl(acl);
    }
}

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

public void addPermissionToAnObjectCollection_ADMINISTRATION(Collection<User> professors, 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;/*from ww w.ja v  a 2 s .co  m*/
    for (User u : professors) {
        sid = new PrincipalSid(u.getUsername());
        Permission p = BasePermission.ADMINISTRATION;

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

        // Now grant some permissions via an access control entry (ACE)
        if (!acl.getEntries().isEmpty())
            acl.insertAce(acl.getEntries().size(), p, sid, true);
        else
            acl.insertAce(2, p, sid, true);
        mutableAclService.updateAcl(acl);

    }

}

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

public void addPermissionToAnObject_ADMINISTRATION(User coordinator, Long id_object, String name_class) {

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

        Sid sid = null;

        sid = new PrincipalSid(coordinator.getUsername());
        Permission p = BasePermission.ADMINISTRATION;

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

        // Now grant some permissions via an access control entry (ACE)
        if (!acl.getEntries().isEmpty())
            acl.insertAce(acl.getEntries().size(), p, sid, true);
        else
            acl.insertAce(2, p, sid, true);

        mutableAclService.updateAcl(acl);
    }
}

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

public void addPermissionToAnObject_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)//  w  w  w  .jav  a2 s. c o  m
        ObjectIdentity oi = new ObjectIdentityImpl(name_class, id_object);

        User admin = userService.findByUsername("admin").getSingleElement();
        Sid admin_sid = new PrincipalSid(admin.getUsername());
        List<Sid> sids = new ArrayList<Sid>();
        sids.add(admin_sid);

        Sid sid = null;

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

        try {

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

        if (!acl.getEntries().isEmpty())
            acl.insertAce(acl.getEntries().size(), p, sid, true);
        else
            acl.insertAce(2, p, sid, true);
        mutableAclService.updateAcl(acl);
    }

}

From source file:com.kylinolap.rest.service.AclService.java

@Override
public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
    try {//from  w  w w  .  j  av a2  s.com
        readAclById(acl.getObjectIdentity());
    } catch (NotFoundException e) {
        throw e;
    }

    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName);
        Delete delete = new Delete(Bytes.toBytes(String.valueOf(acl.getObjectIdentity().getIdentifier())));
        delete.deleteFamily(Bytes.toBytes(ACL_ACES_FAMILY));
        htable.delete(delete);

        Put put = new Put(Bytes.toBytes(String.valueOf(acl.getObjectIdentity().getIdentifier())));

        if (null != acl.getParentAcl()) {
            put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_PARENT_COLUMN),
                    domainObjSerializer
                            .serialize(new DomainObjectInfo(acl.getParentAcl().getObjectIdentity())));
        }

        for (AccessControlEntry ace : acl.getEntries()) {
            AceInfo aceInfo = new AceInfo(ace);
            put.add(Bytes.toBytes(ACL_ACES_FAMILY), Bytes.toBytes(aceInfo.getSidInfo().getSid()),
                    aceSerializer.serialize(aceInfo));
        }

        if (!put.isEmpty()) {
            htable.put(put);
            htable.flushCommits();

            logger.debug("ACL of " + acl.getObjectIdentity() + " updated successfully.");
        }
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }

    return (MutableAcl) readAclById(acl.getObjectIdentity());
}