From 5b16c42e1558236caeaae6e44b49e9658fb62f29 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Sun, 18 Apr 2004 11:35:24 +0000 Subject: [PATCH] Enhance mock so it is told whether to grant or deny access. --- .../MockAuthenticationManager.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/acegisecurity/MockAuthenticationManager.java b/core/src/test/java/org/acegisecurity/MockAuthenticationManager.java index 33fa59d2ca..d781f55c6a 100644 --- a/core/src/test/java/org/acegisecurity/MockAuthenticationManager.java +++ b/core/src/test/java/org/acegisecurity/MockAuthenticationManager.java @@ -16,16 +16,36 @@ package net.sf.acegisecurity; /** - * Simply accepts as valid whatever is passed to it. + * Simply accepts as valid whatever is passed to it, if + * grantAccess is set to true. * * @author Ben Alex * @version $Id$ */ public class MockAuthenticationManager implements AuthenticationManager { + //~ Instance fields ======================================================== + + private boolean grantAccess = true; + + //~ Constructors =========================================================== + + public MockAuthenticationManager(boolean grantAccess) { + this.grantAccess = grantAccess; + } + + public MockAuthenticationManager() { + super(); + } + //~ Methods ================================================================ public Authentication authenticate(Authentication authentication) throws AuthenticationException { - return authentication; + if (grantAccess) { + return authentication; + } else { + throw new BadCredentialsException( + "MockAuthenticationManager instructed to deny access"); + } } }