| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.acegisecurity.vote; |
| 17 |
|
|
| 18 |
|
import java.util.Iterator; |
| 19 |
|
import java.util.List; |
| 20 |
|
|
| 21 |
|
import org.acegisecurity.AccessDecisionManager; |
| 22 |
|
import org.acegisecurity.AccessDeniedException; |
| 23 |
|
import org.acegisecurity.AcegiMessageSource; |
| 24 |
|
import org.acegisecurity.ConfigAttribute; |
| 25 |
|
import org.springframework.beans.factory.InitializingBean; |
| 26 |
|
import org.springframework.context.MessageSource; |
| 27 |
|
import org.springframework.context.MessageSourceAware; |
| 28 |
|
import org.springframework.context.support.MessageSourceAccessor; |
| 29 |
|
import org.springframework.util.Assert; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
21 |
public abstract class AbstractAccessDecisionManager implements AccessDecisionManager, InitializingBean, |
| 40 |
|
MessageSourceAware { |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
private List decisionVoters; |
| 45 |
|
|
| 46 |
21 |
protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor(); |
| 47 |
|
|
| 48 |
21 |
private boolean allowIfAllAbstainDecisions = false; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
public void afterPropertiesSet() throws Exception { |
| 54 |
1 |
Assert.notEmpty(this.decisionVoters, "A list of AccessDecisionVoters is required"); |
| 55 |
1 |
Assert.notNull(this.messages, "A message source must be set"); |
| 56 |
1 |
} |
| 57 |
|
|
| 58 |
|
protected final void checkAllowIfAllAbstainDecisions() { |
| 59 |
6 |
if (!this.isAllowIfAllAbstainDecisions()) { |
| 60 |
3 |
throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied", |
| 61 |
|
"Access is denied")); |
| 62 |
|
} |
| 63 |
3 |
} |
| 64 |
|
|
| 65 |
|
public List getDecisionVoters() { |
| 66 |
67 |
return this.decisionVoters; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
public boolean isAllowIfAllAbstainDecisions() { |
| 70 |
12 |
return allowIfAllAbstainDecisions; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
public void setAllowIfAllAbstainDecisions(boolean allowIfAllAbstainDecisions) { |
| 74 |
4 |
this.allowIfAllAbstainDecisions = allowIfAllAbstainDecisions; |
| 75 |
4 |
} |
| 76 |
|
|
| 77 |
|
public void setDecisionVoters(List newList) { |
| 78 |
21 |
Assert.notEmpty(newList); |
| 79 |
|
|
| 80 |
21 |
Iterator iter = newList.iterator(); |
| 81 |
|
|
| 82 |
83 |
while (iter.hasNext()) { |
| 83 |
62 |
Object currentObject = iter.next(); |
| 84 |
63 |
Assert.isInstanceOf(AccessDecisionVoter.class, currentObject, "AccessDecisionVoter " + currentObject.getClass().getName() |
| 85 |
|
+ " must implement AccessDecisionVoter"); |
| 86 |
62 |
} |
| 87 |
|
|
| 88 |
21 |
this.decisionVoters = newList; |
| 89 |
21 |
} |
| 90 |
|
|
| 91 |
|
public void setMessageSource(MessageSource messageSource) { |
| 92 |
1 |
this.messages = new MessageSourceAccessor(messageSource); |
| 93 |
1 |
} |
| 94 |
|
|
| 95 |
|
public boolean supports(ConfigAttribute attribute) { |
| 96 |
0 |
Iterator iter = this.decisionVoters.iterator(); |
| 97 |
|
|
| 98 |
0 |
while (iter.hasNext()) { |
| 99 |
0 |
AccessDecisionVoter voter = (AccessDecisionVoter) iter.next(); |
| 100 |
|
|
| 101 |
0 |
if (voter.supports(attribute)) { |
| 102 |
0 |
return true; |
| 103 |
|
} |
| 104 |
0 |
} |
| 105 |
|
|
| 106 |
0 |
return false; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
public boolean supports(Class clazz) { |
| 121 |
1 |
Iterator iter = this.decisionVoters.iterator(); |
| 122 |
|
|
| 123 |
3 |
while (iter.hasNext()) { |
| 124 |
2 |
AccessDecisionVoter voter = (AccessDecisionVoter) iter.next(); |
| 125 |
|
|
| 126 |
2 |
if (!voter.supports(clazz)) { |
| 127 |
0 |
return false; |
| 128 |
|
} |
| 129 |
2 |
} |
| 130 |
|
|
| 131 |
1 |
return true; |
| 132 |
|
} |
| 133 |
|
} |