diff --git a/samples/contacts/src/main/java/sample/contact/ContactDao.java b/samples/contacts/src/main/java/sample/contact/ContactDao.java
index fff885cfbd..38519281b6 100644
--- a/samples/contacts/src/main/java/sample/contact/ContactDao.java
+++ b/samples/contacts/src/main/java/sample/contact/ContactDao.java
@@ -31,45 +31,13 @@ public interface ContactDao {
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 deletePermission(Integer aclObjectIdentity, String recipient);
-
public List findAll();
public List findAllPrincipals();
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 null
if not
- * found
- */
- public Integer lookupAclObjectIdentity(Contact contact);
-
public void update(Contact contact);
}
diff --git a/samples/contacts/src/main/java/sample/contact/ContactDaoSpring.java b/samples/contacts/src/main/java/sample/contact/ContactDaoSpring.java
index 51d5c59276..da5df230a4 100644
--- a/samples/contacts/src/main/java/sample/contact/ContactDaoSpring.java
+++ b/samples/contacts/src/main/java/sample/contact/ContactDaoSpring.java
@@ -15,8 +15,6 @@
package sample.contact;
-import net.sf.acegisecurity.acl.basic.SimpleAclEntry;
-
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.object.MappingSqlQuery;
@@ -40,15 +38,11 @@ import javax.sql.DataSource;
public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
//~ Instance fields ========================================================
- private AclObjectIdentityByObjectIdentityQuery aclObjectIdentityByObjectIdentityQuery;
- private AclObjectIdentityInsert aclObjectIdentityInsert;
private ContactDelete contactDelete;
private ContactInsert contactInsert;
private ContactUpdate contactUpdate;
private ContactsAllQuery contactsAllQuery;
private ContactsByIdQuery contactsByIdQuery;
- private PermissionDelete permissionDelete;
- private PermissionInsert permissionInsert;
private PrincipalsAllQuery principalsAllQuery;
private RolesAllQuery rolesAllQuery;
@@ -68,25 +62,10 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
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) {
contactDelete.delete(contactId);
}
- public void deletePermission(Integer aclObjectIdentity, String recipient) {
- permissionDelete.delete(aclObjectIdentity, recipient);
- }
-
public List findAll() {
return contactsAllQuery.execute();
}
@@ -99,17 +78,6 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
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) {
contactUpdate.update(contact);
}
@@ -118,14 +86,10 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
contactInsert = new ContactInsert(getDataSource());
contactUpdate = new ContactUpdate(getDataSource());
contactDelete = new ContactDelete(getDataSource());
- aclObjectIdentityInsert = new AclObjectIdentityInsert(getDataSource());
- permissionInsert = new PermissionInsert(getDataSource());
- permissionDelete = new PermissionDelete(getDataSource());
contactsAllQuery = new ContactsAllQuery(getDataSource());
principalsAllQuery = new PrincipalsAllQuery(getDataSource());
rolesAllQuery = new RolesAllQuery(getDataSource());
contactsByIdQuery = new ContactsByIdQuery(getDataSource());
- aclObjectIdentityByObjectIdentityQuery = new AclObjectIdentityByObjectIdentityQuery(getDataSource());
}
private String makeObjectIdentity(Contact contact) {
diff --git a/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java b/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java
index db8811e62a..8a10cbf07a 100644
--- a/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java
+++ b/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java
@@ -15,6 +15,9 @@
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.context.ContextHolder;
import net.sf.acegisecurity.context.SecureContext;
@@ -34,6 +37,7 @@ import java.util.Random;
public class ContactManagerBackend implements ContactManager, InitializingBean {
//~ Instance fields ========================================================
+ private BasicAclExtendedDao basicAclExtendedDao;
private ContactDao contactDao;
private int counter = 100;
@@ -50,6 +54,14 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
return list;
}
+ public void setBasicAclExtendedDao(BasicAclExtendedDao basicAclExtendedDao) {
+ this.basicAclExtendedDao = basicAclExtendedDao;
+ }
+
+ public BasicAclExtendedDao getBasicAclExtendedDao() {
+ return basicAclExtendedDao;
+ }
+
public Contact getById(Integer id) {
return contactDao.getById(id);
}
@@ -77,15 +89,21 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
public void addPermission(Contact contact, String recipient,
Integer permission) {
- Integer aclObjectIdentity = contactDao.lookupAclObjectIdentity(contact);
- contactDao.createPermission(aclObjectIdentity, recipient,
- permission.intValue());
+ SimpleAclEntry simpleAclEntry = new SimpleAclEntry();
+ simpleAclEntry.setAclObjectIdentity(makeObjectIdentity(contact));
+ simpleAclEntry.setMask(permission.intValue());
+ simpleAclEntry.setRecipient(recipient);
+ basicAclExtendedDao.create(simpleAclEntry);
}
public void afterPropertiesSet() throws Exception {
if (contactDao == null) {
throw new IllegalArgumentException("contactDao required");
}
+
+ if (basicAclExtendedDao == null) {
+ throw new IllegalArgumentException("basicAclExtendedDao required");
+ }
}
public void create(Contact contact) {
@@ -94,18 +112,19 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
contactDao.create(contact);
// Grant the current principal access to the contact
- Integer aclObjectIdentity = contactDao.createAclObjectIdentity(contact);
- contactDao.createPermission(aclObjectIdentity, getUsername(),
- SimpleAclEntry.ADMINISTRATION);
+ addPermission(contact, getUsername(),
+ new Integer(SimpleAclEntry.ADMINISTRATION));
}
public void delete(Contact contact) {
contactDao.delete(contact.getId());
+
+ // Delete the ACL information as well
+ basicAclExtendedDao.delete(makeObjectIdentity(contact));
}
public void deletePermission(Contact contact, String recipient) {
- Integer aclObjectIdentity = contactDao.lookupAclObjectIdentity(contact);
- contactDao.deletePermission(aclObjectIdentity, recipient);
+ basicAclExtendedDao.delete(makeObjectIdentity(contact), recipient);
}
public void update(Contact contact) {
@@ -116,4 +135,9 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
return ((SecureContext) ContextHolder.getContext()).getAuthentication()
.getPrincipal().toString();
}
+
+ private AclObjectIdentity makeObjectIdentity(Contact contact) {
+ return new NamedEntityObjectIdentity(contact.getClass().getName(),
+ contact.getId().toString());
+ }
}
diff --git a/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml b/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml
index 5eba89d2ab..64a6678335 100644
--- a/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml
+++ b/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml
@@ -78,10 +78,10 @@
-
+
-
+
diff --git a/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml b/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml
index aa8c2c90a7..6666a49cee 100644
--- a/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml
+++ b/samples/contacts/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml
@@ -66,6 +66,7 @@
+