Example usage for org.springframework.security.acls.model ObjectIdentity getIdentifier

List of usage examples for org.springframework.security.acls.model ObjectIdentity getIdentifier

Introduction

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

Prototype

Serializable getIdentifier();

Source Link

Document

Obtains the actual identifier.

Usage

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

@Test
public void creatingIdentityWithByteArrayIdentifier() {
    NavigableMap<byte[], byte[]> familyMap = recordMap(byte[].class, false);
    AclRecord underTest = new AclRecord(ID.getBytes(), familyMap, null);

    ObjectIdentity returnedIdentity = underTest.getIdentity();
    assertEquals(TYPE, returnedIdentity.getType());
    assertTrue(ArrayUtils.isEquals(ID.getBytes(), returnedIdentity.getIdentifier()));
    assertTrue(ArrayUtils.isEquals(ID.getBytes(), underTest.getKey()));
    assertTrue(ArrayUtils.isEquals(byte[].class.getName().getBytes(), underTest.getIdTypeBytes()));
    assertEquals(new GrantedAuthoritySid(SOME_PRINCIPAL), underTest.getOwner());
}

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

@Test
public void testReadAclsByIdUsingMapping() {
    when(mapper.getMapping(c1.class.getCanonicalName())).thenReturn(c2.class);

    ObjectIdentity mappedIdentity = mock(ObjectIdentity.class);
    when(mappedIdentity.getType()).thenReturn(c2.class.getCanonicalName());
    when(mappedIdentity.getIdentifier()).thenReturn(1L);
    List<ObjectIdentity> mappedObjects = new ArrayList<ObjectIdentity>();
    mappedObjects.add(mappedIdentity);//from   w w w. jav  a2  s.c om

    Map<ObjectIdentity, Acl> result = sut.readAclsById(objects, sids);

    ObjectIdentity actualArgument = stragegyCallArgument.get(0);
    assertEquals(actualArgument.getType(), mappedIdentity.getType());
    assertEquals(actualArgument.getIdentifier(), mappedIdentity.getIdentifier());
    assertEquals(result.keySet().iterator().next().getType(), c1.class.getCanonicalName());
}

From source file:com.excilys.ebi.bank.service.impl.security.BankAclService.java

@Override
@Cacheable(cacheName = IConstants.Cache.ACL_CACHE, keyGenerator = @KeyGenerator(name = "StringCacheKeyGenerator"))
@Transactional(readOnly = true)// w ww .  j  ava  2 s.  co m
public Acl readAclById(ObjectIdentity object, List<Sid> sids) throws NotFoundException {

    SimpleAclImpl acl = new SimpleAclImpl(object);

    logger.info("type={} id={}", object.getType(), object.getIdentifier());

    for (Sid sid : sids) {
        if (sid instanceof GrantedAuthoritySid
                && GrantedAuthoritySid.class.cast(sid).getGrantedAuthority().equals(Role.ROLE_ADMIN.name())) {
            acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.READ, true));
            acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.WRITE, true));
            acl.getEntries()
                    .add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.ADMINISTRATION, true));

        } else if (sid instanceof PrincipalSid) {
            Integer accountId = Integer.class.cast(object.getIdentifier());
            String login = ((PrincipalSid) sid).getPrincipal();
            Assert.notNull(accountId, "accountId is required");
            Assert.notNull(login, "login is required");

            if (accountDao.isAccountOfUser(accountId, login)) {
                acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.READ, true));
                acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.WRITE, true));
            }
        }
    }

    return acl;
}

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

@Test
public void testMultipleDtoOnSameEntityMappings() {
    when(mapper.getMapping(c1.class.getCanonicalName())).thenReturn(c2.class);
    when(mapper.getMapping(c3.class.getCanonicalName())).thenReturn(c2.class);

    ObjectIdentity mappedIdentity = mock(ObjectIdentity.class);
    when(mappedIdentity.getType()).thenReturn(c1.class.getCanonicalName());
    when(mappedIdentity.getIdentifier()).thenReturn(1L);
    ObjectIdentity secondMappedIdentity = mock(ObjectIdentity.class);
    when(secondMappedIdentity.getType()).thenReturn(c3.class.getCanonicalName());
    when(secondMappedIdentity.getIdentifier()).thenReturn(1L);
    List<ObjectIdentity> mappedObjects = new ArrayList<ObjectIdentity>();
    mappedObjects.add(mappedIdentity);//from  w  w  w. j  ava2  s  .  c o m
    mappedObjects.add(secondMappedIdentity);

    Map<ObjectIdentity, Acl> result = sut.readAclsById(mappedObjects, sids);

    assertEquals(stragegyCallArgument.size(), mappedObjects.size());
    assertEquals(stragegyCallArgument.get(0).getType(), c2.class.getCanonicalName());
    assertEquals(stragegyCallArgument.get(1).getType(), c2.class.getCanonicalName());
    assertTrue(result.containsKey(mappedIdentity));
    assertTrue(result.containsKey(secondMappedIdentity));
}

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

protected DBObject toDBObject(ObjectIdentity oid) {
    return new BasicDBObject(classFieldName, oid.getType()).append(identityFieldName, oid.getIdentifier());
}

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

/**
 * Complete constructor for when we want to construct the acl with all details we need to persist.
 * /*w ww  .  jav a  2 s .  co  m*/
 * The converter is required for all identifier types except byte[] although several key types are already
 * catered for via the default converters in {@link HBaseACLRepository}
 * 
 * N.B. The converter is required to be configured with a class exactly matching the stored id type
 * 
 * To configure the converter see {@link HBaseACLRepository}.
 * 
 * @param identity
 * @param converter
 */
public AclRecord(final ObjectIdentity identity, final Sid owner, final AclIdentifierConverter<?> converter) {
    this.identity = identity;
    this.key = createKey(identity.getIdentifier(), converter);
    this.owner = owner;
}

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

@Override
public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
    Assert.notNull(objectIdentity, "Object Identity required");
    Assert.notNull(objectIdentity.getIdentifier(), "Object Identity doesn't provide an identifier");

    if (deleteChildren) {
        LOG.trace(ACL, "Recursively removing all the child acl entries.");

        List<ObjectIdentity> children = findChildren(objectIdentity);
        if (children != null) {
            for (ObjectIdentity child : children) {
                deleteAcl(child, true);/*from   ww w . j  a  va2s  . c  o m*/
            }
        }
    } else if (findChildren(objectIdentity) != null) {
        LOG.warn(ACL, "Children exists for object identity {}.", objectIdentity);

        throw new ChildrenExistException("Children exists for object identity " + objectIdentity);
    }

    LOG.debug(ACL, "Removing object identity {} from acl", objectIdentity);

    getAclCollection().remove(queryByObjectIdentity(objectIdentity), writeConcern);

    LOG.trace(ACL, "Evict the object identity {} from cache", objectIdentity);

    aclCache.evictFromCache(objectIdentity);
}

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

@Override
public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
    Assert.notNull(objectIdentity, "Object Identity required");
    Assert.notNull(objectIdentity.getIdentifier(), "Object Identity doesn't provide an identifier");

    if (LOG.isDebugEnabled()) {
        LOG.debug("BEGIN deleteAcl: objectIdentity: " + objectIdentity + ", deleteChildren: " + deleteChildren);
    }/*w  ww  . j  ava2  s. c  o m*/

    List<AclObjectIdentity> objIdsToDelete = new ArrayList<>();
    List<ObjectIdentity> objectsToDelete = new ArrayList<>();
    objectsToDelete.add(objectIdentity);

    List<ObjectIdentity> children = findChildren(objectIdentity);
    if (deleteChildren) {
        for (ObjectIdentity child : children) {
            objectsToDelete.addAll(calculateChildrenReccursively(child));
        }
    } else if (children != null && !children.isEmpty()) {
        throw new ChildrenExistException(
                "Cannot delete '" + objectIdentity + "' (has " + children.size() + " children)");
    }

    for (ObjectIdentity objId : objectsToDelete) {
        objIdsToDelete.add(new AclObjectIdentity(objId));
    }
    aclRepository.deleteAcls(objIdsToDelete);

    // Clear the cache
    if (aclCache != null) {
        for (ObjectIdentity obj : objectsToDelete) {
            aclCache.evictFromCache(obj);
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("END deleteAcl");
    }
}

From source file:org.jtalks.common.security.DtoLookupStrategy.java

/**
 * This method returns {@link ObjectIdentity} mapped to provided one using the following logic:
 * <ul>//from w  ww.  java2s  .  com
 * <li>If no mapping found for the identity type, same object is returned;</li>
 * <li>Instead, a new {@link ObjectIdentity} is created with the type mapped to the type of the original
 * identity and with the same identifier.</li>
 * </ul>
 *
 * @param identity Original identity
 * @return Mapped identity as described above.
 */
private ObjectIdentity getMappedIdentity(ObjectIdentity identity) {
    ObjectIdentity result = identity;

    String identityClass = identity.getType();
    Class identityMappedTo = mapper.getMapping(identityClass);
    if (identityMappedTo != null) {
        result = new ObjectIdentityImpl(identityMappedTo.getCanonicalName(), identity.getIdentifier());
    }

    return result;
}

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

private AclIdentifierConverter<?> resolveConverter(final ObjectIdentity identity) {
    Serializable identifier = identity.getIdentifier();
    Assert.notNull(identifier, "Identifier must not be null");
    Class<? extends Serializable> identifierClass = Primitives.wrap(identifier.getClass());
    return aclIdentifierConverters.get(identifierClass);
}