Use new BasicAclExtendedDao for DAO CRUD operations instead of ContactDao.

This commit is contained in:
Ben Alex 2004-11-15 13:04:54 +00:00
parent af5917b685
commit f286c34312
5 changed files with 35 additions and 78 deletions

View File

@ -31,45 +31,13 @@ public interface ContactDao {
public void create(Contact contact); public void create(Contact contact);
/**
* Creates an acl_object_identity for the specified Contact.
*
* @param contact to create an entry for
*
* @return the acl_object_identity identifier
*/
public Integer createAclObjectIdentity(Contact contact);
/**
* Given an acl_object_identitiy identifier, grant the specified recipient
* read access to the object identified.
*
* @param aclObjectIdentity to assign the read permission against
* @param recipient receiving the permission
* @param permission to assign
*/
public void createPermission(Integer aclObjectIdentity, String recipient,
int permission);
public void delete(Integer contactId); public void delete(Integer contactId);
public void deletePermission(Integer aclObjectIdentity, String recipient);
public List findAll(); public List findAll();
public List findAllPrincipals(); public List findAllPrincipals();
public List findAllRoles(); public List findAllRoles();
/**
* Obtains the acl_object_identity for the specified Contact.
*
* @param contact to locate an acl_object_identity for
*
* @return the acl_object_identity identifier or <code>null</code> if not
* found
*/
public Integer lookupAclObjectIdentity(Contact contact);
public void update(Contact contact); public void update(Contact contact);
} }

View File

@ -15,8 +15,6 @@
package sample.contact; package sample.contact;
import net.sf.acegisecurity.acl.basic.SimpleAclEntry;
import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.support.JdbcDaoSupport; import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.object.MappingSqlQuery; import org.springframework.jdbc.object.MappingSqlQuery;
@ -40,15 +38,11 @@ import javax.sql.DataSource;
public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao { public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
//~ Instance fields ======================================================== //~ Instance fields ========================================================
private AclObjectIdentityByObjectIdentityQuery aclObjectIdentityByObjectIdentityQuery;
private AclObjectIdentityInsert aclObjectIdentityInsert;
private ContactDelete contactDelete; private ContactDelete contactDelete;
private ContactInsert contactInsert; private ContactInsert contactInsert;
private ContactUpdate contactUpdate; private ContactUpdate contactUpdate;
private ContactsAllQuery contactsAllQuery; private ContactsAllQuery contactsAllQuery;
private ContactsByIdQuery contactsByIdQuery; private ContactsByIdQuery contactsByIdQuery;
private PermissionDelete permissionDelete;
private PermissionInsert permissionInsert;
private PrincipalsAllQuery principalsAllQuery; private PrincipalsAllQuery principalsAllQuery;
private RolesAllQuery rolesAllQuery; private RolesAllQuery rolesAllQuery;
@ -68,25 +62,10 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
contactInsert.insert(contact); contactInsert.insert(contact);
} }
public Integer createAclObjectIdentity(Contact contact) {
return new Integer(aclObjectIdentityInsert.insert(makeObjectIdentity(
contact), null, SimpleAclEntry.class.getName()));
}
public void createPermission(Integer aclObjectIdentity, String recipient,
int permission) {
permissionInsert.insert(aclObjectIdentity, recipient,
new Integer(permission));
}
public void delete(Integer contactId) { public void delete(Integer contactId) {
contactDelete.delete(contactId); contactDelete.delete(contactId);
} }
public void deletePermission(Integer aclObjectIdentity, String recipient) {
permissionDelete.delete(aclObjectIdentity, recipient);
}
public List findAll() { public List findAll() {
return contactsAllQuery.execute(); return contactsAllQuery.execute();
} }
@ -99,17 +78,6 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
return rolesAllQuery.execute(); return rolesAllQuery.execute();
} }
public Integer lookupAclObjectIdentity(Contact contact) {
List list = aclObjectIdentityByObjectIdentityQuery.execute(makeObjectIdentity(
contact));
if (list.size() == 0) {
return null;
} else {
return (Integer) list.get(0);
}
}
public void update(Contact contact) { public void update(Contact contact) {
contactUpdate.update(contact); contactUpdate.update(contact);
} }
@ -118,14 +86,10 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
contactInsert = new ContactInsert(getDataSource()); contactInsert = new ContactInsert(getDataSource());
contactUpdate = new ContactUpdate(getDataSource()); contactUpdate = new ContactUpdate(getDataSource());
contactDelete = new ContactDelete(getDataSource()); contactDelete = new ContactDelete(getDataSource());
aclObjectIdentityInsert = new AclObjectIdentityInsert(getDataSource());
permissionInsert = new PermissionInsert(getDataSource());
permissionDelete = new PermissionDelete(getDataSource());
contactsAllQuery = new ContactsAllQuery(getDataSource()); contactsAllQuery = new ContactsAllQuery(getDataSource());
principalsAllQuery = new PrincipalsAllQuery(getDataSource()); principalsAllQuery = new PrincipalsAllQuery(getDataSource());
rolesAllQuery = new RolesAllQuery(getDataSource()); rolesAllQuery = new RolesAllQuery(getDataSource());
contactsByIdQuery = new ContactsByIdQuery(getDataSource()); contactsByIdQuery = new ContactsByIdQuery(getDataSource());
aclObjectIdentityByObjectIdentityQuery = new AclObjectIdentityByObjectIdentityQuery(getDataSource());
} }
private String makeObjectIdentity(Contact contact) { private String makeObjectIdentity(Contact contact) {

View File

@ -15,6 +15,9 @@
package sample.contact; package sample.contact;
import net.sf.acegisecurity.acl.basic.AclObjectIdentity;
import net.sf.acegisecurity.acl.basic.BasicAclExtendedDao;
import net.sf.acegisecurity.acl.basic.NamedEntityObjectIdentity;
import net.sf.acegisecurity.acl.basic.SimpleAclEntry; import net.sf.acegisecurity.acl.basic.SimpleAclEntry;
import net.sf.acegisecurity.context.ContextHolder; import net.sf.acegisecurity.context.ContextHolder;
import net.sf.acegisecurity.context.SecureContext; import net.sf.acegisecurity.context.SecureContext;
@ -34,6 +37,7 @@ import java.util.Random;
public class ContactManagerBackend implements ContactManager, InitializingBean { public class ContactManagerBackend implements ContactManager, InitializingBean {
//~ Instance fields ======================================================== //~ Instance fields ========================================================
private BasicAclExtendedDao basicAclExtendedDao;
private ContactDao contactDao; private ContactDao contactDao;
private int counter = 100; private int counter = 100;
@ -50,6 +54,14 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
return list; return list;
} }
public void setBasicAclExtendedDao(BasicAclExtendedDao basicAclExtendedDao) {
this.basicAclExtendedDao = basicAclExtendedDao;
}
public BasicAclExtendedDao getBasicAclExtendedDao() {
return basicAclExtendedDao;
}
public Contact getById(Integer id) { public Contact getById(Integer id) {
return contactDao.getById(id); return contactDao.getById(id);
} }
@ -77,15 +89,21 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
public void addPermission(Contact contact, String recipient, public void addPermission(Contact contact, String recipient,
Integer permission) { Integer permission) {
Integer aclObjectIdentity = contactDao.lookupAclObjectIdentity(contact); SimpleAclEntry simpleAclEntry = new SimpleAclEntry();
contactDao.createPermission(aclObjectIdentity, recipient, simpleAclEntry.setAclObjectIdentity(makeObjectIdentity(contact));
permission.intValue()); simpleAclEntry.setMask(permission.intValue());
simpleAclEntry.setRecipient(recipient);
basicAclExtendedDao.create(simpleAclEntry);
} }
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
if (contactDao == null) { if (contactDao == null) {
throw new IllegalArgumentException("contactDao required"); throw new IllegalArgumentException("contactDao required");
} }
if (basicAclExtendedDao == null) {
throw new IllegalArgumentException("basicAclExtendedDao required");
}
} }
public void create(Contact contact) { public void create(Contact contact) {
@ -94,18 +112,19 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
contactDao.create(contact); contactDao.create(contact);
// Grant the current principal access to the contact // Grant the current principal access to the contact
Integer aclObjectIdentity = contactDao.createAclObjectIdentity(contact); addPermission(contact, getUsername(),
contactDao.createPermission(aclObjectIdentity, getUsername(), new Integer(SimpleAclEntry.ADMINISTRATION));
SimpleAclEntry.ADMINISTRATION);
} }
public void delete(Contact contact) { public void delete(Contact contact) {
contactDao.delete(contact.getId()); contactDao.delete(contact.getId());
// Delete the ACL information as well
basicAclExtendedDao.delete(makeObjectIdentity(contact));
} }
public void deletePermission(Contact contact, String recipient) { public void deletePermission(Contact contact, String recipient) {
Integer aclObjectIdentity = contactDao.lookupAclObjectIdentity(contact); basicAclExtendedDao.delete(makeObjectIdentity(contact), recipient);
contactDao.deletePermission(aclObjectIdentity, recipient);
} }
public void update(Contact contact) { public void update(Contact contact) {
@ -116,4 +135,9 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
return ((SecureContext) ContextHolder.getContext()).getAuthentication() return ((SecureContext) ContextHolder.getContext()).getAuthentication()
.getPrincipal().toString(); .getPrincipal().toString();
} }
private AclObjectIdentity makeObjectIdentity(Contact contact) {
return new NamedEntityObjectIdentity(contact.getClass().getName(),
contact.getId().toString());
}
} }

View File

@ -78,10 +78,10 @@
</bean> </bean>
<bean id="basicAclProvider" class="net.sf.acegisecurity.acl.basic.BasicAclProvider"> <bean id="basicAclProvider" class="net.sf.acegisecurity.acl.basic.BasicAclProvider">
<property name="basicAclDao"><ref local="basicAclDao"/></property> <property name="basicAclDao"><ref local="basicAclExtendedDao"/></property>
</bean> </bean>
<bean id="basicAclDao" class="net.sf.acegisecurity.acl.basic.jdbc.JdbcDaoImpl"> <bean id="basicAclExtendedDao" class="net.sf.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl">
<property name="dataSource"><ref bean="dataSource"/></property> <property name="dataSource"><ref bean="dataSource"/></property>
</bean> </bean>

View File

@ -66,6 +66,7 @@
<bean id="contactManagerTarget" class="sample.contact.ContactManagerBackend"> <bean id="contactManagerTarget" class="sample.contact.ContactManagerBackend">
<property name="contactDao"><ref local="contactDao"/></property> <property name="contactDao"><ref local="contactDao"/></property>
<property name="basicAclExtendedDao"><ref bean="basicAclExtendedDao"/></property>
</bean> </bean>
</beans> </beans>