public void setValues(PreparedStatement ps) throws SQLException { int i = 0; for (ObjectIdentity oid : objectIdentities) { // Determine prepared statement values for this iteration String type = oid.getType(); // No need to check for nulls, as guaranteed non-null by // ObjectIdentity.getIdentifier() interface contract String identifier = oid.getIdentifier().toString(); // Inject values ps.setString((2 * i) + 1, identifier); ps.setString((2 * i) + 2, type); i++; } } }, new ProcessResultSet(acls, sids));
public ObjectIdentityImpl(ObjectIdentity oid) { this(oid.getType(), String.valueOf(oid.getIdentifier())); }
/** * Important so caching operates properly. * <p> * Considers an object of the same class equal if it has the same * <code>classname</code> and <code>id</code> properties. * <p> * Numeric identities (Integer and Long values) are considered equal if they are * numerically equal. Other serializable types are evaluated using a simple equality. * * @param arg0 object to compare * * @return <code>true</code> if the presented object matches this object */ public boolean equals(Object arg0) { if (arg0 == null || !(arg0 instanceof ObjectIdentity)) { return false; } ObjectIdentity other = (ObjectIdentity) arg0; if (!identifier.equals(other.getIdentifier())) { return false; } return type.equals(other.getType()); }
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) { Object[] args = { parentIdentity.getIdentifier().toString(), parentIdentity.getType() }; List<ObjectIdentity> objects = jdbcOperations.query(findChildrenSql, args, new RowMapper<ObjectIdentity>() { 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); } }); if (objects.size() == 0) { return null; } return objects; }
/** * Retrieves the primary key from the acl_object_identity table for the passed * ObjectIdentity. Unlike some other methods in this implementation, this method will * NOT create a row (use {@link #createObjectIdentity(ObjectIdentity, Sid)} instead). * * @param oid to find * * @return the object identity or null if not found */ protected Long retrieveObjectIdentityPrimaryKey(ObjectIdentity oid) { try { return jdbcOperations.queryForObject(selectObjectIdentityPrimaryKey, Long.class, oid.getType(), oid.getIdentifier().toString()); } catch (DataAccessException notFound) { return null; } }
/** * Creates an entry in the acl_object_identity table for the passed ObjectIdentity. * The Sid is also necessary, as acl_object_identity has defined the sid column as * non-null. * * @param object to represent an acl_object_identity for * @param owner for the SID column (will be created if there is no acl_sid entry for * this particular Sid already) */ protected void createObjectIdentity(ObjectIdentity object, Sid owner) { Long sidId = createOrRetrieveSidPrimaryKey(owner, true); Long classId = createOrRetrieveClassPrimaryKey(object.getType(), true, object.getIdentifier().getClass()); jdbcOperations.update(insertObjectIdentity, classId, object.getIdentifier().toString(), sidId, Boolean.TRUE); }
@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 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 public void findChildrenWithoutIdType() { ObjectIdentity objectIdentity = new ObjectIdentityImpl(MockLongIdDomainObject.class, 4711L); List<ObjectIdentity> objectIdentities = aclServiceIntegration.findChildren(objectIdentity); assertThat(objectIdentities.size()).isEqualTo(1); assertThat(objectIdentities.get(0).getType()).isEqualTo(MockUntypedIdDomainObject.class.getName()); assertThat(objectIdentities.get(0).getIdentifier()).isEqualTo(5000L); }
@Test public void findChildrenOfIdTypeUUID() { ObjectIdentity objectIdentity = new ObjectIdentityImpl(MockUntypedIdDomainObject.class, 5000L); aclServiceIntegration.setAclClassIdSupported(true); List<ObjectIdentity> objectIdentities = aclServiceIntegration.findChildren(objectIdentity); assertThat(objectIdentities.size()).isEqualTo(1); assertThat(objectIdentities.get(0).getType()).isEqualTo("costcenter"); assertThat(objectIdentities.get(0).getIdentifier()).isEqualTo(UUID.fromString("25d93b3f-c3aa-4814-9d5e-c7c96ced7762")); }
@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"); }
/** * Make id fot type of identity (ignore object.identifier). * @param object * @return */ public static String toTypeId(ObjectIdentity object) { Assert.notNull(object, "ObjectIdentity is null"); String type = object.getType(); return toTypeId(type); }
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"); Serializable identifier = (Serializable) rs.getObject("obj_id"); identifier = aclClassIdUtils.identifierFrom(identifier, rs); return new ObjectIdentityImpl(javaType, identifier); } }); if (objects.size() == 0) { return null; } return objects; }
public void setValues(PreparedStatement ps) throws SQLException { int i = 0; for (ObjectIdentity oid : objectIdentities) { // Determine prepared statement values for this iteration String type = oid.getType(); // No need to check for nulls, as guaranteed non-null by // ObjectIdentity.getIdentifier() interface contract String identifier = oid.getIdentifier().toString(); // Inject values ps.setString((2 * i) + 1, identifier); ps.setString((2 * i) + 2, type); i++; } } }, new ProcessResultSet(acls, sids));
public static String toId(ObjectIdentity object) { Assert.notNull(object, "ObjectIdentity is null"); Object idsrc = object.getIdentifier(); Assert.notNull(idsrc, "identifier is null"); String type = object.getType(); return toId(type, idsrc); }
public static ObjectIdentityData from(ObjectIdentity objectIdentity) { if(objectIdentity == null || objectIdentity instanceof ObjectIdentityData) { return (ObjectIdentityData) objectIdentity; } return new ObjectIdentityData(objectIdentity.getType(), objectIdentity.getIdentifier()); }
@Transactional public AclSecuredObjectIdentityData getAclSecuredObjectIdentity(ObjectIdentity objectIdentity) { AclSecuredClassDescriptionData aclClass = aclSecuredClassDao.loadOrCreate(objectIdentity.getType()); // No need to check for nulls, as guaranteed non-null by // ObjectIdentity.getIdentifier() interface contract String identifier = objectIdentity.getIdentifier().toString(); long id = (Long.valueOf(identifier)).longValue(); AclSecuredObjectIdentityData aclObjectIdentity = aclObjectIdentityDao.findByObjectId(aclClass.getId(), id); return aclObjectIdentity; }
@Override public boolean hasPermission(ObjectIdentity objectIdentity, Permission action) { if (SecurityUtils.currentUserIsSuOrSystem()) { return true; } else { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && permissionEvaluator.hasPermission( authentication, objectIdentity.getIdentifier(), objectIdentity.getType(), getCumulativePermissionToCheck(action)); } }
@Transactional public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException { AclSecuredClassDescriptionData aclClass = aclSecuredClassDao.load(objectIdentity.getType()); if (aclClass == null) { return; } // No need to check for nulls, as guaranteed non-null by // ObjectIdentity.getIdentifier() interface contract String identifier = objectIdentity.getIdentifier().toString(); long id = (Long.valueOf(identifier)).longValue(); AclSecuredObjectIdentityData aclObjectIdentity = aclObjectIdentityDao.findByObjectId(aclClass.getId(), id); if (aclObjectIdentity != null) { removeAcl(aclObjectIdentity); aclCache.evictFromCache(objectIdentity); } }