Made BasicAclProvider to only respond to specified ACL object requests.
This commit is contained in:
parent
11afb20856
commit
f1d993f47b
|
@ -8,6 +8,7 @@ Changes in version 0.7 (2004-xx-xx)
|
||||||
* Added AuthenticationProcessingFilter.setDetails for use by subclasses
|
* Added AuthenticationProcessingFilter.setDetails for use by subclasses
|
||||||
* Added 403-causing exception to HttpSession via SecurityEnforcementFilter
|
* Added 403-causing exception to HttpSession via SecurityEnforcementFilter
|
||||||
* Added net.sf.acegisecurity.intercept.event package
|
* Added net.sf.acegisecurity.intercept.event package
|
||||||
|
* Improved BasicAclProvider to only respond to specified ACL object requests
|
||||||
* Refactored MethodDefinitionSource to work with Method, not MethodInvocation
|
* Refactored MethodDefinitionSource to work with Method, not MethodInvocation
|
||||||
* Refactored AbstractSecurityInterceptor to better support other AOP libraries
|
* Refactored AbstractSecurityInterceptor to better support other AOP libraries
|
||||||
* Fixed AbstractProcessingFitler to use removeAttribute (JRun compatibility)
|
* Fixed AbstractProcessingFitler to use removeAttribute (JRun compatibility)
|
||||||
|
|
|
@ -93,6 +93,7 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
|
||||||
private BasicAclDao basicAclDao;
|
private BasicAclDao basicAclDao;
|
||||||
private BasicAclEntryCache basicAclEntryCache = new NullAclEntryCache();
|
private BasicAclEntryCache basicAclEntryCache = new NullAclEntryCache();
|
||||||
private Class defaultAclObjectIdentityClass = NamedEntityObjectIdentity.class;
|
private Class defaultAclObjectIdentityClass = NamedEntityObjectIdentity.class;
|
||||||
|
private Class restrictSupportToClass = null;
|
||||||
private EffectiveAclsResolver effectiveAclsResolver = new GrantedAuthorityEffectiveAclsResolver();
|
private EffectiveAclsResolver effectiveAclsResolver = new GrantedAuthorityEffectiveAclsResolver();
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
@ -230,6 +231,28 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
|
||||||
return effectiveAclsResolver;
|
return effectiveAclsResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to a value other than <code>null</code>, the {@link
|
||||||
|
* #supports(Object)} method will <b>only</b> support the indicates class.
|
||||||
|
* This is useful if you wish to wire multiple
|
||||||
|
* <code>BasicAclProvider</code>s in a list of
|
||||||
|
* <code>AclProviderManager.providers</code> but only have particular
|
||||||
|
* instances respond to particular domain object types.
|
||||||
|
*
|
||||||
|
* @param restrictSupportToClass the class to restrict this
|
||||||
|
* <code>BasicAclProvider</code> to service request for, or
|
||||||
|
* <code>null</code> (the default) if the
|
||||||
|
* <code>BasicAclProvider</code> should respond to every class
|
||||||
|
* presented
|
||||||
|
*/
|
||||||
|
public void setRestrictSupportToClass(Class restrictSupportToClass) {
|
||||||
|
this.restrictSupportToClass = restrictSupportToClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class getRestrictSupportToClass() {
|
||||||
|
return restrictSupportToClass;
|
||||||
|
}
|
||||||
|
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
if (basicAclDao == null) {
|
if (basicAclDao == null) {
|
||||||
throw new IllegalArgumentException("basicAclDao required");
|
throw new IllegalArgumentException("basicAclDao required");
|
||||||
|
@ -260,9 +283,14 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates support for the passed object if it an
|
* Indicates support for the passed object.
|
||||||
* <code>AclObjectIdentity</code> is returned by {@link
|
*
|
||||||
* #obtainIdentity(Object)}.
|
* <p>
|
||||||
|
* An object will only be supported if it (i) is allowed to be supported as
|
||||||
|
* defined by the {@link #setRestrictSupportToClass(Class)} method,
|
||||||
|
* <b>and</b> (ii) if an <code>AclObjectIdentity</code> is returned by
|
||||||
|
* {@link #obtainIdentity(Object)} for that object.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param domainInstance the instance to check
|
* @param domainInstance the instance to check
|
||||||
*
|
*
|
||||||
|
@ -270,6 +298,16 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
|
||||||
* <code>false</code> otherwise
|
* <code>false</code> otherwise
|
||||||
*/
|
*/
|
||||||
public boolean supports(Object domainInstance) {
|
public boolean supports(Object domainInstance) {
|
||||||
|
if (domainInstance == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((restrictSupportToClass != null)
|
||||||
|
&& !restrictSupportToClass.isAssignableFrom(
|
||||||
|
domainInstance.getClass())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (obtainIdentity(domainInstance) == null) {
|
if (obtainIdentity(domainInstance) == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -184,6 +184,10 @@ public class BasicAclProviderTests extends TestCase {
|
||||||
|
|
||||||
provider.setBasicAclDao(new MockDao());
|
provider.setBasicAclDao(new MockDao());
|
||||||
assertNotNull(provider.getBasicAclDao());
|
assertNotNull(provider.getBasicAclDao());
|
||||||
|
|
||||||
|
assertNull(provider.getRestrictSupportToClass());
|
||||||
|
provider.setRestrictSupportToClass(SomeDomain.class);
|
||||||
|
assertEquals(SomeDomain.class, provider.getRestrictSupportToClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStartupFailsIfNullAclDao() throws Exception {
|
public void testStartupFailsIfNullAclDao() throws Exception {
|
||||||
|
@ -276,6 +280,16 @@ public class BasicAclProviderTests extends TestCase {
|
||||||
|
|
||||||
// this one SHOULD be supported, as it implements AclObjectIdentityAware
|
// this one SHOULD be supported, as it implements AclObjectIdentityAware
|
||||||
assertTrue(provider.supports(new MockDomain(4)));
|
assertTrue(provider.supports(new MockDomain(4)));
|
||||||
|
|
||||||
|
// now restrict the provider to only respond to SomeDomain.class requests
|
||||||
|
provider.setRestrictSupportToClass(SomeDomain.class);
|
||||||
|
assertEquals(SomeDomain.class, provider.getRestrictSupportToClass());
|
||||||
|
|
||||||
|
// this one SHOULD be supported, as it has a getId() method AND it meets the restrictSupportToClass criteria
|
||||||
|
assertTrue(provider.supports(new SomeDomain()));
|
||||||
|
|
||||||
|
// this one should NOT be suported, as whilst it implement AclObjectIdentityAware (as proven earlier in the test), it does NOT meet the restrictSupportToClass criteria
|
||||||
|
assertFalse(provider.supports(new MockDomain(4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private JdbcDaoImpl makePopulatedJdbcDao() throws Exception {
|
private JdbcDaoImpl makePopulatedJdbcDao() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue