Example usage for org.springframework.security.acls.model AccessControlEntry getPermission

List of usage examples for org.springframework.security.acls.model AccessControlEntry getPermission

Introduction

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

Prototype

Permission getPermission();

Source Link

Usage

From source file:com.ewcms.core.site.web.AclAction.java

private List<Map<String, Object>> permissionItems(List<AccessControlEntry> aces, boolean inheriting) {

    List<Map<String, Object>> userItems = new ArrayList<Map<String, Object>>();
    List<Map<String, Object>> groupItems = new ArrayList<Map<String, Object>>();
    List<Map<String, Object>> authorityItems = new ArrayList<Map<String, Object>>();
    for (AccessControlEntry ace : aces) {
        Sid sid = ace.getSid();/*  ww  w  . j a  v  a  2 s . c o m*/
        String n = (sid instanceof PrincipalSid) ? ((PrincipalSid) sid).getPrincipal()
                : ((GrantedAuthoritySid) sid).getGrantedAuthority();
        int m = ace.getPermission().getMask();
        if (isAuthority(n)) {
            authorityItems.add(permissionItem(n, m));
        } else if (isGroup(n)) {
            groupItems.add(permissionItem(n, m));
        } else {
            userItems.add(permissionItem(n, m));
        }
    }

    List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
    items.addAll(authorityItems);
    items.addAll(groupItems);
    items.addAll(userItems);
    items.add(inheritItem(inheriting));

    return items;
}

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;/*from  w  w w  .  ja v a 2  s.co  m*/
        // Prepare the information we'd like in our access control entry
        // (ACE)
        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 removePermissionToAnObject_READ(User user, Long id_object, String name_class) {
    if (user != null) {

        // Create or update the relevant ACL
        MutableAcl acl = null;// w ww .jav a  2 s  .c  o m
        // Prepare the information we'd like in our access control entry
        // (ACE)
        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;/*from w  w w . jav a  2s  .c  om*/
        // Prepare the information we'd like in our access control entry
        // (ACE)
        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;/*from  w  w w . j a v a 2 s  . co  m*/
    // Prepare the information we'd like in our access control entry (ACE)
    ObjectIdentity oi = new ObjectIdentityImpl(name_class, id_object);

    Sid sid = null;

    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 removePermissionToAnObjectCollection_READ(Collection<User> users, Long id_object,
        String name_class) {

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

    Sid sid = null;

    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:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java

private AccessControlEntryValue createAceValue(final AccessControlEntry ace) {
    Serializable aceId = ace.getId();
    // we require the ACE ids to be uuids for ease of serialization /
    // deserialization
    UUID id = (UUID) (aceId != null && aceId instanceof UUID ? aceId : UUID.randomUUID());
    return new AccessControlEntryValue(id, ace.getSid(), ace.getPermission(), ace.isGranting());
}

From source file:org.apache.kylin.rest.service.AccessService.java

public List<AccessEntryResponse> generateAceResponsesByFuzzMatching(Acl acl, String nameSeg,
        boolean isCaseSensitive) {
    if (null == acl) {
        return Collections.emptyList();
    }//from w w  w .  jav  a 2 s.  c o m

    List<AccessEntryResponse> result = new ArrayList<AccessEntryResponse>();
    for (AccessControlEntry ace : acl.getEntries()) {
        if (nameSeg != null && !needAdd(nameSeg, isCaseSensitive, getName(ace.getSid()))) {
            continue;
        }
        result.add(new AccessEntryResponse(ace.getId(), ace.getSid(), ace.getPermission(), ace.isGranting()));
    }

    return result;
}

From source file:org.apache.kylin.rest.service.AccessService.java

public Object generateAllAceResponses(Acl acl) {
    List<AccessEntryResponse> result = new ArrayList<AccessEntryResponse>();

    while (acl != null) {
        for (AccessControlEntry ace : acl.getEntries()) {
            result.add(/*from   w w w  . j  a v  a 2  s .c  o  m*/
                    new AccessEntryResponse(ace.getId(), ace.getSid(), ace.getPermission(), ace.isGranting()));
        }
        acl = acl.getParentAcl();
    }

    return result;
}

From source file:org.apache.kylin.rest.service.AccessService.java

private Map<String, Integer> getProjectPermission(String project) {
    Map<String, Integer> SidWithPermission = new HashMap<>();

    String uuid = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject(project).getUuid();
    AclEntity ae = getAclEntity(AclEntityType.PROJECT_INSTANCE, uuid);
    Acl acl = getAcl(ae);/*from w  w  w  . j a  v a2  s  . c om*/
    if (acl != null && acl.getEntries() != null) {
        List<AccessControlEntry> aces = acl.getEntries();
        for (AccessControlEntry ace : aces) {
            Sid sid = ace.getSid();
            if (sid instanceof PrincipalSid) {
                String principal = ((PrincipalSid) sid).getPrincipal();
                SidWithPermission.put(principal, ace.getPermission().getMask());
            }
            if (sid instanceof GrantedAuthoritySid) {
                String grantedAuthority = ((GrantedAuthoritySid) sid).getGrantedAuthority();
                SidWithPermission.put(grantedAuthority, ace.getPermission().getMask());
            }
        }
    }
    return SidWithPermission;
}