From 07e805e3421a14ac1b2414cb6406577896cffc06 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Tue, 23 May 2006 11:03:30 +0000 Subject: [PATCH] SEC-262: Refactor common method into superclass. --- .../vote/AbstractAccessDecisionManager.java | 9 +++++++++ .../java/org/acegisecurity/vote/AffirmativeBased.java | 8 +------- .../main/java/org/acegisecurity/vote/ConsensusBased.java | 8 +------- .../main/java/org/acegisecurity/vote/UnanimousBased.java | 8 +------- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/vote/AbstractAccessDecisionManager.java b/core/src/main/java/org/acegisecurity/vote/AbstractAccessDecisionManager.java index 1f2e1e52d1..16bd3147f6 100644 --- a/core/src/main/java/org/acegisecurity/vote/AbstractAccessDecisionManager.java +++ b/core/src/main/java/org/acegisecurity/vote/AbstractAccessDecisionManager.java @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.List; import org.acegisecurity.AccessDecisionManager; +import org.acegisecurity.AccessDeniedException; import org.acegisecurity.AcegiMessageSource; import org.acegisecurity.ConfigAttribute; import org.springframework.beans.factory.InitializingBean; @@ -138,4 +139,12 @@ public abstract class AbstractAccessDecisionManager return true; } + + protected final void checkAllowIfAllAbstainDecisions() { + if (!this.isAllowIfAllAbstainDecisions()) { + throw new AccessDeniedException(messages.getMessage( + "AbstractAccessDecisionManager.accessDenied", + "Access is denied")); + } + } } diff --git a/core/src/main/java/org/acegisecurity/vote/AffirmativeBased.java b/core/src/main/java/org/acegisecurity/vote/AffirmativeBased.java index 93ce2d4942..c113632f7c 100644 --- a/core/src/main/java/org/acegisecurity/vote/AffirmativeBased.java +++ b/core/src/main/java/org/acegisecurity/vote/AffirmativeBased.java @@ -79,12 +79,6 @@ public class AffirmativeBased extends AbstractAccessDecisionManager { } // To get this far, every AccessDecisionVoter abstained - if (this.isAllowIfAllAbstainDecisions()) { - return; - } else { - throw new AccessDeniedException(messages.getMessage( - "AbstractAccessDecisionManager.accessDenied", - "Access is denied")); - } + checkAllowIfAllAbstainDecisions(); } } diff --git a/core/src/main/java/org/acegisecurity/vote/ConsensusBased.java b/core/src/main/java/org/acegisecurity/vote/ConsensusBased.java index 38f899bd4d..333101919b 100644 --- a/core/src/main/java/org/acegisecurity/vote/ConsensusBased.java +++ b/core/src/main/java/org/acegisecurity/vote/ConsensusBased.java @@ -108,13 +108,7 @@ public class ConsensusBased extends AbstractAccessDecisionManager { } // To get this far, every AccessDecisionVoter abstained - if (this.isAllowIfAllAbstainDecisions()) { - return; - } else { - throw new AccessDeniedException(messages.getMessage( - "AbstractAccessDecisionManager.accessDenied", - "Access is denied")); - } + checkAllowIfAllAbstainDecisions(); } public boolean isAllowIfEqualGrantedDeniedDecisions() { diff --git a/core/src/main/java/org/acegisecurity/vote/UnanimousBased.java b/core/src/main/java/org/acegisecurity/vote/UnanimousBased.java index a2b57645be..92530f117a 100644 --- a/core/src/main/java/org/acegisecurity/vote/UnanimousBased.java +++ b/core/src/main/java/org/acegisecurity/vote/UnanimousBased.java @@ -106,12 +106,6 @@ public class UnanimousBased extends AbstractAccessDecisionManager { } // To get this far, every AccessDecisionVoter abstained - if (this.isAllowIfAllAbstainDecisions()) { - return; - } else { - throw new AccessDeniedException(messages.getMessage( - "AbstractAccessDecisionManager.accessDenied", - "Access is denied")); - } + checkAllowIfAllAbstainDecisions(); } }