private static String objID(ObjectIdentity domainObjId) { return String.valueOf(domainObjId.getIdentifier()); }
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())); }
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; }
/** * 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()); }
/** * 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); }
/** * 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; } }
@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 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 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"); }
@Test public void findOneChildren() { List<ObjectIdentity> result = new ArrayList<>(); result.add(new ObjectIdentityImpl(Object.class, "5577")); Object[] args = {"1", "org.springframework.security.acls.jdbc.JdbcAclServiceTests$MockLongIdDomainObject"}; when( jdbcOperations.query(anyString(), aryEq(args), any(RowMapper.class))).thenReturn(result); ObjectIdentity objectIdentity = new ObjectIdentityImpl(MockLongIdDomainObject.class, 1L); List<ObjectIdentity> objectIdentities = aclService.findChildren(objectIdentity); assertThat(objectIdentities.size()).isEqualTo(1); assertThat(objectIdentities.get(0).getIdentifier()).isEqualTo("5577"); }
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");
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); }
private MutableAcl getOrCreateParentAcl(ISecuredObject<?> securedParent, Sid sid, sk.seges.acris.security.shared.user_management.domain.Permission[] permissions, ObjectIdentity identity) { try { MutableAcl parentAcl = (MutableAcl) aclService.readAclById(identity); return parentAcl; } catch (NotFoundException e) { logger.info("No parent with aclId: " + identity.getIdentifier().toString() + " and class: " + identity.getClass().getName() + " not exist, it will be created! "); setAclRecords(securedParent, sid, permissions); return getOrCreateParentAcl(securedParent, sid, permissions, identity); } }
public void updateAclSource(ObjectIdentity oid, AclModifier modifier) { AclProvider provider = getAclProvider(oid); provider.update(oid.getIdentifier(), modifier); } }
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 AclSource getAclSource(ObjectIdentity oid) { AclProvider provider = getAclProvider(oid); AclSource source = provider.provide(oid.getIdentifier()); if(source == null) { throw new NotFoundException("Can not find acl for id : " + oid); } return source; }