From 98422b69a83e2806eb685c89f74ad254bab8588b Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Tue, 9 Dec 2008 14:27:31 +0000 Subject: [PATCH] Java5 updates. --- .../AfterInvocationProviderManager.java | 63 ++++++++----------- .../afterinvocation/ArrayFilterer.java | 6 +- .../afterinvocation/CollectionFilterer.java | 14 ++--- .../security/afterinvocation/Filterer.java | 2 +- 4 files changed, 37 insertions(+), 48 deletions(-) diff --git a/core/src/main/java/org/springframework/security/afterinvocation/AfterInvocationProviderManager.java b/core/src/main/java/org/springframework/security/afterinvocation/AfterInvocationProviderManager.java index 64c2c2c69e..7ad8e5ab7a 100644 --- a/core/src/main/java/org/springframework/security/afterinvocation/AfterInvocationProviderManager.java +++ b/core/src/main/java/org/springframework/security/afterinvocation/AfterInvocationProviderManager.java @@ -15,28 +15,29 @@ package org.springframework.security.afterinvocation; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.InitializingBean; import org.springframework.security.AccessDeniedException; import org.springframework.security.AfterInvocationManager; import org.springframework.security.Authentication; import org.springframework.security.ConfigAttribute; -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; - /** - * Provider-based implementation of {@link AfterInvocationManager}.

Handles configuration of a bean context - * defined list of {@link AfterInvocationProvider}s.

- *

Every AfterInvocationProvider will be polled when the {@link #decide(Authentication, Object, + * Provider-based implementation of {@link AfterInvocationManager}. + *

+ * Handles configuration of a bean context defined list of {@link AfterInvocationProvider}s. + *

+ * Every AfterInvocationProvider will be polled when the {@link #decide(Authentication, Object, * List, Object)} method is called. The Object returned from each provider will be * presented to the successive provider for processing. This means each provider must ensure they return the * Object, even if they are not interested in the "after invocation" decision (perhaps as the secure - * object invocation did not include a configuration attribute a given provider is configured to respond to).

+ * object invocation did not include a configuration attribute a given provider is configured to respond to). * * @author Ben Alex * @version $Id$ @@ -48,7 +49,7 @@ public class AfterInvocationProviderManager implements AfterInvocationManager, I //~ Instance fields ================================================================================================ - private List providers; + private List providers; //~ Methods ======================================================================================================== @@ -56,51 +57,41 @@ public class AfterInvocationProviderManager implements AfterInvocationManager, I checkIfValidList(this.providers); } - private void checkIfValidList(List listToCheck) { + private void checkIfValidList(List listToCheck) { if ((listToCheck == null) || (listToCheck.size() == 0)) { throw new IllegalArgumentException("A list of AfterInvocationProviders is required"); } } public Object decide(Authentication authentication, Object object, List config, - Object returnedObject) throws AccessDeniedException { - Iterator iter = this.providers.iterator(); + Object returnedObject) throws AccessDeniedException { Object result = returnedObject; - while (iter.hasNext()) { - AfterInvocationProvider provider = (AfterInvocationProvider) iter.next(); + for(AfterInvocationProvider provider : providers) { result = provider.decide(authentication, object, config, result); } return result; } - public List getProviders() { + public List getProviders() { return this.providers; } - public void setProviders(List newList) { + public void setProviders(List newList) { checkIfValidList(newList); + providers = new ArrayList(newList.size()); - Iterator iter = newList.iterator(); - - while (iter.hasNext()) { - Object currentObject = iter.next(); - + for(Object currentObject : newList) { Assert.isInstanceOf(AfterInvocationProvider.class, currentObject, "AfterInvocationProvider " + currentObject.getClass().getName() + " must implement AfterInvocationProvider"); + providers.add((AfterInvocationProvider) currentObject); } - - this.providers = newList; } public boolean supports(ConfigAttribute attribute) { - Iterator iter = this.providers.iterator(); - - while (iter.hasNext()) { - AfterInvocationProvider provider = (AfterInvocationProvider) iter.next(); - + for(AfterInvocationProvider provider : providers) { if (logger.isDebugEnabled()) { logger.debug("Evaluating " + attribute + " against " + provider); } @@ -115,7 +106,9 @@ public class AfterInvocationProviderManager implements AfterInvocationManager, I /** * Iterates through all AfterInvocationProviders and ensures each can support the presented - * class.

If one or more providers cannot support the presented class, false is returned.

+ * class. + *

+ * If one or more providers cannot support the presented class, false is returned. * * @param clazz the secure object class being queries * @@ -123,11 +116,7 @@ public class AfterInvocationProviderManager implements AfterInvocationManager, I * every one of its AfterInvocationProviders to support the secure object class */ public boolean supports(Class clazz) { - Iterator iter = this.providers.iterator(); - - while (iter.hasNext()) { - AfterInvocationProvider provider = (AfterInvocationProvider) iter.next(); - + for (AfterInvocationProvider provider : providers) { if (!provider.supports(clazz)) { return false; } diff --git a/core/src/main/java/org/springframework/security/afterinvocation/ArrayFilterer.java b/core/src/main/java/org/springframework/security/afterinvocation/ArrayFilterer.java index 928d53184d..94972141d2 100644 --- a/core/src/main/java/org/springframework/security/afterinvocation/ArrayFilterer.java +++ b/core/src/main/java/org/springframework/security/afterinvocation/ArrayFilterer.java @@ -40,7 +40,7 @@ class ArrayFilterer implements Filterer { //~ Instance fields ================================================================================================ - private Set removeList; + private Set removeList; private Object[] list; //~ Constructors =================================================================================================== @@ -51,7 +51,7 @@ class ArrayFilterer implements Filterer { // Collect the removed objects to a HashSet so that // it is fast to lookup them when a filtered array // is constructed. - removeList = new HashSet(); + removeList = new HashSet(); } //~ Methods ======================================================================================================== @@ -87,7 +87,7 @@ class ArrayFilterer implements Filterer { * * @see org.springframework.security.afterinvocation.Filterer#iterator() */ - public Iterator iterator() { + public Iterator iterator() { return new ArrayIterator(list); } diff --git a/core/src/main/java/org/springframework/security/afterinvocation/CollectionFilterer.java b/core/src/main/java/org/springframework/security/afterinvocation/CollectionFilterer.java index 0254a56270..c689c9d07f 100644 --- a/core/src/main/java/org/springframework/security/afterinvocation/CollectionFilterer.java +++ b/core/src/main/java/org/springframework/security/afterinvocation/CollectionFilterer.java @@ -38,16 +38,16 @@ class CollectionFilterer implements Filterer { //~ Instance fields ================================================================================================ - private Collection collection; + private Collection collection; // collectionIter offers significant performance optimisations (as // per security-developer mailing list conversation 19/5/05) - private Iterator collectionIter; - private Set removeList; + private Iterator collectionIter; + private Set removeList; //~ Constructors =================================================================================================== - CollectionFilterer(Collection collection) { + CollectionFilterer(Collection collection) { this.collection = collection; // We create a Set of objects to be removed from the Collection, @@ -57,7 +57,7 @@ class CollectionFilterer implements Filterer { // to the method may not necessarily be re-constructable (as // the Collection(collection) constructor is not guaranteed and // manually adding may lose sort order or other capabilities) - removeList = new HashSet(); + removeList = new HashSet(); } //~ Methods ======================================================================================================== @@ -68,7 +68,7 @@ class CollectionFilterer implements Filterer { */ public Object getFilteredObject() { // Now the Iterator has ended, remove Objects from Collection - Iterator removeIter = removeList.iterator(); + Iterator removeIter = removeList.iterator(); int originalSize = collection.size(); @@ -88,7 +88,7 @@ class CollectionFilterer implements Filterer { * * @see org.springframework.security.afterinvocation.Filterer#iterator() */ - public Iterator iterator() { + public Iterator iterator() { collectionIter = collection.iterator(); return collectionIter; diff --git a/core/src/main/java/org/springframework/security/afterinvocation/Filterer.java b/core/src/main/java/org/springframework/security/afterinvocation/Filterer.java index 0dcca73695..a36ee3f371 100644 --- a/core/src/main/java/org/springframework/security/afterinvocation/Filterer.java +++ b/core/src/main/java/org/springframework/security/afterinvocation/Filterer.java @@ -40,7 +40,7 @@ interface Filterer { * * @return an Iterator */ - Iterator iterator(); + Iterator iterator(); /** * Removes the the given object from the resulting list.