Polish Sorting ObjectPostProcessor

* Add Test
* Only sort on adding new entry

Issue gh-3572
This commit is contained in:
Rob Winch
2016-03-08 10:38:59 -06:00
parent a366489c3c
commit 3164bd6f8d
4 changed files with 83 additions and 6 deletions

View File

@@ -15,13 +15,13 @@
*/
package org.springframework.security.config.annotation;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
/**
* A base class for {@link SecurityConfigurer} that allows subclasses to only implement
* the methods they are interested in. It also provides a mechanism for using the
@@ -115,7 +115,6 @@ public abstract class SecurityConfigurerAdapter<O, B extends SecurityBuilder<O>>
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object postProcess(Object object) {
Collections.sort(postProcessors, AnnotationAwareOrderComparator.INSTANCE);
for (ObjectPostProcessor opp : postProcessors) {
Class<?> oppClass = opp.getClass();
Class<?> oppType = GenericTypeResolver.resolveTypeArgument(oppClass,
@@ -134,7 +133,9 @@ public abstract class SecurityConfigurerAdapter<O, B extends SecurityBuilder<O>>
*/
private boolean addObjectPostProcessor(
ObjectPostProcessor<? extends Object> objectPostProcessor) {
return this.postProcessors.add(objectPostProcessor);
boolean result = this.postProcessors.add(objectPostProcessor);
Collections.sort(postProcessors, AnnotationAwareOrderComparator.INSTANCE);
return result;
}
}
}