From 1a78f9e15fa6d1ee7a6bda1385a1d6a03d25be91 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Fri, 15 Apr 2005 01:21:41 +0000 Subject: [PATCH] Refactored to use Spring Assert class (thanks IntelliJ :). --- .../acegisecurity/acl/AclProviderManager.java | 32 ++-- .../acl/basic/AbstractBasicAclEntry.java | 16 +- .../acl/basic/BasicAclProvider.java | 48 +++--- .../acl/basic/NamedEntityObjectIdentity.java | 8 +- .../acl/basic/cache/BasicAclEntryHolder.java | 10 +- .../cache/EhCacheBasedAclEntryCache.java | 5 +- .../adapters/AuthByAdapterProvider.java | 6 +- ...InvocationCollectionFilteringProvider.java | 14 +- .../BasicAclEntryAfterInvocationProvider.java | 14 +- .../AbstractSecurityInterceptor.java | 107 +++++--------- .../AbstractMethodDefinitionSource.java | 18 +-- .../AnonymousAuthenticationToken.java | 6 +- .../cas/CasAuthenticationProvider.java | 28 +--- .../providers/cas/CasAuthenticationToken.java | 6 +- .../cas/cache/EhCacheBasedTicketCache.java | 5 +- .../populator/DaoCasAuthoritiesPopulator.java | 6 +- .../cas/proxy/AcceptAnyCasProxy.java | 5 +- .../cas/proxy/NamedCasProxyDecider.java | 12 +- .../cas/proxy/RejectProxyTickets.java | 7 +- .../AbstractTicketValidator.java | 11 +- .../dao/DaoAuthenticationProvider.java | 11 +- .../PasswordDaoAuthenticationProvider.java | 11 +- .../dao/cache/EhCacheBasedUserCache.java | 5 +- .../dao/event/AuthenticationEvent.java | 5 +- .../jaas/JaasAuthenticationProvider.java | 11 +- .../rcp/RemoteAuthenticationManagerImpl.java | 6 +- .../rcp/RemoteAuthenticationProvider.java | 6 +- .../RememberMeAuthenticationToken.java | 6 +- .../RunAsImplAuthenticationProvider.java | 6 +- .../acegisecurity/runas/RunAsManagerImpl.java | 6 +- .../ChannelProcessingFilter.java | 22 +-- .../InsecureChannelProcessor.java | 10 +- .../RetryWithHttpEntryPoint.java | 10 +- .../RetryWithHttpsEntryPoint.java | 10 +- .../securechannel/SecureChannelProcessor.java | 14 +- .../ui/basicauth/BasicProcessingFilter.java | 12 +- .../ui/cas/CasProcessingFilterEntryPoint.java | 11 +- ...henticationProcessingFilterEntryPoint.java | 15 +- .../org/acegisecurity/userdetails/User.java | 5 +- .../userdetails/memory/InMemoryDaoImpl.java | 6 +- .../userdetails/memory/UserMap.java | 5 +- .../acegisecurity/util/FilterChainProxy.java | 16 +- .../acegisecurity/util/PortMapperImpl.java | 14 +- .../acegisecurity/util/PortResolverImpl.java | 5 +- .../vote/BasicAclEntryVoter.java | 20 +-- .../contact/AddPermissionController.java | 6 +- .../contact/AdminPermissionController.java | 12 +- .../sample/contact/ContactManagerBackend.java | 10 +- .../sample/contact/DataSourcePopulator.java | 137 ++++++------------ .../java/sample/contact/DeleteController.java | 6 +- .../contact/DeletePermissionController.java | 12 +- .../sample/contact/PublicIndexController.java | 6 +- .../sample/contact/SecureIndexController.java | 6 +- 53 files changed, 268 insertions(+), 539 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/acl/AclProviderManager.java b/core/src/main/java/org/acegisecurity/acl/AclProviderManager.java index 1cc047edcc..ab4efa535a 100644 --- a/core/src/main/java/org/acegisecurity/acl/AclProviderManager.java +++ b/core/src/main/java/org/acegisecurity/acl/AclProviderManager.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.util.Iterator; import java.util.List; @@ -50,10 +51,7 @@ public class AclProviderManager implements AclManager, InitializingBean { //~ Methods ================================================================ public AclEntry[] getAcls(Object domainInstance) { - if (domainInstance == null) { - throw new IllegalArgumentException( - "domainInstance is null - violating interface contract"); - } + Assert.notNull(domainInstance, "domainInstance is null - violating interface contract"); Iterator iter = providers.iterator(); @@ -63,7 +61,7 @@ public class AclProviderManager implements AclManager, InitializingBean { if (provider.supports(domainInstance)) { if (logger.isDebugEnabled()) { logger.debug("ACL lookup using " - + provider.getClass().getName()); + + provider.getClass().getName()); } return provider.getAcls(domainInstance); @@ -72,7 +70,7 @@ public class AclProviderManager implements AclManager, InitializingBean { if (logger.isDebugEnabled()) { logger.debug("No AclProvider found for " - + domainInstance.toString()); + + domainInstance.toString()); } return null; @@ -80,15 +78,8 @@ public class AclProviderManager implements AclManager, InitializingBean { public AclEntry[] getAcls(Object domainInstance, Authentication authentication) { - if (domainInstance == null) { - throw new IllegalArgumentException( - "domainInstance is null - violating interface contract"); - } - - if (authentication == null) { - throw new IllegalArgumentException( - "authentication is null - violating interface contract"); - } + Assert.notNull(domainInstance, "domainInstance is null - violating interface contract"); + Assert.notNull(authentication, "authentication is null - violating interface contract"); Iterator iter = providers.iterator(); @@ -98,21 +89,21 @@ public class AclProviderManager implements AclManager, InitializingBean { if (provider.supports(domainInstance)) { if (logger.isDebugEnabled()) { logger.debug("ACL lookup using " - + provider.getClass().getName()); + + provider.getClass().getName()); } return provider.getAcls(domainInstance, authentication); } else { if (logger.isDebugEnabled()) { logger.debug("Provider " + provider.toString() - + " does not support " + domainInstance); + + " does not support " + domainInstance); } } } if (logger.isDebugEnabled()) { logger.debug("No AclProvider found for " - + domainInstance.toString()); + + domainInstance.toString()); } return null; @@ -157,9 +148,6 @@ public class AclProviderManager implements AclManager, InitializingBean { } private void checkIfValidList(List listToCheck) { - if ((listToCheck == null) || (listToCheck.size() == 0)) { - throw new IllegalArgumentException( - "A list of AclManagers is required"); - } + Assert.notEmpty(listToCheck, "A list of AclManagers is required"); } } diff --git a/core/src/main/java/org/acegisecurity/acl/basic/AbstractBasicAclEntry.java b/core/src/main/java/org/acegisecurity/acl/basic/AbstractBasicAclEntry.java index b6837e56b8..87565e87de 100644 --- a/core/src/main/java/org/acegisecurity/acl/basic/AbstractBasicAclEntry.java +++ b/core/src/main/java/org/acegisecurity/acl/basic/AbstractBasicAclEntry.java @@ -17,6 +17,7 @@ package net.sf.acegisecurity.acl.basic; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.Assert; import java.util.Arrays; @@ -49,14 +50,9 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry { public AbstractBasicAclEntry(Object recipient, AclObjectIdentity aclObjectIdentity, AclObjectIdentity aclObjectParentIdentity, int mask) { - if (recipient == null) { - throw new IllegalArgumentException("recipient cannot be null"); - } + Assert.notNull(recipient, "recipient cannot be null"); - if (aclObjectIdentity == null) { - throw new IllegalArgumentException( - "aclObjectIdentity cannot be null"); - } + Assert.notNull(aclObjectIdentity, "aclObjectIdentity cannot be null"); validPermissions = getValidPermissions(); Arrays.sort(validPermissions); @@ -64,9 +60,9 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry { for (int i = 0; i < validPermissions.length; i++) { if (logger.isDebugEnabled()) { logger.debug("Valid permission: " - + printPermissionsBlock(validPermissions[i]) + " " - + printBinary(validPermissions[i]) + " (" - + validPermissions[i] + ")"); + + printPermissionsBlock(validPermissions[i]) + " " + + printBinary(validPermissions[i]) + " (" + + validPermissions[i] + ")"); } } diff --git a/core/src/main/java/org/acegisecurity/acl/basic/BasicAclProvider.java b/core/src/main/java/org/acegisecurity/acl/basic/BasicAclProvider.java index b89d3afc66..635c1b1c07 100644 --- a/core/src/main/java/org/acegisecurity/acl/basic/BasicAclProvider.java +++ b/core/src/main/java/org/acegisecurity/acl/basic/BasicAclProvider.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.lang.reflect.Constructor; @@ -103,10 +104,7 @@ public class BasicAclProvider implements AclProvider, InitializingBean { AclObjectIdentity aclIdentity = obtainIdentity(domainInstance); - if (aclIdentity == null) { - throw new IllegalArgumentException( - "domainInstance is not supported by this provider"); - } + Assert.notNull(aclIdentity, "domainInstance is not supported by this provider"); if (logger.isDebugEnabled()) { logger.debug("Looking up: " + aclIdentity.toString()); @@ -123,14 +121,14 @@ public class BasicAclProvider implements AclProvider, InitializingBean { for (int i = 0; i < instanceAclEntries.length; i++) { if (logger.isDebugEnabled()) { logger.debug("Explicit add: " - + instanceAclEntries[i].toString()); + + instanceAclEntries[i].toString()); } map.put(instanceAclEntries[i].getRecipient(), instanceAclEntries[i]); } AclObjectIdentity parent = instanceAclEntries[0] - .getAclObjectParentIdentity(); + .getAclObjectParentIdentity(); while (parent != null) { BasicAclEntry[] parentAclEntries = lookup(parent); @@ -153,15 +151,15 @@ public class BasicAclProvider implements AclProvider, InitializingBean { if (!map.containsKey(parentAclEntries[i].getRecipient())) { if (logger.isDebugEnabled()) { logger.debug("Added parent to map: " - + parentAclEntries[i].toString()); + + parentAclEntries[i].toString()); } map.put(parentAclEntries[i].getRecipient(), - parentAclEntries[i]); + parentAclEntries[i]); } else { if (logger.isDebugEnabled()) { logger.debug("Did NOT add parent to map: " - + parentAclEntries[i].toString()); + + parentAclEntries[i].toString()); } } } @@ -172,7 +170,7 @@ public class BasicAclProvider implements AclProvider, InitializingBean { Collection collection = map.values(); - return (AclEntry[]) collection.toArray(new AclEntry[] {}); + return (AclEntry[]) collection.toArray(new AclEntry[]{}); } public AclEntry[] getAcls(Object domainInstance, @@ -254,31 +252,19 @@ public class BasicAclProvider implements AclProvider, InitializingBean { } public void afterPropertiesSet() { - if (basicAclDao == null) { - throw new IllegalArgumentException("basicAclDao required"); - } - - if (basicAclEntryCache == null) { - throw new IllegalArgumentException("basicAclEntryCache required"); - } - - if (effectiveAclsResolver == null) { - throw new IllegalArgumentException("effectiveAclsResolver required"); - } - - if ((defaultAclObjectIdentityClass == null) - || (!AclObjectIdentity.class.isAssignableFrom( - this.defaultAclObjectIdentityClass))) { - throw new IllegalArgumentException( - "defaultAclObjectIdentityClass that implements AclObjectIdentity is required"); - } + Assert.notNull(basicAclDao, "basicAclDao required"); + Assert.notNull(basicAclEntryCache, "basicAclEntryCache required"); + Assert.notNull(basicAclEntryCache, "basicAclEntryCache required"); + Assert.notNull(effectiveAclsResolver, "effectiveAclsResolver required"); + Assert.notNull(defaultAclObjectIdentityClass, "defaultAclObjectIdentityClass required"); + Assert.isTrue(AclObjectIdentity.class.isAssignableFrom(this.defaultAclObjectIdentityClass), + "defaultAclObjectIdentityClass must implement AclObjectIdentity"); try { Constructor constructor = defaultAclObjectIdentityClass - .getConstructor(new Class[] {Object.class}); + .getConstructor(new Class[]{Object.class}); } catch (NoSuchMethodException nsme) { - throw new IllegalArgumentException( - "defaultAclObjectIdentityClass must provide a constructor that accepts the domain object instance!"); + throw new IllegalArgumentException("defaultAclObjectIdentityClass must provide a constructor that accepts the domain object instance!"); } } diff --git a/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java b/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java index ed86661caf..9fd70edd71 100644 --- a/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java +++ b/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java @@ -15,6 +15,8 @@ package net.sf.acegisecurity.acl.basic; +import org.springframework.util.Assert; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -65,9 +67,7 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity { */ public NamedEntityObjectIdentity(Object object) throws IllegalAccessException, InvocationTargetException { - if (object == null) { - throw new IllegalArgumentException("object cannot be null"); - } + Assert.notNull(object, "object cannot be null"); this.classname = object.getClass().getName(); @@ -79,7 +79,7 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity { this.id = result.toString(); } catch (NoSuchMethodException nsme) { throw new IllegalArgumentException("Object of class '" + clazz - + "' does not provide the required getId() method: " + object); + + "' does not provide the required getId() method: " + object); } } diff --git a/core/src/main/java/org/acegisecurity/acl/basic/cache/BasicAclEntryHolder.java b/core/src/main/java/org/acegisecurity/acl/basic/cache/BasicAclEntryHolder.java index f7038d8f32..76314b920e 100644 --- a/core/src/main/java/org/acegisecurity/acl/basic/cache/BasicAclEntryHolder.java +++ b/core/src/main/java/org/acegisecurity/acl/basic/cache/BasicAclEntryHolder.java @@ -19,6 +19,8 @@ import net.sf.acegisecurity.acl.basic.BasicAclEntry; import java.io.Serializable; +import org.springframework.util.Assert; + /** * Used by {@link EhCacheBasedAclEntryCache} to store the array of @@ -57,14 +59,10 @@ public class BasicAclEntryHolder implements Serializable { * passed to the constructor */ public BasicAclEntryHolder(BasicAclEntry[] aclEntries) { - if (aclEntries == null) { - throw new IllegalArgumentException("aclEntries cannot be null"); - } + Assert.notNull(aclEntries, "aclEntries cannot be null"); for (int i = 0; i < aclEntries.length; i++) { - if (aclEntries[i] == null) { - throw new IllegalArgumentException("aclEntries cannot be null"); - } + Assert.notNull(aclEntries[i], "aclEntries cannot be null"); } this.basicAclEntries = aclEntries; diff --git a/core/src/main/java/org/acegisecurity/acl/basic/cache/EhCacheBasedAclEntryCache.java b/core/src/main/java/org/acegisecurity/acl/basic/cache/EhCacheBasedAclEntryCache.java index 4fd8d96b9f..6061db0cc8 100644 --- a/core/src/main/java/org/acegisecurity/acl/basic/cache/EhCacheBasedAclEntryCache.java +++ b/core/src/main/java/org/acegisecurity/acl/basic/cache/EhCacheBasedAclEntryCache.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.util.Assert; /** @@ -89,9 +90,7 @@ public class EhCacheBasedAclEntryCache implements BasicAclEntryCache, } public void afterPropertiesSet() throws Exception { - if (cache == null) { - throw new IllegalArgumentException("cache mandatory"); - } + Assert.notNull(cache, "cache mandatory"); } public void putEntriesInCache(BasicAclEntry[] basicAclEntry) { diff --git a/core/src/main/java/org/acegisecurity/adapters/AuthByAdapterProvider.java b/core/src/main/java/org/acegisecurity/adapters/AuthByAdapterProvider.java index 23a8e57ac6..84e249bd74 100644 --- a/core/src/main/java/org/acegisecurity/adapters/AuthByAdapterProvider.java +++ b/core/src/main/java/org/acegisecurity/adapters/AuthByAdapterProvider.java @@ -21,6 +21,7 @@ import net.sf.acegisecurity.BadCredentialsException; import net.sf.acegisecurity.providers.AuthenticationProvider; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** @@ -58,10 +59,7 @@ public class AuthByAdapterProvider implements InitializingBean, } public void afterPropertiesSet() throws Exception { - if (key == null) { - throw new IllegalArgumentException( - "A Key is required and should match that configured for the adapters"); - } + Assert.notNull(key, "A Key is required and should match that configured for the adapters"); } public Authentication authenticate(Authentication authentication) diff --git a/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationCollectionFilteringProvider.java b/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationCollectionFilteringProvider.java index 4877c0b5bf..ec6b4192cc 100644 --- a/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationCollectionFilteringProvider.java +++ b/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationCollectionFilteringProvider.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.lang.reflect.Array; @@ -138,18 +139,11 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProvider } public void afterPropertiesSet() throws Exception { - if (processConfigAttribute == null) { - throw new IllegalArgumentException( - "A processConfigAttribute is mandatory"); - } + Assert.notNull(processConfigAttribute, "A processConfigAttribute is mandatory"); + Assert.notNull(aclManager, "An aclManager is mandatory"); if ((requirePermission == null) || (requirePermission.length == 0)) { - throw new IllegalArgumentException( - "One or more requirePermission entries is mandatory"); - } - - if (aclManager == null) { - throw new IllegalArgumentException("An aclManager is mandatory"); + throw new IllegalArgumentException("One or more requirePermission entries is mandatory"); } } diff --git a/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationProvider.java b/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationProvider.java index 75a13a9bcd..0eee0413ad 100644 --- a/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationProvider.java +++ b/core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationProvider.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.util.Iterator; @@ -129,18 +130,11 @@ public class BasicAclEntryAfterInvocationProvider } public void afterPropertiesSet() throws Exception { - if (processConfigAttribute == null) { - throw new IllegalArgumentException( - "A processConfigAttribute is mandatory"); - } + Assert.notNull(processConfigAttribute, "A processConfigAttribute is mandatory"); + Assert.notNull(aclManager, "An aclManager is mandatory"); if ((requirePermission == null) || (requirePermission.length == 0)) { - throw new IllegalArgumentException( - "One or more requirePermission entries is mandatory"); - } - - if (aclManager == null) { - throw new IllegalArgumentException("An aclManager is mandatory"); + throw new IllegalArgumentException("One or more requirePermission entries is mandatory"); } } diff --git a/core/src/main/java/org/acegisecurity/intercept/AbstractSecurityInterceptor.java b/core/src/main/java/org/acegisecurity/intercept/AbstractSecurityInterceptor.java index 989a2b6a55..b921f5d6cc 100644 --- a/core/src/main/java/org/acegisecurity/intercept/AbstractSecurityInterceptor.java +++ b/core/src/main/java/org/acegisecurity/intercept/AbstractSecurityInterceptor.java @@ -43,6 +43,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.util.Assert; import java.util.HashSet; import java.util.Iterator; @@ -221,80 +222,61 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, } public void afterPropertiesSet() throws Exception { - if (getSecureObjectClass() == null) { - throw new IllegalArgumentException( - "Subclass must provide a non-null response to getSecureObjectClass()"); - } + Assert.notNull(getSecureObjectClass(), "Subclass must provide a non-null response to getSecureObjectClass()"); - if (this.authenticationManager == null) { - throw new IllegalArgumentException( - "An AuthenticationManager is required"); - } + Assert.notNull(this.authenticationManager, "An AuthenticationManager is required"); - if (this.accessDecisionManager == null) { - throw new IllegalArgumentException( - "An AccessDecisionManager is required"); - } + Assert.notNull(this.accessDecisionManager, "An AccessDecisionManager is required"); - if (this.runAsManager == null) { - throw new IllegalArgumentException("A RunAsManager is required"); - } + Assert.notNull(this.runAsManager, "A RunAsManager is required"); - if (this.obtainObjectDefinitionSource() == null) { - throw new IllegalArgumentException( - "An ObjectDefinitionSource is required"); - } + Assert.notNull(this.obtainObjectDefinitionSource(), "An ObjectDefinitionSource is required"); if (!this.obtainObjectDefinitionSource().supports(getSecureObjectClass())) { - throw new IllegalArgumentException( - "ObjectDefinitionSource does not support secure object class: " - + getSecureObjectClass()); + throw new IllegalArgumentException("ObjectDefinitionSource does not support secure object class: " + + getSecureObjectClass()); } if (!this.runAsManager.supports(getSecureObjectClass())) { - throw new IllegalArgumentException( - "RunAsManager does not support secure object class: " - + getSecureObjectClass()); + throw new IllegalArgumentException("RunAsManager does not support secure object class: " + + getSecureObjectClass()); } if (!this.accessDecisionManager.supports(getSecureObjectClass())) { - throw new IllegalArgumentException( - "AccessDecisionManager does not support secure object class: " - + getSecureObjectClass()); + throw new IllegalArgumentException("AccessDecisionManager does not support secure object class: " + + getSecureObjectClass()); } if ((this.afterInvocationManager != null) - && !this.afterInvocationManager.supports(getSecureObjectClass())) { - throw new IllegalArgumentException( - "AfterInvocationManager does not support secure object class: " - + getSecureObjectClass()); + && !this.afterInvocationManager.supports(getSecureObjectClass())) { + throw new IllegalArgumentException("AfterInvocationManager does not support secure object class: " + + getSecureObjectClass()); } if (this.validateConfigAttributes) { Iterator iter = this.obtainObjectDefinitionSource() - .getConfigAttributeDefinitions(); + .getConfigAttributeDefinitions(); if (iter == null) { if (logger.isWarnEnabled()) { - logger.warn( - "Could not validate configuration attributes as the MethodDefinitionSource did not return a ConfigAttributeDefinition Iterator"); + logger.warn("Could not validate configuration attributes as the MethodDefinitionSource did not return a ConfigAttributeDefinition Iterator"); } } else { Set set = new HashSet(); while (iter.hasNext()) { ConfigAttributeDefinition def = (ConfigAttributeDefinition) iter - .next(); + .next(); Iterator attributes = def.getConfigAttributes(); while (attributes.hasNext()) { ConfigAttribute attr = (ConfigAttribute) attributes - .next(); + .next(); if (!this.runAsManager.supports(attr) - && !this.accessDecisionManager.supports(attr) - && ((this.afterInvocationManager == null) - || !this.afterInvocationManager.supports(attr))) { + && !this.accessDecisionManager.supports(attr) + && ((this.afterInvocationManager == null) + || !this.afterInvocationManager.supports(attr))) { set.add(attr); } } @@ -305,9 +287,8 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, logger.info("Validated configuration attributes"); } } else { - throw new IllegalArgumentException( - "Unsupported configuration attributes: " - + set.toString()); + throw new IllegalArgumentException("Unsupported configuration attributes: " + + set.toString()); } } } @@ -354,31 +335,25 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, } protected InterceptorStatusToken beforeInvocation(Object object) { - if (object == null) { - throw new IllegalArgumentException("Object was null"); - } - - if (!getSecureObjectClass().isAssignableFrom(object.getClass())) { - throw new IllegalArgumentException( - "Security invocation attempted for object " + object - + " but AbstractSecurityInterceptor only configured to support secure objects of type: " - + getSecureObjectClass()); - } + Assert.notNull(object, "Object was null"); + Assert.isTrue(getSecureObjectClass().isAssignableFrom(object.getClass()), "Security invocation attempted for object " + object + + " but AbstractSecurityInterceptor only configured to support secure objects of type: " + + getSecureObjectClass()); ConfigAttributeDefinition attr = this.obtainObjectDefinitionSource() - .getAttributes(object); + .getAttributes(object); if (attr != null) { if (logger.isDebugEnabled()) { logger.debug("Secure object: " + object.toString() - + "; ConfigAttributes: " + attr.toString()); + + "; ConfigAttributes: " + attr.toString()); } // Ensure ContextHolder presents a populated SecureContext if ((ContextHolder.getContext() == null) - || !(ContextHolder.getContext() instanceof SecureContext)) { + || !(ContextHolder.getContext() instanceof SecureContext)) { credentialsNotFound("A valid SecureContext was not provided in the RequestContext", - object, attr); + object, attr); } SecureContext context = (SecureContext) ContextHolder.getContext(); @@ -387,7 +362,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, // not call Context.validate() like the ContextInterceptor) if (context.getAuthentication() == null) { credentialsNotFound("Authentication credentials were not found in the SecureContext", - object, attr); + object, attr); } // Attempt authentication @@ -439,23 +414,22 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, if (runAs == null) { if (logger.isDebugEnabled()) { - logger.debug( - "RunAsManager did not change Authentication object"); + logger.debug("RunAsManager did not change Authentication object"); } return new InterceptorStatusToken(authenticated, false, attr, - object); // no further work post-invocation + object); // no further work post-invocation } else { if (logger.isDebugEnabled()) { logger.debug("Switching to RunAs Authentication: " - + runAs.toString()); + + runAs.toString()); } context.setAuthentication(runAs); ContextHolder.setContext((Context) context); return new InterceptorStatusToken(authenticated, true, attr, - object); // revert to token.Authenticated post-invocation + object); // revert to token.Authenticated post-invocation } } else { if (logger.isDebugEnabled()) { @@ -466,14 +440,13 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, // Set Authentication object (if it exists) to be unauthenticated if ((ContextHolder.getContext() != null) - && ContextHolder.getContext() instanceof SecureContext) { + && ContextHolder.getContext() instanceof SecureContext) { SecureContext context = (SecureContext) ContextHolder - .getContext(); + .getContext(); if (context.getAuthentication() != null) { if (logger.isDebugEnabled()) { - logger.debug( - "Authentication object detected and tagged as unauthenticated"); + logger.debug("Authentication object detected and tagged as unauthenticated"); } Authentication authenticated = context.getAuthentication(); diff --git a/core/src/main/java/org/acegisecurity/intercept/method/AbstractMethodDefinitionSource.java b/core/src/main/java/org/acegisecurity/intercept/method/AbstractMethodDefinitionSource.java index be9716ebac..c6a5271950 100644 --- a/core/src/main/java/org/acegisecurity/intercept/method/AbstractMethodDefinitionSource.java +++ b/core/src/main/java/org/acegisecurity/intercept/method/AbstractMethodDefinitionSource.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.reflect.CodeSignature; +import org.springframework.util.Assert; import java.lang.reflect.Method; @@ -44,9 +45,7 @@ public abstract class AbstractMethodDefinitionSource public ConfigAttributeDefinition getAttributes(Object object) throws IllegalArgumentException { - if (object == null) { - throw new IllegalArgumentException("Object cannot be null"); - } + Assert.notNull(object, "Object cannot be null"); if (object instanceof MethodInvocation) { return this.lookupAttributes(((MethodInvocation) object).getMethod()); @@ -57,7 +56,7 @@ public abstract class AbstractMethodDefinitionSource Class targetClazz = jp.getTarget().getClass(); String targetMethodName = jp.getStaticPart().getSignature().getName(); Class[] types = ((CodeSignature) jp.getStaticPart().getSignature()) - .getParameterTypes(); + .getParameterTypes(); if (logger.isDebugEnabled()) { logger.debug("Target Class: " + targetClazz); @@ -66,22 +65,19 @@ public abstract class AbstractMethodDefinitionSource for (int i = 0; i < types.length; i++) { if (logger.isDebugEnabled()) { logger.debug("Target Method Arg #" + i + ": " - + types[i]); + + types[i]); } } } try { - return this.lookupAttributes(targetClazz.getMethod( - targetMethodName, types)); + return this.lookupAttributes(targetClazz.getMethod(targetMethodName, types)); } catch (NoSuchMethodException nsme) { - throw new IllegalArgumentException( - "Could not obtain target method from JoinPoint: " + jp); + throw new IllegalArgumentException("Could not obtain target method from JoinPoint: " + jp); } } - throw new IllegalArgumentException( - "Object must be a MethodInvocation or JoinPoint"); + throw new IllegalArgumentException("Object must be a MethodInvocation or JoinPoint"); } public boolean supports(Class clazz) { diff --git a/core/src/main/java/org/acegisecurity/providers/anonymous/AnonymousAuthenticationToken.java b/core/src/main/java/org/acegisecurity/providers/anonymous/AnonymousAuthenticationToken.java index 2f52920f58..51d75b6fa9 100644 --- a/core/src/main/java/org/acegisecurity/providers/anonymous/AnonymousAuthenticationToken.java +++ b/core/src/main/java/org/acegisecurity/providers/anonymous/AnonymousAuthenticationToken.java @@ -20,6 +20,8 @@ import net.sf.acegisecurity.providers.AbstractAuthenticationToken; import java.io.Serializable; +import org.springframework.util.Assert; + /** * Represents an anonymous Authentication. @@ -56,11 +58,9 @@ public class AnonymousAuthenticationToken extends AbstractAuthenticationToken } for (int i = 0; i < authorities.length; i++) { - if (authorities[i] == null) { - throw new IllegalArgumentException("Granted authority element " + Assert.notNull(authorities[i], "Granted authority element " + i + " is null - GrantedAuthority[] cannot contain any null elements"); - } } this.keyHash = key.hashCode(); diff --git a/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationProvider.java index 62995500db..e58b7fa7d0 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationProvider.java @@ -27,6 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** @@ -104,28 +105,11 @@ public class CasAuthenticationProvider implements AuthenticationProvider, } public void afterPropertiesSet() throws Exception { - if (this.casAuthoritiesPopulator == null) { - throw new IllegalArgumentException( - "A casAuthoritiesPopulator must be set"); - } - - if (this.ticketValidator == null) { - throw new IllegalArgumentException("A ticketValidator must be set"); - } - - if (this.casProxyDecider == null) { - throw new IllegalArgumentException("A casProxyDecider must be set"); - } - - if (this.statelessTicketCache == null) { - throw new IllegalArgumentException( - "A statelessTicketCache must be set"); - } - - if (key == null) { - throw new IllegalArgumentException( - "A Key is required so CasAuthenticationProvider can identify tokens it previously authenticated"); - } + Assert.notNull(this.casAuthoritiesPopulator, "A casAuthoritiesPopulator must be set"); + Assert.notNull(this.ticketValidator, "A ticketValidator must be set"); + Assert.notNull(this.casProxyDecider, "A casProxyDecider must be set"); + Assert.notNull(this.statelessTicketCache, "A statelessTicketCache must be set"); + Assert.notNull(key, "A Key is required so CasAuthenticationProvider can identify tokens it previously authenticated"); } public Authentication authenticate(Authentication authentication) diff --git a/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationToken.java b/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationToken.java index 1e3dd09ad4..9b894b6858 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationToken.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/CasAuthenticationToken.java @@ -23,6 +23,8 @@ import java.io.Serializable; import java.util.List; +import org.springframework.util.Assert; + /** * Represents a successful CAS Authentication. @@ -77,11 +79,9 @@ public class CasAuthenticationToken extends AbstractAuthenticationToken } for (int i = 0; i < authorities.length; i++) { - if (authorities[i] == null) { - throw new IllegalArgumentException("Granted authority element " + Assert.notNull(authorities[i], "Granted authority element " + i + " is null - GrantedAuthority[] cannot contain any null elements"); - } } this.keyHash = key.hashCode(); diff --git a/core/src/main/java/org/acegisecurity/providers/cas/cache/EhCacheBasedTicketCache.java b/core/src/main/java/org/acegisecurity/providers/cas/cache/EhCacheBasedTicketCache.java index c68d9e0fb4..7fff47ed79 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/cache/EhCacheBasedTicketCache.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/cache/EhCacheBasedTicketCache.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.util.Assert; /** @@ -80,9 +81,7 @@ public class EhCacheBasedTicketCache implements StatelessTicketCache, } public void afterPropertiesSet() throws Exception { - if (cache == null) { - throw new IllegalArgumentException("cache mandatory"); - } + Assert.notNull(cache, "cache mandatory"); } public void putTicketInCache(CasAuthenticationToken token) { diff --git a/core/src/main/java/org/acegisecurity/providers/cas/populator/DaoCasAuthoritiesPopulator.java b/core/src/main/java/org/acegisecurity/providers/cas/populator/DaoCasAuthoritiesPopulator.java index d6423f2c49..b1cc53f625 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/populator/DaoCasAuthoritiesPopulator.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/populator/DaoCasAuthoritiesPopulator.java @@ -21,6 +21,7 @@ import net.sf.acegisecurity.providers.cas.CasAuthoritiesPopulator; import net.sf.acegisecurity.providers.dao.AuthenticationDao; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** @@ -58,9 +59,6 @@ public class DaoCasAuthoritiesPopulator implements CasAuthoritiesPopulator, } public void afterPropertiesSet() throws Exception { - if (this.authenticationDao == null) { - throw new IllegalArgumentException( - "An authenticationDao must be set"); - } + Assert.notNull(this.authenticationDao, "An authenticationDao must be set"); } } diff --git a/core/src/main/java/org/acegisecurity/providers/cas/proxy/AcceptAnyCasProxy.java b/core/src/main/java/org/acegisecurity/providers/cas/proxy/AcceptAnyCasProxy.java index f6fa468b90..359fb3c650 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/proxy/AcceptAnyCasProxy.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/proxy/AcceptAnyCasProxy.java @@ -20,6 +20,7 @@ import net.sf.acegisecurity.providers.cas.ProxyUntrustedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.Assert; import java.util.List; @@ -44,9 +45,7 @@ public class AcceptAnyCasProxy implements CasProxyDecider { public void confirmProxyListTrusted(List proxyList) throws ProxyUntrustedException { - if (proxyList == null) { - throw new IllegalArgumentException("proxyList cannot be null"); - } + Assert.notNull(proxyList, "proxyList cannot be null"); if (logger.isDebugEnabled()) { logger.debug("Always accepting proxy list: " + proxyList.toString()); diff --git a/core/src/main/java/org/acegisecurity/providers/cas/proxy/NamedCasProxyDecider.java b/core/src/main/java/org/acegisecurity/providers/cas/proxy/NamedCasProxyDecider.java index 5a0e60b58f..9875fc455a 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/proxy/NamedCasProxyDecider.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/proxy/NamedCasProxyDecider.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.util.List; @@ -58,17 +59,12 @@ public class NamedCasProxyDecider implements CasProxyDecider, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (this.validProxies == null) { - throw new IllegalArgumentException( - "A validProxies list must be set"); - } + Assert.notNull(this.validProxies, "A validProxies list must be set"); } public void confirmProxyListTrusted(List proxyList) throws ProxyUntrustedException { - if (proxyList == null) { - throw new IllegalArgumentException("proxyList cannot be null"); - } + Assert.notNull(proxyList, "proxyList cannot be null"); if (logger.isDebugEnabled()) { logger.debug("Proxy list: " + proxyList.toString()); @@ -81,7 +77,7 @@ public class NamedCasProxyDecider implements CasProxyDecider, InitializingBean { if (!validProxies.contains(proxyList.get(0))) { throw new ProxyUntrustedException("Nearest proxy '" - + proxyList.get(0) + "' is untrusted"); + + proxyList.get(0) + "' is untrusted"); } } } diff --git a/core/src/main/java/org/acegisecurity/providers/cas/proxy/RejectProxyTickets.java b/core/src/main/java/org/acegisecurity/providers/cas/proxy/RejectProxyTickets.java index 92aab08fc7..13864f617e 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/proxy/RejectProxyTickets.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/proxy/RejectProxyTickets.java @@ -20,6 +20,7 @@ import net.sf.acegisecurity.providers.cas.ProxyUntrustedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.Assert; import java.util.List; @@ -44,9 +45,7 @@ public class RejectProxyTickets implements CasProxyDecider { public void confirmProxyListTrusted(List proxyList) throws ProxyUntrustedException { - if (proxyList == null) { - throw new IllegalArgumentException("proxyList cannot be null"); - } + Assert.notNull(proxyList, "proxyList cannot be null"); if (proxyList.size() == 0) { // A Service Ticket (not a Proxy Ticket) @@ -55,7 +54,7 @@ public class RejectProxyTickets implements CasProxyDecider { if (logger.isDebugEnabled()) { logger.debug("Proxies are unacceptable; proxy list provided: " - + proxyList.toString()); + + proxyList.toString()); } throw new ProxyUntrustedException("Proxy tickets are rejected"); diff --git a/core/src/main/java/org/acegisecurity/providers/cas/ticketvalidator/AbstractTicketValidator.java b/core/src/main/java/org/acegisecurity/providers/cas/ticketvalidator/AbstractTicketValidator.java index 1cd25cc9c3..fb7a12243f 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/ticketvalidator/AbstractTicketValidator.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/ticketvalidator/AbstractTicketValidator.java @@ -19,6 +19,7 @@ import net.sf.acegisecurity.providers.cas.TicketValidator; import net.sf.acegisecurity.ui.cas.ServiceProperties; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** @@ -80,14 +81,8 @@ public abstract class AbstractTicketValidator implements TicketValidator, } public void afterPropertiesSet() throws Exception { - if ((this.casValidate == null) || "".equals(casValidate)) { - throw new IllegalArgumentException("A casValidate URL must be set"); - } - - if (serviceProperties == null) { - throw new IllegalArgumentException( - "serviceProperties must be specified"); - } + Assert.hasLength(casValidate, "A casValidate URL must be set"); + Assert.notNull(serviceProperties, "serviceProperties must be specified"); if ((trustStore != null) && (!"".equals(trustStore))) { System.setProperty("javax.net.ssl.trustStore", trustStore); diff --git a/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java index 2296f21f5d..a8ba4355e8 100644 --- a/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java @@ -45,6 +45,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.dao.DataAccessException; +import org.springframework.util.Assert; /** @@ -196,14 +197,8 @@ public class DaoAuthenticationProvider implements AuthenticationProvider, } public void afterPropertiesSet() throws Exception { - if (this.authenticationDao == null) { - throw new IllegalArgumentException( - "An Authentication DAO must be set"); - } - - if (this.userCache == null) { - throw new IllegalArgumentException("A user cache must be set"); - } + Assert.notNull(this.authenticationDao, "An Authentication DAO must be set"); + Assert.notNull(this.userCache, "A user cache must be set"); } public Authentication authenticate(Authentication authentication) diff --git a/core/src/main/java/org/acegisecurity/providers/dao/PasswordDaoAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/dao/PasswordDaoAuthenticationProvider.java index 83955036d8..ff6490a621 100644 --- a/core/src/main/java/org/acegisecurity/providers/dao/PasswordDaoAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/dao/PasswordDaoAuthenticationProvider.java @@ -42,6 +42,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.dao.DataAccessException; +import org.springframework.util.Assert; /** @@ -141,14 +142,8 @@ public class PasswordDaoAuthenticationProvider implements AuthenticationProvider } public void afterPropertiesSet() throws Exception { - if (this.authenticationDao == null) { - throw new IllegalArgumentException( - "A Password authentication DAO must be set"); - } - - if (this.userCache == null) { - throw new IllegalArgumentException("A user cache must be set"); - } + Assert.notNull(this.authenticationDao, "A Password authentication DAO must be set"); + Assert.notNull(this.userCache, "A user cache must be set"); } public Authentication authenticate(Authentication authentication) diff --git a/core/src/main/java/org/acegisecurity/providers/dao/cache/EhCacheBasedUserCache.java b/core/src/main/java/org/acegisecurity/providers/dao/cache/EhCacheBasedUserCache.java index a59726b7d2..e4cc1ba448 100644 --- a/core/src/main/java/org/acegisecurity/providers/dao/cache/EhCacheBasedUserCache.java +++ b/core/src/main/java/org/acegisecurity/providers/dao/cache/EhCacheBasedUserCache.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.util.Assert; /** @@ -79,9 +80,7 @@ public class EhCacheBasedUserCache implements UserCache, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (cache == null) { - throw new IllegalArgumentException("cache mandatory"); - } + Assert.notNull(cache, "cache mandatory"); } public void putUserInCache(UserDetails user) { diff --git a/core/src/main/java/org/acegisecurity/providers/dao/event/AuthenticationEvent.java b/core/src/main/java/org/acegisecurity/providers/dao/event/AuthenticationEvent.java index 20a358a1bc..f31cb73e18 100644 --- a/core/src/main/java/org/acegisecurity/providers/dao/event/AuthenticationEvent.java +++ b/core/src/main/java/org/acegisecurity/providers/dao/event/AuthenticationEvent.java @@ -20,6 +20,7 @@ import net.sf.acegisecurity.UserDetails; import net.sf.acegisecurity.providers.dao.User; import org.springframework.context.ApplicationEvent; +import org.springframework.util.Assert; /** @@ -53,9 +54,7 @@ public abstract class AuthenticationEvent extends ApplicationEvent { super(authentication); // No need to check authentication isn't null, as done by super - if (user == null) { - throw new IllegalArgumentException("User is required"); - } + Assert.notNull(user, "User is required"); this.user = user; } diff --git a/core/src/main/java/org/acegisecurity/providers/jaas/JaasAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/jaas/JaasAuthenticationProvider.java index cfc6dd53d5..1b62240a31 100644 --- a/core/src/main/java/org/acegisecurity/providers/jaas/JaasAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/jaas/JaasAuthenticationProvider.java @@ -259,14 +259,9 @@ public class JaasAuthenticationProvider implements AuthenticationProvider, public void afterPropertiesSet() throws Exception { - if (loginConfig == null) { - throw new IllegalArgumentException("loginConfig must be set on " - + getClass()); - } - - if ((loginContextName == null) || "".equals(loginContextName)) { - throw new IllegalArgumentException("loginContextName must be set on " + getClass()); - } + Assert.notNull(loginConfig, "loginConfig must be set on " + + getClass()); + Assert.hasLength(loginContextName, "loginContextName must be set on " + getClass()); String loginConfigStr = null; diff --git a/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationManagerImpl.java b/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationManagerImpl.java index 70f4168b84..800d629370 100644 --- a/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationManagerImpl.java +++ b/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationManagerImpl.java @@ -21,6 +21,7 @@ import net.sf.acegisecurity.GrantedAuthority; import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** @@ -53,10 +54,7 @@ public class RemoteAuthenticationManagerImpl } public void afterPropertiesSet() throws Exception { - if (this.authenticationManager == null) { - throw new IllegalArgumentException( - "authenticationManager is required"); - } + Assert.notNull(this.authenticationManager, "authenticationManager is required"); } public GrantedAuthority[] attemptAuthentication(String username, diff --git a/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationProvider.java index 3bea7b33fb..3f90bccee7 100644 --- a/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/rcp/RemoteAuthenticationProvider.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** @@ -79,10 +80,7 @@ public class RemoteAuthenticationProvider implements AuthenticationProvider, } public void afterPropertiesSet() throws Exception { - if (this.remoteAuthenticationManager == null) { - throw new IllegalArgumentException( - "remoteAuthenticationManager is mandatory"); - } + Assert.notNull(this.remoteAuthenticationManager, "remoteAuthenticationManager is mandatory"); } public Authentication authenticate(Authentication authentication) diff --git a/core/src/main/java/org/acegisecurity/providers/rememberme/RememberMeAuthenticationToken.java b/core/src/main/java/org/acegisecurity/providers/rememberme/RememberMeAuthenticationToken.java index 9917e8be5e..08219f9d0e 100644 --- a/core/src/main/java/org/acegisecurity/providers/rememberme/RememberMeAuthenticationToken.java +++ b/core/src/main/java/org/acegisecurity/providers/rememberme/RememberMeAuthenticationToken.java @@ -20,6 +20,8 @@ import net.sf.acegisecurity.providers.AbstractAuthenticationToken; import java.io.Serializable; +import org.springframework.util.Assert; + /** * Represents a remembered Authentication. @@ -62,11 +64,9 @@ public class RememberMeAuthenticationToken extends AbstractAuthenticationToken } for (int i = 0; i < authorities.length; i++) { - if (authorities[i] == null) { - throw new IllegalArgumentException("Granted authority element " + Assert.notNull(authorities[i], "Granted authority element " + i + " is null - GrantedAuthority[] cannot contain any null elements"); - } } this.keyHash = key.hashCode(); diff --git a/core/src/main/java/org/acegisecurity/runas/RunAsImplAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/runas/RunAsImplAuthenticationProvider.java index e57c47b0bd..e49a8d12f5 100644 --- a/core/src/main/java/org/acegisecurity/runas/RunAsImplAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/runas/RunAsImplAuthenticationProvider.java @@ -21,6 +21,7 @@ import net.sf.acegisecurity.BadCredentialsException; import net.sf.acegisecurity.providers.AuthenticationProvider; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; /** @@ -58,10 +59,7 @@ public class RunAsImplAuthenticationProvider implements InitializingBean, } public void afterPropertiesSet() throws Exception { - if (key == null) { - throw new IllegalArgumentException( - "A Key is required and should match that configured for the RunAsManagerImpl"); - } + Assert.notNull(key, "A Key is required and should match that configured for the RunAsManagerImpl"); } public Authentication authenticate(Authentication authentication) diff --git a/core/src/main/java/org/acegisecurity/runas/RunAsManagerImpl.java b/core/src/main/java/org/acegisecurity/runas/RunAsManagerImpl.java index 8c4471b361..9d462292b8 100644 --- a/core/src/main/java/org/acegisecurity/runas/RunAsManagerImpl.java +++ b/core/src/main/java/org/acegisecurity/runas/RunAsManagerImpl.java @@ -23,6 +23,7 @@ import net.sf.acegisecurity.GrantedAuthorityImpl; import net.sf.acegisecurity.RunAsManager; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.util.Iterator; import java.util.List; @@ -94,10 +95,7 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (key == null) { - throw new IllegalArgumentException( - "A Key is required and should match that configured for the RunAsImplAuthenticationProvider"); - } + Assert.notNull(key, "A Key is required and should match that configured for the RunAsImplAuthenticationProvider"); } public Authentication buildRunAs(Authentication authentication, diff --git a/core/src/main/java/org/acegisecurity/securechannel/ChannelProcessingFilter.java b/core/src/main/java/org/acegisecurity/securechannel/ChannelProcessingFilter.java index 92be0da303..8f9223f62d 100644 --- a/core/src/main/java/org/acegisecurity/securechannel/ChannelProcessingFilter.java +++ b/core/src/main/java/org/acegisecurity/securechannel/ChannelProcessingFilter.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -96,23 +97,15 @@ public class ChannelProcessingFilter implements InitializingBean, Filter { } public void afterPropertiesSet() throws Exception { - if (filterInvocationDefinitionSource == null) { - throw new IllegalArgumentException( - "filterInvocationDefinitionSource must be specified"); - } - - if (channelDecisionManager == null) { - throw new IllegalArgumentException( - "channelDecisionManager must be specified"); - } + Assert.notNull(filterInvocationDefinitionSource, "filterInvocationDefinitionSource must be specified"); + Assert.notNull(channelDecisionManager, "channelDecisionManager must be specified"); Iterator iter = this.filterInvocationDefinitionSource - .getConfigAttributeDefinitions(); + .getConfigAttributeDefinitions(); if (iter == null) { if (logger.isWarnEnabled()) { - logger.warn( - "Could not validate configuration attributes as the FilterInvocationDefinitionSource did not return a ConfigAttributeDefinition Iterator"); + logger.warn("Could not validate configuration attributes as the FilterInvocationDefinitionSource did not return a ConfigAttributeDefinition Iterator"); } return; @@ -122,7 +115,7 @@ public class ChannelProcessingFilter implements InitializingBean, Filter { while (iter.hasNext()) { ConfigAttributeDefinition def = (ConfigAttributeDefinition) iter - .next(); + .next(); Iterator attributes = def.getConfigAttributes(); while (attributes.hasNext()) { @@ -139,8 +132,7 @@ public class ChannelProcessingFilter implements InitializingBean, Filter { logger.info("Validated configuration attributes"); } } else { - throw new IllegalArgumentException( - "Unsupported configuration attributes: " + set.toString()); + throw new IllegalArgumentException("Unsupported configuration attributes: " + set.toString()); } } diff --git a/core/src/main/java/org/acegisecurity/securechannel/InsecureChannelProcessor.java b/core/src/main/java/org/acegisecurity/securechannel/InsecureChannelProcessor.java index 23c2204c2d..0966850ec9 100644 --- a/core/src/main/java/org/acegisecurity/securechannel/InsecureChannelProcessor.java +++ b/core/src/main/java/org/acegisecurity/securechannel/InsecureChannelProcessor.java @@ -20,6 +20,7 @@ import net.sf.acegisecurity.ConfigAttributeDefinition; import net.sf.acegisecurity.intercept.web.FilterInvocation; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -77,13 +78,8 @@ public class InsecureChannelProcessor implements InitializingBean, } public void afterPropertiesSet() throws Exception { - if ((insecureKeyword == null) || "".equals(insecureKeyword)) { - throw new IllegalArgumentException("insecureKeyword required"); - } - - if (entryPoint == null) { - throw new IllegalArgumentException("entryPoint required"); - } + Assert.hasLength(insecureKeyword, "insecureKeyword required"); + Assert.notNull(entryPoint, "entryPoint required"); } public void decide(FilterInvocation invocation, diff --git a/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpEntryPoint.java b/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpEntryPoint.java index da7647842c..44525b749c 100644 --- a/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpEntryPoint.java +++ b/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpEntryPoint.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -76,13 +77,8 @@ public class RetryWithHttpEntryPoint implements InitializingBean, } public void afterPropertiesSet() throws Exception { - if (portMapper == null) { - throw new IllegalArgumentException("portMapper is required"); - } - - if (portResolver == null) { - throw new IllegalArgumentException("portResolver is required"); - } + Assert.notNull(portMapper, "portMapper is required"); + Assert.notNull(portResolver, "portResolver is required"); } public void commence(ServletRequest request, ServletResponse response) diff --git a/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpsEntryPoint.java b/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpsEntryPoint.java index 71127d6468..26fe9e9438 100644 --- a/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpsEntryPoint.java +++ b/core/src/main/java/org/acegisecurity/securechannel/RetryWithHttpsEntryPoint.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -76,13 +77,8 @@ public class RetryWithHttpsEntryPoint implements InitializingBean, } public void afterPropertiesSet() throws Exception { - if (portMapper == null) { - throw new IllegalArgumentException("portMapper is required"); - } - - if (portResolver == null) { - throw new IllegalArgumentException("portResolver is required"); - } + Assert.notNull(portMapper, "portMapper is required"); + Assert.notNull(portResolver, "portResolver is required"); } public void commence(ServletRequest request, ServletResponse response) diff --git a/core/src/main/java/org/acegisecurity/securechannel/SecureChannelProcessor.java b/core/src/main/java/org/acegisecurity/securechannel/SecureChannelProcessor.java index 4c9367f43b..6e1e4d68ae 100644 --- a/core/src/main/java/org/acegisecurity/securechannel/SecureChannelProcessor.java +++ b/core/src/main/java/org/acegisecurity/securechannel/SecureChannelProcessor.java @@ -20,6 +20,7 @@ import net.sf.acegisecurity.ConfigAttributeDefinition; import net.sf.acegisecurity.intercept.web.FilterInvocation; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -76,20 +77,13 @@ public class SecureChannelProcessor implements InitializingBean, } public void afterPropertiesSet() throws Exception { - if ((secureKeyword == null) || "".equals(secureKeyword)) { - throw new IllegalArgumentException("secureKeyword required"); - } - - if (entryPoint == null) { - throw new IllegalArgumentException("entryPoint required"); - } + Assert.hasLength(secureKeyword, "secureKeyword required"); + Assert.notNull(entryPoint, "entryPoint required"); } public void decide(FilterInvocation invocation, ConfigAttributeDefinition config) throws IOException, ServletException { - if ((invocation == null) || (config == null)) { - throw new IllegalArgumentException("Nulls cannot be provided"); - } + Assert.isTrue((invocation != null) && (config != null), "Nulls cannot be provided"); Iterator iter = config.getConfigAttributes(); diff --git a/core/src/main/java/org/acegisecurity/ui/basicauth/BasicProcessingFilter.java b/core/src/main/java/org/acegisecurity/ui/basicauth/BasicProcessingFilter.java index 8340940bb0..6c93a8f0de 100644 --- a/core/src/main/java/org/acegisecurity/ui/basicauth/BasicProcessingFilter.java +++ b/core/src/main/java/org/acegisecurity/ui/basicauth/BasicProcessingFilter.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -132,15 +133,8 @@ public class BasicProcessingFilter implements Filter, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (this.authenticationManager == null) { - throw new IllegalArgumentException( - "An AuthenticationManager is required"); - } - - if (this.authenticationEntryPoint == null) { - throw new IllegalArgumentException( - "An AuthenticationEntryPoint is required"); - } + Assert.notNull(this.authenticationManager, "An AuthenticationManager is required"); + Assert.notNull(this.authenticationEntryPoint, "An AuthenticationEntryPoint is required"); } public void destroy() {} diff --git a/core/src/main/java/org/acegisecurity/ui/cas/CasProcessingFilterEntryPoint.java b/core/src/main/java/org/acegisecurity/ui/cas/CasProcessingFilterEntryPoint.java index 59fd6ff4a7..c74eb36675 100644 --- a/core/src/main/java/org/acegisecurity/ui/cas/CasProcessingFilterEntryPoint.java +++ b/core/src/main/java/org/acegisecurity/ui/cas/CasProcessingFilterEntryPoint.java @@ -19,6 +19,7 @@ import net.sf.acegisecurity.AuthenticationException; import net.sf.acegisecurity.intercept.web.AuthenticationEntryPoint; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -79,14 +80,8 @@ public class CasProcessingFilterEntryPoint implements AuthenticationEntryPoint, } public void afterPropertiesSet() throws Exception { - if ((loginUrl == null) || "".equals(loginUrl)) { - throw new IllegalArgumentException("loginUrl must be specified"); - } - - if (serviceProperties == null) { - throw new IllegalArgumentException( - "serviceProperties must be specified"); - } + Assert.hasLength(loginUrl, "loginUrl must be specified"); + Assert.notNull(serviceProperties, "serviceProperties must be specified"); } public void commence(ServletRequest request, ServletResponse response, diff --git a/core/src/main/java/org/acegisecurity/ui/webapp/AuthenticationProcessingFilterEntryPoint.java b/core/src/main/java/org/acegisecurity/ui/webapp/AuthenticationProcessingFilterEntryPoint.java index 437060f567..239b9698d4 100644 --- a/core/src/main/java/org/acegisecurity/ui/webapp/AuthenticationProcessingFilterEntryPoint.java +++ b/core/src/main/java/org/acegisecurity/ui/webapp/AuthenticationProcessingFilterEntryPoint.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.io.IOException; @@ -121,17 +122,9 @@ public class AuthenticationProcessingFilterEntryPoint } public void afterPropertiesSet() throws Exception { - if ((loginFormUrl == null) || "".equals(loginFormUrl)) { - throw new IllegalArgumentException("loginFormUrl must be specified"); - } - - if (portMapper == null) { - throw new IllegalArgumentException("portMapper must be specified"); - } - - if (portResolver == null) { - throw new IllegalArgumentException("portResolver must be specified"); - } + Assert.hasLength(loginFormUrl,"loginFormUrl must be specified"); + Assert.notNull(portMapper, "portMapper must be specified"); + Assert.notNull(portResolver, "portResolver must be specified"); } public void commence(ServletRequest request, ServletResponse response, diff --git a/core/src/main/java/org/acegisecurity/userdetails/User.java b/core/src/main/java/org/acegisecurity/userdetails/User.java index 4400c0ab06..887df88eed 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/User.java +++ b/core/src/main/java/org/acegisecurity/userdetails/User.java @@ -17,6 +17,7 @@ package net.sf.acegisecurity.providers.dao; import net.sf.acegisecurity.GrantedAuthority; import net.sf.acegisecurity.UserDetails; +import org.springframework.util.Assert; /** @@ -134,11 +135,9 @@ public class User implements UserDetails { } for (int i = 0; i < authorities.length; i++) { - if (authorities[i] == null) { - throw new IllegalArgumentException("Granted authority element " + Assert.notNull(authorities[i], "Granted authority element " + i + " is null - GrantedAuthority[] cannot contain any null elements"); - } } this.username = username; diff --git a/core/src/main/java/org/acegisecurity/userdetails/memory/InMemoryDaoImpl.java b/core/src/main/java/org/acegisecurity/userdetails/memory/InMemoryDaoImpl.java index 64326b0101..5207673a56 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/memory/InMemoryDaoImpl.java +++ b/core/src/main/java/org/acegisecurity/userdetails/memory/InMemoryDaoImpl.java @@ -22,6 +22,7 @@ import net.sf.acegisecurity.providers.dao.UsernameNotFoundException; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; +import org.springframework.util.Assert; /** @@ -46,10 +47,7 @@ public class InMemoryDaoImpl implements AuthenticationDao, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (this.userMap == null) { - throw new IllegalArgumentException( - "A list of users, passwords, enabled/disabled status and their granted authorities must be set"); - } + Assert.notNull(this.userMap, "A list of users, passwords, enabled/disabled status and their granted authorities must be set"); } public UserDetails loadUserByUsername(String username) diff --git a/core/src/main/java/org/acegisecurity/userdetails/memory/UserMap.java b/core/src/main/java/org/acegisecurity/userdetails/memory/UserMap.java index bf184f1693..cb7710fdeb 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/memory/UserMap.java +++ b/core/src/main/java/org/acegisecurity/userdetails/memory/UserMap.java @@ -21,6 +21,7 @@ import net.sf.acegisecurity.providers.dao.UsernameNotFoundException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.Assert; import java.util.HashMap; import java.util.Map; @@ -82,9 +83,7 @@ public class UserMap { * @throws IllegalArgumentException if a null User was passed */ public void addUser(UserDetails user) throws IllegalArgumentException { - if (user == null) { - throw new IllegalArgumentException("Must be a valid User"); - } + Assert.notNull(user, "Must be a valid User"); logger.info("Adding user [" + user + "]"); this.userMap.put(user.getUsername().toLowerCase(), user); diff --git a/core/src/main/java/org/acegisecurity/util/FilterChainProxy.java b/core/src/main/java/org/acegisecurity/util/FilterChainProxy.java index 8a8609cbc3..3510115bb2 100644 --- a/core/src/main/java/org/acegisecurity/util/FilterChainProxy.java +++ b/core/src/main/java/org/acegisecurity/util/FilterChainProxy.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.util.Assert; import java.io.IOException; @@ -133,15 +134,8 @@ public class FilterChainProxy implements Filter, InitializingBean, } public void afterPropertiesSet() throws Exception { - if (filterInvocationDefinitionSource == null) { - throw new IllegalArgumentException( - "filterInvocationDefinitionSource must be specified"); - } - - if (this.filterInvocationDefinitionSource.getConfigAttributeDefinitions() == null) { - throw new IllegalArgumentException( - "FilterChainProxy requires the FitlerInvocationDefinitionSource to return a non-null response to getConfigAttributeDefinitions()"); - } + Assert.notNull(filterInvocationDefinitionSource, "filterInvocationDefinitionSource must be specified"); + Assert.notNull(this.filterInvocationDefinitionSource.getConfigAttributeDefinitions(), "FilterChainProxy requires the FitlerInvocationDefinitionSource to return a non-null response to getConfigAttributeDefinitions()"); } public void destroy() { @@ -252,11 +246,9 @@ public class FilterChainProxy implements Filter, InitializingBean, ConfigAttribute attr = (ConfigAttribute) attributes.next(); String filterName = attr.getAttribute(); - if (filterName == null) { - throw new IllegalArgumentException("Configuration attribute: '" + Assert.notNull(filterName, "Configuration attribute: '" + attr + "' returned null to the getAttribute() method, which is invalid when used with FilterChainProxy"); - } list.add(this.applicationContext.getBean(filterName, Filter.class)); } diff --git a/core/src/main/java/org/acegisecurity/util/PortMapperImpl.java b/core/src/main/java/org/acegisecurity/util/PortMapperImpl.java index 2bd699f350..15842d18d5 100644 --- a/core/src/main/java/org/acegisecurity/util/PortMapperImpl.java +++ b/core/src/main/java/org/acegisecurity/util/PortMapperImpl.java @@ -15,6 +15,8 @@ package net.sf.acegisecurity.util; +import org.springframework.util.Assert; + import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -75,10 +77,7 @@ public class PortMapperImpl implements PortMapper { * the range 1-65535 for that mapping. */ public void setPortMappings(Map newMappings) { - if (newMappings == null) { - throw new IllegalArgumentException( - "A valid list of HTTPS port mappings must be provided"); - } + Assert.notNull(newMappings, "A valid list of HTTPS port mappings must be provided"); httpsPortMappings.clear(); @@ -90,10 +89,9 @@ public class PortMapperImpl implements PortMapper { Integer httpsPort = new Integer((String) entry.getValue()); if ((httpPort.intValue() < 1) || (httpPort.intValue() > 65535) - || (httpsPort.intValue() < 1) || (httpsPort.intValue() > 65535)) { - throw new IllegalArgumentException( - "one or both ports out of legal range: " + httpPort + ", " - + httpsPort); + || (httpsPort.intValue() < 1) || (httpsPort.intValue() > 65535)) { + throw new IllegalArgumentException("one or both ports out of legal range: " + httpPort + ", " + + httpsPort); } httpsPortMappings.put(httpPort, httpsPort); diff --git a/core/src/main/java/org/acegisecurity/util/PortResolverImpl.java b/core/src/main/java/org/acegisecurity/util/PortResolverImpl.java index ce0e6f0bd7..a3915a5802 100644 --- a/core/src/main/java/org/acegisecurity/util/PortResolverImpl.java +++ b/core/src/main/java/org/acegisecurity/util/PortResolverImpl.java @@ -16,6 +16,7 @@ package net.sf.acegisecurity.util; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import javax.servlet.ServletRequest; @@ -78,8 +79,6 @@ public class PortResolverImpl implements InitializingBean, PortResolver { } public void afterPropertiesSet() throws Exception { - if (portMapper == null) { - throw new IllegalArgumentException("portMapper required"); - } + Assert.notNull(portMapper, "portMapper required"); } } diff --git a/core/src/main/java/org/acegisecurity/vote/BasicAclEntryVoter.java b/core/src/main/java/org/acegisecurity/vote/BasicAclEntryVoter.java index bf649dcc68..b19ac48de5 100644 --- a/core/src/main/java/org/acegisecurity/vote/BasicAclEntryVoter.java +++ b/core/src/main/java/org/acegisecurity/vote/BasicAclEntryVoter.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -194,23 +195,12 @@ public class BasicAclEntryVoter implements AccessDecisionVoter, } public void afterPropertiesSet() throws Exception { - if (processConfigAttribute == null) { - throw new IllegalArgumentException( - "A processConfigAttribute is mandatory"); - } + Assert.notNull(processConfigAttribute, "A processConfigAttribute is mandatory"); + Assert.notNull(aclManager, "An aclManager is mandatory"); + Assert.notNull(processDomainObjectClass, "A processDomainObjectClass is mandatory"); if ((requirePermission == null) || (requirePermission.length == 0)) { - throw new IllegalArgumentException( - "One or more requirePermission entries is mandatory"); - } - - if (aclManager == null) { - throw new IllegalArgumentException("An aclManager is mandatory"); - } - - if (processDomainObjectClass == null) { - throw new IllegalArgumentException( - "A processDomainObjectClass is mandatory"); + throw new IllegalArgumentException("One or more requirePermission entries is mandatory"); } } diff --git a/samples/contacts/src/main/java/sample/contact/AddPermissionController.java b/samples/contacts/src/main/java/sample/contact/AddPermissionController.java index ddc5ca8c10..84f5607138 100644 --- a/samples/contacts/src/main/java/sample/contact/AddPermissionController.java +++ b/samples/contacts/src/main/java/sample/contact/AddPermissionController.java @@ -27,6 +27,7 @@ import org.springframework.web.bind.RequestUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import org.springframework.web.servlet.view.RedirectView; +import org.springframework.util.Assert; import java.util.HashMap; import java.util.Iterator; @@ -60,10 +61,7 @@ public class AddPermissionController extends SimpleFormController } public void afterPropertiesSet() throws Exception { - if (contactManager == null) { - throw new IllegalArgumentException( - "A ContactManager implementation is required"); - } + Assert.notNull(contactManager, "A ContactManager implementation is required"); } protected ModelAndView disallowDuplicateFormSubmission( diff --git a/samples/contacts/src/main/java/sample/contact/AdminPermissionController.java b/samples/contacts/src/main/java/sample/contact/AdminPermissionController.java index 7bcd3ee23e..2651f2f32d 100644 --- a/samples/contacts/src/main/java/sample/contact/AdminPermissionController.java +++ b/samples/contacts/src/main/java/sample/contact/AdminPermissionController.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.web.bind.RequestUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; +import org.springframework.util.Assert; import java.io.IOException; @@ -65,15 +66,8 @@ public class AdminPermissionController implements Controller, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (contactManager == null) { - throw new IllegalArgumentException( - "A ContactManager implementation is required"); - } - - if (aclManager == null) { - throw new IllegalArgumentException( - "An aclManager implementation is required"); - } + Assert.notNull(contactManager, "A ContactManager implementation is required"); + Assert.notNull(aclManager, "An aclManager implementation is required"); } public ModelAndView handleRequest(HttpServletRequest request, diff --git a/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java b/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java index 6041d19625..9f4fd56f95 100644 --- a/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java +++ b/samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java @@ -26,6 +26,7 @@ import net.sf.acegisecurity.context.security.SecureContextUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.support.ApplicationObjectSupport; +import org.springframework.util.Assert; import java.util.List; import java.util.Random; @@ -122,13 +123,8 @@ public class ContactManagerBackend extends ApplicationObjectSupport } public void afterPropertiesSet() throws Exception { - if (contactDao == null) { - throw new IllegalArgumentException("contactDao required"); - } - - if (basicAclExtendedDao == null) { - throw new IllegalArgumentException("basicAclExtendedDao required"); - } + Assert.notNull(contactDao, "contactDao required"); + Assert.notNull(basicAclExtendedDao, "basicAclExtendedDao required"); } public void create(Contact contact) { diff --git a/samples/contacts/src/main/java/sample/contact/DataSourcePopulator.java b/samples/contacts/src/main/java/sample/contact/DataSourcePopulator.java index 2f5d0fb025..e5bd88852f 100644 --- a/samples/contacts/src/main/java/sample/contact/DataSourcePopulator.java +++ b/samples/contacts/src/main/java/sample/contact/DataSourcePopulator.java @@ -18,6 +18,7 @@ package sample.contact; import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.util.Assert; import javax.sql.DataSource; @@ -44,86 +45,47 @@ public class DataSourcePopulator implements InitializingBean { } public void afterPropertiesSet() throws Exception { - if (dataSource == null) { - throw new IllegalArgumentException("dataSource required"); - } + Assert.notNull(dataSource, "dataSource required"); JdbcTemplate template = new JdbcTemplate(dataSource); - template.execute( - "CREATE TABLE CONTACTS(ID INTEGER NOT NULL PRIMARY KEY, CONTACT_NAME VARCHAR_IGNORECASE(50) NOT NULL, EMAIL VARCHAR_IGNORECASE(50) NOT NULL)"); - template.execute( - "INSERT INTO contacts VALUES (1, 'John Smith', 'john@somewhere.com');"); // marissa - template.execute( - "INSERT INTO contacts VALUES (2, 'Michael Citizen', 'michael@xyz.com');"); // marissa - template.execute( - "INSERT INTO contacts VALUES (3, 'Joe Bloggs', 'joe@demo.com');"); // marissa - template.execute( - "INSERT INTO contacts VALUES (4, 'Karen Sutherland', 'karen@sutherland.com');"); // marissa + dianne + scott - template.execute( - "INSERT INTO contacts VALUES (5, 'Mitchell Howard', 'mitchell@abcdef.com');"); // dianne - template.execute( - "INSERT INTO contacts VALUES (6, 'Rose Costas', 'rose@xyz.com');"); // dianne + scott - template.execute( - "INSERT INTO contacts VALUES (7, 'Amanda Smith', 'amanda@abcdef.com');"); // scott - template.execute( - "INSERT INTO contacts VALUES (8, 'Cindy Smith', 'cindy@smith.com');"); // dianne + scott - template.execute( - "INSERT INTO contacts VALUES (9, 'Jonathan Citizen', 'jonathan@xyz.com');"); // scott - template.execute( - "CREATE TABLE ACL_OBJECT_IDENTITY(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,OBJECT_IDENTITY VARCHAR_IGNORECASE(250) NOT NULL,PARENT_OBJECT INTEGER,ACL_CLASS VARCHAR_IGNORECASE(250) NOT NULL,CONSTRAINT UNIQUE_OBJECT_IDENTITY UNIQUE(OBJECT_IDENTITY),CONSTRAINT SYS_FK_3 FOREIGN KEY(PARENT_OBJECT) REFERENCES ACL_OBJECT_IDENTITY(ID))"); - template.execute( - "INSERT INTO acl_object_identity VALUES (1, 'sample.contact.Contact:1', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (2, 'sample.contact.Contact:2', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (3, 'sample.contact.Contact:3', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (4, 'sample.contact.Contact:4', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (5, 'sample.contact.Contact:5', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (6, 'sample.contact.Contact:6', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (7, 'sample.contact.Contact:7', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (8, 'sample.contact.Contact:8', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "INSERT INTO acl_object_identity VALUES (9, 'sample.contact.Contact:9', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); - template.execute( - "CREATE TABLE ACL_PERMISSION(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,ACL_OBJECT_IDENTITY INTEGER NOT NULL,RECIPIENT VARCHAR_IGNORECASE(100) NOT NULL,MASK INTEGER NOT NULL,CONSTRAINT UNIQUE_RECIPIENT UNIQUE(ACL_OBJECT_IDENTITY,RECIPIENT),CONSTRAINT SYS_FK_7 FOREIGN KEY(ACL_OBJECT_IDENTITY) REFERENCES ACL_OBJECT_IDENTITY(ID))"); - template.execute( - "INSERT INTO acl_permission VALUES (null, 1, 'marissa', 1);"); // administer - template.execute( - "INSERT INTO acl_permission VALUES (null, 2, 'marissa', 2);"); // read - template.execute( - "INSERT INTO acl_permission VALUES (null, 3, 'marissa', 22);"); // read+write+delete - template.execute( - "INSERT INTO acl_permission VALUES (null, 4, 'marissa', 1);"); // administer - template.execute( - "INSERT INTO acl_permission VALUES (null, 4, 'dianne', 1);"); // administer - template.execute( - "INSERT INTO acl_permission VALUES (null, 4, 'scott', 2);"); // read - template.execute( - "INSERT INTO acl_permission VALUES (null, 5, 'dianne', 2);"); // read - template.execute( - "INSERT INTO acl_permission VALUES (null, 6, 'dianne', 22);"); // read+write+delete - template.execute( - "INSERT INTO acl_permission VALUES (null, 6, 'scott', 2);"); // read - template.execute( - "INSERT INTO acl_permission VALUES (null, 7, 'scott', 1);"); // administer - template.execute( - "INSERT INTO acl_permission VALUES (null, 8, 'dianne', 2);"); // read - template.execute( - "INSERT INTO acl_permission VALUES (null, 8, 'scott', 2);"); // read - template.execute( - "INSERT INTO acl_permission VALUES (null, 9, 'scott', 22);"); // read+write+delete - template.execute( - "CREATE TABLE USERS(USERNAME VARCHAR_IGNORECASE(50) NOT NULL PRIMARY KEY,PASSWORD VARCHAR_IGNORECASE(50) NOT NULL,ENABLED BOOLEAN NOT NULL);"); - template.execute( - "CREATE TABLE AUTHORITIES(USERNAME VARCHAR_IGNORECASE(50) NOT NULL,AUTHORITY VARCHAR_IGNORECASE(50) NOT NULL,CONSTRAINT FK_AUTHORITIES_USERS FOREIGN KEY(USERNAME) REFERENCES USERS(USERNAME));"); - template.execute( - "CREATE UNIQUE INDEX IX_AUTH_USERNAME ON AUTHORITIES(USERNAME,AUTHORITY);"); + template.execute("CREATE TABLE CONTACTS(ID INTEGER NOT NULL PRIMARY KEY, CONTACT_NAME VARCHAR_IGNORECASE(50) NOT NULL, EMAIL VARCHAR_IGNORECASE(50) NOT NULL)"); + template.execute("INSERT INTO contacts VALUES (1, 'John Smith', 'john@somewhere.com');"); // marissa + template.execute("INSERT INTO contacts VALUES (2, 'Michael Citizen', 'michael@xyz.com');"); // marissa + template.execute("INSERT INTO contacts VALUES (3, 'Joe Bloggs', 'joe@demo.com');"); // marissa + template.execute("INSERT INTO contacts VALUES (4, 'Karen Sutherland', 'karen@sutherland.com');"); // marissa + dianne + scott + template.execute("INSERT INTO contacts VALUES (5, 'Mitchell Howard', 'mitchell@abcdef.com');"); // dianne + template.execute("INSERT INTO contacts VALUES (6, 'Rose Costas', 'rose@xyz.com');"); // dianne + scott + template.execute("INSERT INTO contacts VALUES (7, 'Amanda Smith', 'amanda@abcdef.com');"); // scott + template.execute("INSERT INTO contacts VALUES (8, 'Cindy Smith', 'cindy@smith.com');"); // dianne + scott + template.execute("INSERT INTO contacts VALUES (9, 'Jonathan Citizen', 'jonathan@xyz.com');"); // scott + template.execute("CREATE TABLE ACL_OBJECT_IDENTITY(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,OBJECT_IDENTITY VARCHAR_IGNORECASE(250) NOT NULL,PARENT_OBJECT INTEGER,ACL_CLASS VARCHAR_IGNORECASE(250) NOT NULL,CONSTRAINT UNIQUE_OBJECT_IDENTITY UNIQUE(OBJECT_IDENTITY),CONSTRAINT SYS_FK_3 FOREIGN KEY(PARENT_OBJECT) REFERENCES ACL_OBJECT_IDENTITY(ID))"); + template.execute("INSERT INTO acl_object_identity VALUES (1, 'sample.contact.Contact:1', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (2, 'sample.contact.Contact:2', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (3, 'sample.contact.Contact:3', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (4, 'sample.contact.Contact:4', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (5, 'sample.contact.Contact:5', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (6, 'sample.contact.Contact:6', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (7, 'sample.contact.Contact:7', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (8, 'sample.contact.Contact:8', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("INSERT INTO acl_object_identity VALUES (9, 'sample.contact.Contact:9', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');"); + template.execute("CREATE TABLE ACL_PERMISSION(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,ACL_OBJECT_IDENTITY INTEGER NOT NULL,RECIPIENT VARCHAR_IGNORECASE(100) NOT NULL,MASK INTEGER NOT NULL,CONSTRAINT UNIQUE_RECIPIENT UNIQUE(ACL_OBJECT_IDENTITY,RECIPIENT),CONSTRAINT SYS_FK_7 FOREIGN KEY(ACL_OBJECT_IDENTITY) REFERENCES ACL_OBJECT_IDENTITY(ID))"); + template.execute("INSERT INTO acl_permission VALUES (null, 1, 'marissa', 1);"); // administer + template.execute("INSERT INTO acl_permission VALUES (null, 2, 'marissa', 2);"); // read + template.execute("INSERT INTO acl_permission VALUES (null, 3, 'marissa', 22);"); // read+write+delete + template.execute("INSERT INTO acl_permission VALUES (null, 4, 'marissa', 1);"); // administer + template.execute("INSERT INTO acl_permission VALUES (null, 4, 'dianne', 1);"); // administer + template.execute("INSERT INTO acl_permission VALUES (null, 4, 'scott', 2);"); // read + template.execute("INSERT INTO acl_permission VALUES (null, 5, 'dianne', 2);"); // read + template.execute("INSERT INTO acl_permission VALUES (null, 6, 'dianne', 22);"); // read+write+delete + template.execute("INSERT INTO acl_permission VALUES (null, 6, 'scott', 2);"); // read + template.execute("INSERT INTO acl_permission VALUES (null, 7, 'scott', 1);"); // administer + template.execute("INSERT INTO acl_permission VALUES (null, 8, 'dianne', 2);"); // read + template.execute("INSERT INTO acl_permission VALUES (null, 8, 'scott', 2);"); // read + template.execute("INSERT INTO acl_permission VALUES (null, 9, 'scott', 22);"); // read+write+delete + template.execute("CREATE TABLE USERS(USERNAME VARCHAR_IGNORECASE(50) NOT NULL PRIMARY KEY,PASSWORD VARCHAR_IGNORECASE(50) NOT NULL,ENABLED BOOLEAN NOT NULL);"); + template.execute("CREATE TABLE AUTHORITIES(USERNAME VARCHAR_IGNORECASE(50) NOT NULL,AUTHORITY VARCHAR_IGNORECASE(50) NOT NULL,CONSTRAINT FK_AUTHORITIES_USERS FOREIGN KEY(USERNAME) REFERENCES USERS(USERNAME));"); + template.execute("CREATE UNIQUE INDEX IX_AUTH_USERNAME ON AUTHORITIES(USERNAME,AUTHORITY);"); /* Passwords encoded using MD5, NOT in Base64 format, with null as salt @@ -133,20 +95,13 @@ public class DataSourcePopulator implements InitializingBean { Encoded password for peter is "opal" (but user is disabled) */ - template.execute( - "INSERT INTO USERS VALUES('marissa','a564de63c2d0da68cf47586ee05984d7',TRUE);"); - template.execute( - "INSERT INTO USERS VALUES('dianne','65d15fe9156f9c4bbffd98085992a44e',TRUE);"); - template.execute( - "INSERT INTO USERS VALUES('scott','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);"); - template.execute( - "INSERT INTO USERS VALUES('peter','22b5c9accc6e1ba628cedc63a72d57f8',FALSE);"); - template.execute( - "INSERT INTO AUTHORITIES VALUES('marissa','ROLE_USER');"); - template.execute( - "INSERT INTO AUTHORITIES VALUES('marissa','ROLE_SUPERVISOR');"); - template.execute( - "INSERT INTO AUTHORITIES VALUES('dianne','ROLE_USER');"); + template.execute("INSERT INTO USERS VALUES('marissa','a564de63c2d0da68cf47586ee05984d7',TRUE);"); + template.execute("INSERT INTO USERS VALUES('dianne','65d15fe9156f9c4bbffd98085992a44e',TRUE);"); + template.execute("INSERT INTO USERS VALUES('scott','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);"); + template.execute("INSERT INTO USERS VALUES('peter','22b5c9accc6e1ba628cedc63a72d57f8',FALSE);"); + template.execute("INSERT INTO AUTHORITIES VALUES('marissa','ROLE_USER');"); + template.execute("INSERT INTO AUTHORITIES VALUES('marissa','ROLE_SUPERVISOR');"); + template.execute("INSERT INTO AUTHORITIES VALUES('dianne','ROLE_USER');"); template.execute("INSERT INTO AUTHORITIES VALUES('scott','ROLE_USER');"); template.execute("INSERT INTO AUTHORITIES VALUES('peter','ROLE_USER');"); } diff --git a/samples/contacts/src/main/java/sample/contact/DeleteController.java b/samples/contacts/src/main/java/sample/contact/DeleteController.java index d6fbbc4673..0bc120eed9 100644 --- a/samples/contacts/src/main/java/sample/contact/DeleteController.java +++ b/samples/contacts/src/main/java/sample/contact/DeleteController.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.web.bind.RequestUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; +import org.springframework.util.Assert; import java.io.IOException; @@ -50,10 +51,7 @@ public class DeleteController implements Controller, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (contactManager == null) { - throw new IllegalArgumentException( - "A ContactManager implementation is required"); - } + Assert.notNull(contactManager, "A ContactManager implementation is required"); } public ModelAndView handleRequest(HttpServletRequest request, diff --git a/samples/contacts/src/main/java/sample/contact/DeletePermissionController.java b/samples/contacts/src/main/java/sample/contact/DeletePermissionController.java index 78b73c8e14..4183f82f3f 100644 --- a/samples/contacts/src/main/java/sample/contact/DeletePermissionController.java +++ b/samples/contacts/src/main/java/sample/contact/DeletePermissionController.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.web.bind.RequestUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; +import org.springframework.util.Assert; import java.io.IOException; @@ -64,15 +65,8 @@ public class DeletePermissionController implements Controller, InitializingBean } public void afterPropertiesSet() throws Exception { - if (contactManager == null) { - throw new IllegalArgumentException( - "A ContactManager implementation is required"); - } - - if (aclManager == null) { - throw new IllegalArgumentException( - "An aclManager implementation is required"); - } + Assert.notNull(contactManager, "A ContactManager implementation is required"); + Assert.notNull(aclManager, "An aclManager implementation is required"); } public ModelAndView handleRequest(HttpServletRequest request, diff --git a/samples/contacts/src/main/java/sample/contact/PublicIndexController.java b/samples/contacts/src/main/java/sample/contact/PublicIndexController.java index 2e51f6e9b4..0325129590 100644 --- a/samples/contacts/src/main/java/sample/contact/PublicIndexController.java +++ b/samples/contacts/src/main/java/sample/contact/PublicIndexController.java @@ -19,6 +19,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; +import org.springframework.util.Assert; import java.io.IOException; @@ -49,10 +50,7 @@ public class PublicIndexController implements Controller, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (contactManager == null) { - throw new IllegalArgumentException( - "A ContactManager implementation is required"); - } + Assert.notNull(contactManager, "A ContactManager implementation is required"); } public ModelAndView handleRequest(HttpServletRequest request, diff --git a/samples/contacts/src/main/java/sample/contact/SecureIndexController.java b/samples/contacts/src/main/java/sample/contact/SecureIndexController.java index 51b5629b50..84c9e45813 100644 --- a/samples/contacts/src/main/java/sample/contact/SecureIndexController.java +++ b/samples/contacts/src/main/java/sample/contact/SecureIndexController.java @@ -19,6 +19,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; +import org.springframework.util.Assert; import java.io.IOException; @@ -53,10 +54,7 @@ public class SecureIndexController implements Controller, InitializingBean { } public void afterPropertiesSet() throws Exception { - if (contactManager == null) { - throw new IllegalArgumentException( - "A ContactManager implementation is required"); - } + Assert.notNull(contactManager, "A ContactManager implementation is required"); } public ModelAndView handleRequest(HttpServletRequest request,