Search in sources :

Example 6 with ObjectIdentityImpl

use of org.springframework.security.acls.domain.ObjectIdentityImpl 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 7 with ObjectIdentityImpl

use of org.springframework.security.acls.domain.ObjectIdentityImpl in project spring-security by spring-projects.

the class JdbcAclService method findChildren.

// ~ Methods
// ========================================================================================================
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
    Object[] args = { parentIdentity.getIdentifier(), parentIdentity.getType() };
    List<ObjectIdentity> objects = jdbcTemplate.query(findChildrenSql, args, new RowMapper<ObjectIdentity>() {

        public ObjectIdentity mapRow(ResultSet rs, int rowNum) throws SQLException {
            String javaType = rs.getString("class");
            Long identifier = new Long(rs.getLong("obj_id"));
            return new ObjectIdentityImpl(javaType, identifier);
        }
    });
    if (objects.size() == 0) {
        return null;
    }
    return objects;
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) SQLException(java.sql.SQLException) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) ResultSet(java.sql.ResultSet)

Example 8 with ObjectIdentityImpl

use of org.springframework.security.acls.domain.ObjectIdentityImpl in project spring-security by spring-projects.

the class AclPermissionCacheOptimizerTests method eagerlyLoadsRequiredAcls.

@Test
public void eagerlyLoadsRequiredAcls() throws Exception {
    AclService service = mock(AclService.class);
    AclPermissionCacheOptimizer pco = new AclPermissionCacheOptimizer(service);
    ObjectIdentityRetrievalStrategy oidStrat = mock(ObjectIdentityRetrievalStrategy.class);
    SidRetrievalStrategy sidStrat = mock(SidRetrievalStrategy.class);
    pco.setObjectIdentityRetrievalStrategy(oidStrat);
    pco.setSidRetrievalStrategy(sidStrat);
    Object[] dos = { new Object(), null, new Object() };
    ObjectIdentity[] oids = { new ObjectIdentityImpl("A", "1"), new ObjectIdentityImpl("A", "2") };
    when(oidStrat.getObjectIdentity(dos[0])).thenReturn(oids[0]);
    when(oidStrat.getObjectIdentity(dos[2])).thenReturn(oids[1]);
    pco.cachePermissionsFor(mock(Authentication.class), Arrays.asList(dos));
    // AclService should be invoked with the list of required Oids
    verify(service).readAclsById(eq(Arrays.asList(oids)), any(List.class));
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Authentication(org.springframework.security.core.Authentication) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) List(java.util.List) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) AclService(org.springframework.security.acls.model.AclService) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Test(org.junit.Test)

Example 9 with ObjectIdentityImpl

use of org.springframework.security.acls.domain.ObjectIdentityImpl in project spring-security by spring-projects.

the class JdbcMutableAclServiceTests method createAclForADuplicateDomainObject.

@Test
@Transactional
public void createAclForADuplicateDomainObject() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(auth);
    ObjectIdentity duplicateOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100));
    jdbcMutableAclService.createAcl(duplicateOid);
    // Try to add the same object second time
    try {
        jdbcMutableAclService.createAcl(duplicateOid);
        fail("It should have thrown AlreadyExistsException");
    } catch (AlreadyExistsException expected) {
    }
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) AlreadyExistsException(org.springframework.security.acls.model.AlreadyExistsException) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ObjectIdentityImpl

use of org.springframework.security.acls.domain.ObjectIdentityImpl in project spring-security by spring-projects.

the class JdbcMutableAclServiceTests method childrenAreClearedFromCacheWhenParentisUpdated2.

/**
	 * SEC-655
	 */
@Test
@Transactional
public void childrenAreClearedFromCacheWhenParentisUpdated2() throws Exception {
    Authentication auth = new TestingAuthenticationToken("system", "secret", "ROLE_IGNORED");
    SecurityContextHolder.getContext().setAuthentication(auth);
    ObjectIdentityImpl rootObject = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(1));
    MutableAcl parent = jdbcMutableAclService.createAcl(rootObject);
    MutableAcl child = jdbcMutableAclService.createAcl(new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2)));
    child.setParent(parent);
    jdbcMutableAclService.updateAcl(child);
    parent.insertAce(0, BasePermission.ADMINISTRATION, new GrantedAuthoritySid("ROLE_ADMINISTRATOR"), true);
    jdbcMutableAclService.updateAcl(parent);
    parent.insertAce(1, BasePermission.DELETE, new PrincipalSid("terry"), true);
    jdbcMutableAclService.updateAcl(parent);
    child = (MutableAcl) jdbcMutableAclService.readAclById(new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2)));
    parent = (MutableAcl) child.getParentAcl();
    assertThat(parent.getEntries()).hasSize(2);
    assertThat(parent.getEntries().get(0).getPermission().getMask()).isEqualTo(16);
    assertThat(parent.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_ADMINISTRATOR"));
    assertThat(parent.getEntries().get(1).getPermission().getMask()).isEqualTo(8);
    assertThat(parent.getEntries().get(1).getSid()).isEqualTo(new PrincipalSid("terry"));
}
Also used : GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) Authentication(org.springframework.security.core.Authentication) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) MutableAcl(org.springframework.security.acls.model.MutableAcl) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)24 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)19 Test (org.junit.Test)13 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)7 Authentication (org.springframework.security.core.Authentication)5 Transactional (org.springframework.transaction.annotation.Transactional)5 BasePermission (org.springframework.security.acls.domain.BasePermission)3 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)3 NotFoundException (org.springframework.security.acls.model.NotFoundException)3 Permission (org.springframework.security.acls.model.Permission)3 Sid (org.springframework.security.acls.model.Sid)3 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3 HashMap (java.util.HashMap)2 AclImpl (org.springframework.security.acls.domain.AclImpl)2 Acl (org.springframework.security.acls.model.Acl)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1