Example usage for org.springframework.security.acls.domain AccessControlEntryImpl AccessControlEntryImpl

List of usage examples for org.springframework.security.acls.domain AccessControlEntryImpl AccessControlEntryImpl

Introduction

In this page you can find the example usage for org.springframework.security.acls.domain AccessControlEntryImpl AccessControlEntryImpl.

Prototype

public AccessControlEntryImpl(Serializable id, Acl acl, Sid sid, Permission permission, boolean granting,
            boolean auditSuccess, boolean auditFailure) 

Source Link

Usage

From source file:org.jtalks.common.security.acl.AclDataProvider.java

@DataProvider
public static Object[][] provideAclWithMixedTypeSids() {
    List<AccessControlEntry> aces = new ArrayList<AccessControlEntry>();
    ExtendedMutableAcl acl = mock(ExtendedMutableAcl.class);
    when(acl.getEntries()).thenReturn(aces);

    aces.add(new AccessControlEntryImpl(1L, acl, new UserGroupSid(1L), GeneralPermission.READ, true, true,
            true));// w  w  w .ja  va2  s .  c om
    aces.add(new AccessControlEntryImpl(2L, acl, new UserSid(2L), BranchPermission.VIEW_TOPICS, false, true,
            true));
    aces.add(new AccessControlEntryImpl(3L, acl, new UserGroupSid(3L), GeneralPermission.WRITE, true, true,
            true));
    return new Object[][] { { acl } };
}

From source file:org.jtalks.common.security.acl.AclDataProvider.java

public static AccessControlEntry createEntry(MutableAcl acl, Sid sid, Permission permission) {
    return new AccessControlEntryImpl(1L, acl, sid, permission, true, true, true);
}

From source file:org.jtalks.common.security.acl.ExtendedMutableAclTest.java

private AccessControlEntry createEntry(long id, MutableAcl acl, Sid sid, Permission permission) {
    return new AccessControlEntryImpl(id, acl, sid, permission, true, true, true);
}

From source file:org.gaixie.micrite.security.service.impl.AclServiceImpl.java

@SuppressWarnings("unchecked")
public Map readAclsById(ObjectIdentity[] objects, Sid[] sids) throws NotFoundException {
    final Map acls = new HashMap();
    for (ObjectIdentity object : objects) {
        // ?Object?acl
        // ?ObjectclassNameid
        String javaType = object.getJavaType().getName();
        AclClass aclClass = aclClassDAO.findByClass(javaType);
        // No need to check for nulls, as guaranteed non-null by ObjectIdentity.getIdentifier() interface contract
        String identifier = object.getIdentifier().toString();
        long id = (Long.valueOf(identifier)).longValue();
        AclObjectIdentity aclObjectIdentity = aclObjectIdentityDAO.findByObjectId(aclClass.getId(), id);
        // ?acl?aclaces
        // spring securityacl?
        if (aclObjectIdentity == null) {
            throw new NotFoundException("Could not found specified aclObjectIdentity.");
            //                AclImpl acl = new AclImpl(object, 0, 
            //                        aclAuthorizationStrategy, auditLogger, 
            //                        null, null, false, new GrantedAuthoritySid("ROLE_ADMIN"));
            //                acls.put(object, acl); 
            //                continue;
        }/*  ww w .j  a v a2 s . co m*/
        AclSid aclOwnerSid = aclObjectIdentity.getAclSid();
        Sid owner;

        if (aclOwnerSid.isPrincipal()) {
            owner = new PrincipalSid(aclOwnerSid.getSid());
        } else {
            owner = new GrantedAuthoritySid(aclOwnerSid.getSid());
        }
        AclImpl acl = new AclImpl(object, aclObjectIdentity.getId(), aclAuthorizationStrategy, auditLogger,
                null, null, false, owner);
        acls.put(object, acl);

        Field acesField = FieldUtils.getField(AclImpl.class, "aces");
        List aces;

        try {
            acesField.setAccessible(true);
            aces = (List) acesField.get(acl);
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException(
                    "Could not obtain AclImpl.ace field: cause[" + ex.getMessage() + "]");
        }

        List<AclEntry> aclEntrys = aclEntryDAO.findByIdentityId(aclObjectIdentity.getId());

        for (AclEntry aclEntry : aclEntrys) {
            AclSid aclSid = aclEntry.getAclSid();
            Sid recipient;
            if (aclSid.isPrincipal()) {
                recipient = new PrincipalSid(aclSid.getSid());
            } else {
                recipient = new GrantedAuthoritySid(aclSid.getSid());
            }

            int mask = aclEntry.getMask();
            Permission permission = convertMaskIntoPermission(mask);
            boolean granting = aclEntry.isGranting();
            boolean auditSuccess = aclEntry.isAuditSuccess();
            boolean auditFailure = aclEntry.isAuditFailure();

            AccessControlEntryImpl ace = new AccessControlEntryImpl(aclEntry.getId(), acl, recipient,
                    permission, granting, auditSuccess, auditFailure);

            // Add the ACE if it doesn't already exist in the ACL.aces field
            if (!aces.contains(ace)) {
                aces.add(ace);
            }
        }

    }
    return acls;
}

From source file:org.jtalks.poulpe.logic.PermissionManagerTest.java

private GroupAce buildGroupAce(Entity entity, JtalksPermission permission, boolean isGranting, Acl acl,
        Sid sid) {/*from   w ww .j a  v a2  s .c o  m*/
    AccessControlEntry accessControlEntry = new AccessControlEntryImpl(entity.getId(), acl, sid, permission,
            isGranting, false, false);
    return new GroupAce(accessControlEntry);
}

From source file:eu.europeana.aas.acl.CassandraAclService.java

/**
 * Creates an {@link AclImpl} instance out of the provided data.
 *
 * @param aclObjectIdentity the {@link AclObjectIdentity} holding the basic
 * Acl data./*from w  ww . j  a v  a 2s  .c o m*/
 * @param aclEntries a set of {@link AclEntry} objects to be converted to
 * {@link AccessControlEntry} objects.
 * @param parentAcl the parent {@link Acl}.
 * @return an {@link AclImpl} instance.
 */
private AclImpl convert(AclObjectIdentity aclObjectIdentity, Set<AclEntry> aclEntries, Acl parentAcl) {
    AclImpl acl = new AclImpl(aclObjectIdentity.toObjectIdentity(), aclObjectIdentity.getId(),
            aclAuthorizationStrategy, grantingStrategy, parentAcl, null,
            aclObjectIdentity.isEntriesInheriting(), aclObjectIdentity.getOwnerSid());

    List<AccessControlEntry> aces = new ArrayList<>(aclEntries.size());
    for (AclEntry entry : aclEntries) {
        AccessControlEntry ace = new AccessControlEntryImpl(entry.getId(), acl, entry.getSidObject(),
                permissionFactory.buildFromMask(entry.getMask()), entry.isGranting(), entry.isAuditSuccess(),
                entry.isAuditFailure());
        aces.add(entry.getOrder(), ace);
    }

    try {
        fieldAces.set(acl, aces);
    } catch (Exception e) {
        LOG.error("Could not set AccessControlEntries in the ACL", e);
    }
    return acl;
}

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

protected final AccessControlEntry toAccessControlEntry(int id, Acl acl, DBObject dbo) {
    Sid sid = toSid((DBObject) dbo.get(sidFieldName));
    Permission permission = permissionFactory
            .buildFromMask(Number.class.cast(dbo.get(maskFieldName)).intValue());
    boolean granting = (Boolean) dbo.get(grantingFieldName);
    Boolean auditSuccess = (Boolean) dbo.get(auditSuccessFieldName);
    if (auditSuccess == null) {
        auditSuccess = Boolean.FALSE;
    }/*from w  w w. ja v  a  2s.c o m*/
    Boolean auditFailure = (Boolean) dbo.get(auditFailureFieldName);
    if (auditFailure == null) {
        auditFailure = Boolean.FALSE;
    }
    return new AccessControlEntryImpl(id, acl, sid, permission, granting, auditSuccess, auditFailure);
}

From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java

private Map<ObjectIdentity, Acl> mapResults(final List<Sid> sids,
        final Map<Long, ObjectIdentity> identitiesByByteId, final Result[] results) {
    Map<ObjectIdentity, Acl> toReturn = new HashMap<ObjectIdentity, Acl>();
    for (Result result : results) {
        if (!result.isEmpty()) {
            byte[] rowKey = result.getRow();

            Long rowId = createRowId(rowKey);
            ObjectIdentity identity = identitiesByByteId.get(rowId);

            NavigableMap<byte[], byte[]> aclFamilyMap = result.getFamilyMap(ACL_FAMILY);

            AclRecord aclRecord = new AclRecord(rowKey, aclFamilyMap, resolveConverter(identity));

            List<AccessControlEntry> entries = new ArrayList<AccessControlEntry>();
            MutableAcl acl = new SimpleAcl(identity, aclRecord.getOwner(), entries, sids, util);

            NavigableMap<byte[], byte[]> aceMap = result.getFamilyMap(ACE_FAMILY);
            for (Entry<byte[], byte[]> keyValue : aceMap.entrySet()) {
                AccessControlEntryValue value = new AccessControlEntryValue(keyValue.getValue(),
                        permissionFactory);
                AccessControlEntry ace = new AccessControlEntryImpl(value.getId(), acl, value.getSid(),
                        value.getPermission(), value.isGranting(), false, false);
                entries.add(ace);//  w  w  w  .  j a v  a 2s  . c om
            }
            toReturn.put(identity, acl);
            aclCache.putInCache(acl);
        }
    }
    return toReturn;
}

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

private void genAces(List<Sid> sids, Result result, AclImpl acl) {
    List<AceInfo> aceInfos = new ArrayList<AceInfo>();
    if (null != sids) {
        // Just return aces in sids
        for (Sid sid : sids) {
            String sidName = null;
            if (sid instanceof PrincipalSid) {
                sidName = ((PrincipalSid) sid).getPrincipal();
            } else if (sid instanceof GrantedAuthoritySid) {
                sidName = ((GrantedAuthoritySid) sid).getGrantedAuthority();
            }//  w w  w  .j  a  va  2s.  c  o m

            AceInfo aceInfo = aceSerializer
                    .deserialize(result.getValue(Bytes.toBytes(ACL_ACES_FAMILY), Bytes.toBytes(sidName)));
            if (null != aceInfo) {
                aceInfos.add(aceInfo);
            }
        }
    } else {
        NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(Bytes.toBytes(ACL_ACES_FAMILY));
        for (byte[] qualifier : familyMap.keySet()) {
            AceInfo aceInfo = aceSerializer.deserialize(familyMap.get(qualifier));

            if (null != aceInfo) {
                aceInfos.add(aceInfo);
            }
        }
    }

    List<AccessControlEntry> newAces = new ArrayList<AccessControlEntry>();
    for (int i = 0; i < aceInfos.size(); i++) {
        AceInfo aceInfo = aceInfos.get(i);

        if (null != aceInfo) {
            Sid sid = aceInfo.getSidInfo().isPrincipal() ? new PrincipalSid(aceInfo.getSidInfo().getSid())
                    : new GrantedAuthoritySid(aceInfo.getSidInfo().getSid());
            AccessControlEntry ace = new AccessControlEntryImpl(Long.valueOf(i), acl, sid,
                    aclPermissionFactory.buildFromMask(aceInfo.getPermissionMask()), true, false, false);
            newAces.add(ace);
        }
    }

    this.setAces(acl, newAces);
}

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

private void genAces(List<Sid> sids, Result result, AclImpl acl)
        throws JsonParseException, JsonMappingException, IOException {
    List<AceInfo> aceInfos = new ArrayList<AceInfo>();
    if (null != sids) {
        // Just return aces in sids
        for (Sid sid : sids) {
            String sidName = null;
            if (sid instanceof PrincipalSid) {
                sidName = ((PrincipalSid) sid).getPrincipal();
            } else if (sid instanceof GrantedAuthoritySid) {
                sidName = ((GrantedAuthoritySid) sid).getGrantedAuthority();
            }//w  w  w .ja  va 2 s. c o m

            AceInfo aceInfo = aceSerializer.deserialize(
                    result.getValue(Bytes.toBytes(AclHBaseStorage.ACL_ACES_FAMILY), Bytes.toBytes(sidName)));
            if (null != aceInfo) {
                aceInfos.add(aceInfo);
            }
        }
    } else {
        NavigableMap<byte[], byte[]> familyMap = result
                .getFamilyMap(Bytes.toBytes(AclHBaseStorage.ACL_ACES_FAMILY));
        for (byte[] qualifier : familyMap.keySet()) {
            AceInfo aceInfo = aceSerializer.deserialize(familyMap.get(qualifier));

            if (null != aceInfo) {
                aceInfos.add(aceInfo);
            }
        }
    }

    List<AccessControlEntry> newAces = new ArrayList<AccessControlEntry>();
    for (int i = 0; i < aceInfos.size(); i++) {
        AceInfo aceInfo = aceInfos.get(i);

        if (null != aceInfo) {
            Sid sid = aceInfo.getSidInfo().isPrincipal() ? new PrincipalSid(aceInfo.getSidInfo().getSid())
                    : new GrantedAuthoritySid(aceInfo.getSidInfo().getSid());
            AccessControlEntry ace = new AccessControlEntryImpl(Long.valueOf(i), acl, sid,
                    aclPermissionFactory.buildFromMask(aceInfo.getPermissionMask()), true, false, false);
            newAces.add(ace);
        }
    }

    this.setAces(acl, newAces);
}