public ObjectIdentity mapRow(ResultSet rs, int rowNum) throws SQLException { String javaType = rs.getString("class"); Serializable identifier = (Serializable) rs.getObject("obj_id"); identifier = aclClassIdUtils.identifierFrom(identifier, rs); return new ObjectIdentityImpl(javaType, identifier); } });
@Test public void stringAndNumericIdsAreNotEqual() throws Exception { ObjectIdentity obj = new ObjectIdentityImpl(Object.class, "1000"); ObjectIdentity obj2 = new ObjectIdentityImpl(Object.class, Long.valueOf(1000)); assertThat(obj).isNotEqualTo(obj2); }
@Test public void testAclsRetrievalWithDefaultBatchSize() throws Exception { ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(100)); ObjectIdentity middleParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(101)); // Deliberately use an integer for the child, to reproduce bug report in SEC-819 ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(102)); Map<ObjectIdentity, Acl> map = this.strategy .readAclsById(Arrays.asList(topParentOid, middleParentOid, childOid), null); checkEntries(topParentOid, middleParentOid, childOid, map); }
@Test public void testAclsRetrievalWithCustomBatchSize() throws Exception { ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(100)); ObjectIdentity middleParentOid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(101)); ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(102)); // Set a batch size to allow multiple database queries in order to retrieve all // acls this.strategy.setBatchSize(1); Map<ObjectIdentity, Acl> map = this.strategy .readAclsById(Arrays.asList(topParentOid, middleParentOid, childOid), null); checkEntries(topParentOid, middleParentOid, childOid, map); }
@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()); }
@Test public void testReadObjectIdentityUsingLongTypeWithConversionServiceEnabled() { ObjectIdentity oid = new ObjectIdentityImpl(TARGET_CLASS, new Long(100)); Map<ObjectIdentity, Acl> foundAcls = uuidEnabledStrategy.readAclsById(Arrays.asList(oid), Arrays.asList(BEN_SID)); Assert.assertEquals(1, foundAcls.size()); Assert.assertNotNull(foundAcls.get(oid)); }
@Test public void testReadObjectIdentityUsingUuidType() { ObjectIdentity oid = new ObjectIdentityImpl(TARGET_CLASS_WITH_UUID, OBJECT_IDENTITY_UUID); Map<ObjectIdentity, Acl> foundAcls = uuidEnabledStrategy.readAclsById(Arrays.asList(oid), Arrays.asList(BEN_SID)); Assert.assertEquals(1, foundAcls.size()); Assert.assertNotNull(foundAcls.get(oid)); }
@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()); }
@Test public void gettersReturnExpectedValues() throws Exception { ObjectIdentity obj = new ObjectIdentityImpl(DOMAIN_CLASS, Long.valueOf(1)); assertThat(obj.getIdentifier()).isEqualTo(Long.valueOf(1)); assertThat(obj.getType()).isEqualTo(MockIdDomainObject.class.getName()); }
@Test(expected = ConversionFailedException.class) public void testReadObjectIdentityUsingNonUuidInDatabase() { ObjectIdentity oid = new ObjectIdentityImpl(TARGET_CLASS_WITH_UUID, OBJECT_IDENTITY_LONG_AS_UUID); uuidEnabledStrategy.readAclsById(Arrays.asList(oid), Arrays.asList(BEN_SID)); } }
@Test public void findChildrenOfIdTypeLong() { ObjectIdentity objectIdentity = new ObjectIdentityImpl("location", "US-PAL"); List<ObjectIdentity> objectIdentities = aclServiceIntegration.findChildren(objectIdentity); assertThat(objectIdentities.size()).isEqualTo(2); assertThat(objectIdentities.get(0).getType()).isEqualTo(MockLongIdDomainObject.class.getName()); assertThat(objectIdentities.get(0).getIdentifier()).isEqualTo(4711L); assertThat(objectIdentities.get(1).getType()).isEqualTo(MockLongIdDomainObject.class.getName()); assertThat(objectIdentities.get(1).getIdentifier()).isEqualTo(4712L); }
@Test(expected = IllegalArgumentException.class) public void nullOwnerIsNotSupported() { String query = "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (6,2,104,null,null,1);"; getJdbcTemplate().execute(query); ObjectIdentity oid = new ObjectIdentityImpl(TARGET_CLASS, new Long(104)); strategy.readAclsById(Arrays.asList(oid), Arrays.asList(BEN_SID)); }
@Test public void hashcodeIsDifferentForDifferentJavaTypes() throws Exception { ObjectIdentity obj = new ObjectIdentityImpl(Object.class, Long.valueOf(1)); ObjectIdentity obj2 = new ObjectIdentityImpl(String.class, Long.valueOf(1)); assertThat(obj.hashCode()).isNotEqualTo(obj2.hashCode()); }
@Test public void findChildrenOfIdTypeString() { ObjectIdentity objectIdentity = new ObjectIdentityImpl("location", "US"); aclServiceIntegration.setAclClassIdSupported(true); List<ObjectIdentity> objectIdentities = aclServiceIntegration.findChildren(objectIdentity); assertThat(objectIdentities.size()).isEqualTo(1); assertThat(objectIdentities.get(0).getType()).isEqualTo("location"); assertThat(objectIdentities.get(0).getIdentifier()).isEqualTo("US-PAL"); }
@Test @Transactional public void identityWithUuidIdIsSupportedByCreateAcl() throws Exception { SecurityContextHolder.getContext().setAuthentication(getAuth()); UUID id = UUID.randomUUID(); ObjectIdentity oid = new ObjectIdentityImpl(TARGET_CLASS_WITH_UUID, id); getJdbcMutableAclService().createAcl(oid); assertThat(getJdbcMutableAclService().readAclById(new ObjectIdentityImpl( TARGET_CLASS_WITH_UUID, id))).isNotNull(); } }
@Test public void testObjectIdentityCreation() throws Exception { MockIdDomainObject domain = new MockIdDomainObject(); domain.setId(Integer.valueOf(1)); ObjectIdentityRetrievalStrategy retStrategy = new ObjectIdentityRetrievalStrategyImpl(); ObjectIdentity identity = retStrategy.getObjectIdentity(domain); assertThat(identity).isNotNull(); assertThat(new ObjectIdentityImpl(domain)).isEqualTo(identity); }
@Test public void findNoChildren() { ObjectIdentity objectIdentity = new ObjectIdentityImpl(MockLongIdDomainObject.class, 1L); List<ObjectIdentity> objectIdentities = aclService.findChildren(objectIdentity); assertThat(objectIdentities).isNull(); }
@Test public void findChildrenForUnknownObject() { ObjectIdentity objectIdentity = new ObjectIdentityImpl(Object.class, 33); List<ObjectIdentity> objectIdentities = aclServiceIntegration.findChildren(objectIdentity); assertThat(objectIdentities).isNull(); }
@Test(expected = NotFoundException.class) public void readAclByIdMissingAcl() { Map<ObjectIdentity, Acl> result = new HashMap<>(); when( lookupStrategy.readAclsById(anyList(), anyList())).thenReturn(result); ObjectIdentity objectIdentity = new ObjectIdentityImpl(Object.class, 1); List<Sid> sids = Arrays.<Sid>asList(new PrincipalSid("user")); aclService.readAclById(objectIdentity, sids); }
@Before public void setup() { myCache = new EhCacheBasedAclCache(cache, new DefaultPermissionGrantingStrategy( new ConsoleAuditLogger()), new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_USER"))); ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100)); AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); acl = new AclImpl(identity, Long.valueOf(1), aclAuthorizationStrategy, new ConsoleAuditLogger()); }