Search in sources :

Example 11 with ObjectIdentity

use of org.springframework.security.acls.model.ObjectIdentity in project spring-security by spring-projects.

the class ObjectIdentityImplTests method equalStringIdsAreEqualAndHaveSameHashcode.

@Test
public void equalStringIdsAreEqualAndHaveSameHashcode() throws Exception {
    ObjectIdentity obj = new ObjectIdentityImpl(Object.class, "1000");
    ObjectIdentity obj2 = new ObjectIdentityImpl(Object.class, "1000");
    assertThat(obj2).isEqualTo(obj);
    assertThat(obj2.hashCode()).isEqualTo(obj.hashCode());
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) Test(org.junit.Test)

Example 12 with ObjectIdentity

use of org.springframework.security.acls.model.ObjectIdentity in project spring-security by spring-projects.

the class ObjectIdentityImplTests method longAndIntegerIdsWithSameValueAreEqualAndHaveSameHashcode.

@Test
public void longAndIntegerIdsWithSameValueAreEqualAndHaveSameHashcode() {
    ObjectIdentity obj = new ObjectIdentityImpl(Object.class, new Long(5));
    ObjectIdentity obj2 = new ObjectIdentityImpl(Object.class, Integer.valueOf(5));
    assertThat(obj2).isEqualTo(obj);
    assertThat(obj2.hashCode()).isEqualTo(obj.hashCode());
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) Test(org.junit.Test)

Example 13 with ObjectIdentity

use of org.springframework.security.acls.model.ObjectIdentity in project spring-security by spring-projects.

the class ObjectIdentityImplTests method testEquals.

@Test
public void testEquals() throws Exception {
    ObjectIdentity obj = new ObjectIdentityImpl(DOMAIN_CLASS, Long.valueOf(1));
    MockIdDomainObject mockObj = new MockIdDomainObject();
    mockObj.setId(Long.valueOf(1));
    String string = "SOME_STRING";
    assertThat(string).isNotSameAs(obj);
    assertThat(obj.equals(null)).isFalse();
    assertThat(obj.equals("DIFFERENT_OBJECT_TYPE")).isFalse();
    assertThat(obj.equals(new ObjectIdentityImpl(DOMAIN_CLASS, Long.valueOf(2)))).isFalse();
    assertThat(obj).isNotEqualTo(new ObjectIdentityImpl("org.springframework.security.acls.domain.ObjectIdentityImplTests$MockOtherIdDomainObject", Long.valueOf(1)));
    assertThat(new ObjectIdentityImpl(DOMAIN_CLASS, 1L)).isEqualTo(obj);
    assertThat(new ObjectIdentityImpl(mockObj)).isEqualTo(obj);
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) Test(org.junit.Test)

Example 14 with ObjectIdentity

use of org.springframework.security.acls.model.ObjectIdentity in project spring-security by spring-projects.

the class BasicLookupStrategyTests method testReadAllObjectIdentitiesWhenLastElementIsAlreadyCached.

/**
	 * Test created from SEC-590.
	 */
@Test
public void testReadAllObjectIdentitiesWhenLastElementIsAlreadyCached() throws Exception {
    String query = "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (4,2,104,null,1,1);" + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (5,2,105,4,1,1);" + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (6,2,106,4,1,1);" + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (7,2,107,5,1,1);" + "INSERT INTO acl_entry(ID,ACL_OBJECT_IDENTITY,ACE_ORDER,SID,MASK,GRANTING,AUDIT_SUCCESS,AUDIT_FAILURE) VALUES (5,4,0,1,1,1,0,0)";
    jdbcTemplate.execute(query);
    ObjectIdentity grandParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(104));
    ObjectIdentity parent1Oid = new ObjectIdentityImpl(TARGET_CLASS, new Long(105));
    ObjectIdentity parent2Oid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(106));
    ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(107));
    // First lookup only child, thus populating the cache with grandParent,
    // parent1
    // and child
    List<Permission> checkPermission = Arrays.asList(BasePermission.READ);
    List<Sid> sids = Arrays.asList(BEN_SID);
    List<ObjectIdentity> childOids = Arrays.asList(childOid);
    strategy.setBatchSize(6);
    Map<ObjectIdentity, Acl> foundAcls = strategy.readAclsById(childOids, sids);
    Acl foundChildAcl = foundAcls.get(childOid);
    assertThat(foundChildAcl).isNotNull();
    assertThat(foundChildAcl.isGranted(checkPermission, sids, false)).isTrue();
    // Search for object identities has to be done in the following order:
    // last
    // element have to be one which
    // is already in cache and the element before it must not be stored in
    // cache
    List<ObjectIdentity> allOids = Arrays.asList(grandParentOid, parent1Oid, parent2Oid, childOid);
    try {
        foundAcls = strategy.readAclsById(allOids, sids);
    } catch (NotFoundException notExpected) {
        fail("It shouldn't have thrown NotFoundException");
    }
    Acl foundParent2Acl = foundAcls.get(parent2Oid);
    assertThat(foundParent2Acl).isNotNull();
    assertThat(foundParent2Acl.isGranted(checkPermission, sids, false)).isTrue();
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Permission(org.springframework.security.acls.model.Permission) NotFoundException(org.springframework.security.acls.model.NotFoundException) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl) Sid(org.springframework.security.acls.model.Sid)

Example 15 with ObjectIdentity

use of org.springframework.security.acls.model.ObjectIdentity in project spring-security by spring-projects.

the class BasicLookupStrategyTests method testAllParentsAreRetrievedWhenChildIsLoaded.

@Test
public void testAllParentsAreRetrievedWhenChildIsLoaded() throws Exception {
    String query = "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (4,2,103,1,1,1);";
    jdbcTemplate.execute(query);
    ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100));
    ObjectIdentity middleParentOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(101));
    ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(102));
    ObjectIdentity middleParent2Oid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(103));
    // Retrieve the child
    Map<ObjectIdentity, Acl> map = this.strategy.readAclsById(Arrays.asList(childOid), null);
    // Check that the child and all its parents were retrieved
    assertThat(map.get(childOid)).isNotNull();
    assertThat(map.get(childOid).getObjectIdentity()).isEqualTo(childOid);
    assertThat(map.get(middleParentOid)).isNotNull();
    assertThat(map.get(middleParentOid).getObjectIdentity()).isEqualTo(middleParentOid);
    assertThat(map.get(topParentOid)).isNotNull();
    assertThat(map.get(topParentOid).getObjectIdentity()).isEqualTo(topParentOid);
    // The second parent shouldn't have been retrieved
    assertThat(map.get(middleParent2Oid)).isNull();
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl)

Aggregations

ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)46 MutableAcl (org.springframework.security.acls.model.MutableAcl)22 Test (org.junit.Test)21 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)19 Acl (org.springframework.security.acls.model.Acl)16 Authentication (org.springframework.security.core.Authentication)12 Sid (org.springframework.security.acls.model.Sid)11 NotFoundException (org.springframework.security.acls.model.NotFoundException)10 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)8 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)8 Permission (org.springframework.security.acls.model.Permission)7 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)6 Transactional (org.springframework.transaction.annotation.Transactional)5 BasePermission (org.springframework.security.acls.domain.BasePermission)4 ObjectIdentityRetrievalStrategy (org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy)4 HashMap (java.util.HashMap)3 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)3 AccessControlEntry (org.springframework.security.acls.model.AccessControlEntry)3 AclService (org.springframework.security.acls.model.AclService)3 SidRetrievalStrategy (org.springframework.security.acls.model.SidRetrievalStrategy)3