mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-29 15:22:15 +00:00
Fix broken test caused by null application context in AbtractAccessDecisionManager when auto-detection of voters is called.
This commit is contained in:
parent
c5cc42e16c
commit
aea1148ffb
@ -38,7 +38,7 @@ import org.springframework.util.Assert;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract implementation of {@link AccessDecisionManager}.
|
* Abstract implementation of {@link AccessDecisionManager}.
|
||||||
* <p>
|
* <p/>
|
||||||
* Handles configuration of a bean context defined list of
|
* Handles configuration of a bean context defined list of
|
||||||
* {@link AccessDecisionVoter}s and the access control behaviour if all voters
|
* {@link AccessDecisionVoter}s and the access control behaviour if all voters
|
||||||
* abstain from voting (defaults to deny access).
|
* abstain from voting (defaults to deny access).
|
||||||
@ -55,15 +55,13 @@ public abstract class AbstractAccessDecisionManager implements AccessDecisionMan
|
|||||||
|
|
||||||
private boolean allowIfAllAbstainDecisions = false;
|
private boolean allowIfAllAbstainDecisions = false;
|
||||||
|
|
||||||
private boolean isSetDecisionVotersInvoked = false;
|
|
||||||
|
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
// ~ Methods
|
// ~ Methods
|
||||||
// ========================================================================================================
|
// ========================================================================================================
|
||||||
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
if (!isSetDecisionVotersInvoked) {
|
if (decisionVoters == null || decisionVoters.isEmpty()) {
|
||||||
autoDetectVoters();
|
autoDetectVoters();
|
||||||
}
|
}
|
||||||
Assert.notEmpty(this.decisionVoters, "A list of AccessDecisionVoters is required");
|
Assert.notEmpty(this.decisionVoters, "A list of AccessDecisionVoters is required");
|
||||||
@ -71,8 +69,10 @@ public abstract class AbstractAccessDecisionManager implements AccessDecisionMan
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void autoDetectVoters() {
|
private void autoDetectVoters() {
|
||||||
|
Assert.notNull(applicationContext, "Auto-detection of voters requires an application context");
|
||||||
Map map = this.applicationContext.getBeansOfType(AccessDecisionVoter.class);
|
Map map = this.applicationContext.getBeansOfType(AccessDecisionVoter.class);
|
||||||
List list = new ArrayList();
|
List list = new ArrayList();
|
||||||
|
|
||||||
for (Iterator it = map.values().iterator(); it.hasNext();) {
|
for (Iterator it = map.values().iterator(); it.hasNext();) {
|
||||||
list.add((it.next()));
|
list.add((it.next()));
|
||||||
}
|
}
|
||||||
@ -100,24 +100,15 @@ public abstract class AbstractAccessDecisionManager implements AccessDecisionMan
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDecisionVoters(List newList) {
|
public void setDecisionVoters(List newList) {
|
||||||
isSetDecisionVotersInvoked = true;
|
|
||||||
Assert.notEmpty(newList);
|
Assert.notEmpty(newList);
|
||||||
|
|
||||||
Iterator iter = newList.iterator();
|
Iterator iter = newList.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Object currentObject = null;
|
Object currentObject = iter.next();
|
||||||
|
Assert.isInstanceOf(AccessDecisionVoter.class, currentObject, "AccessDecisionVoter " + currentObject.getClass().getName()
|
||||||
try {
|
|
||||||
currentObject = iter.next();
|
|
||||||
|
|
||||||
AccessDecisionVoter attemptToCast = (AccessDecisionVoter) currentObject;
|
|
||||||
}
|
|
||||||
catch (ClassCastException cce) {
|
|
||||||
throw new IllegalArgumentException("AccessDecisionVoter " + currentObject.getClass().getName()
|
|
||||||
+ " must implement AccessDecisionVoter");
|
+ " must implement AccessDecisionVoter");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.decisionVoters = newList;
|
this.decisionVoters = newList;
|
||||||
}
|
}
|
||||||
@ -143,13 +134,12 @@ public abstract class AbstractAccessDecisionManager implements AccessDecisionMan
|
|||||||
/**
|
/**
|
||||||
* Iterates through all <code>AccessDecisionVoter</code>s and ensures
|
* Iterates through all <code>AccessDecisionVoter</code>s and ensures
|
||||||
* each can support the presented class.
|
* each can support the presented class.
|
||||||
* <p>
|
* <p/>
|
||||||
* If one or more voters cannot support the presented class,
|
* If one or more voters cannot support the presented class,
|
||||||
* <code>false</code> is returned.
|
* <code>false</code> is returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param clazz DOCUMENT ME!
|
* @param clazz DOCUMENT ME!
|
||||||
*
|
|
||||||
* @return DOCUMENT ME!
|
* @return DOCUMENT ME!
|
||||||
*/
|
*/
|
||||||
public boolean supports(Class clazz) {
|
public boolean supports(Class clazz) {
|
||||||
@ -169,5 +159,4 @@ public abstract class AbstractAccessDecisionManager implements AccessDecisionMan
|
|||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user