mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 21:12:18 +00:00
Enhance mock so it is told whether to grant or deny access.
This commit is contained in:
parent
f38ed01b29
commit
5b16c42e15
@ -16,16 +16,36 @@
|
|||||||
package net.sf.acegisecurity;
|
package net.sf.acegisecurity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simply accepts as valid whatever is passed to it.
|
* Simply accepts as valid whatever is passed to it, if
|
||||||
|
* <code>grantAccess</code> is set to <code>true</code>.
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class MockAuthenticationManager implements AuthenticationManager {
|
public class MockAuthenticationManager implements AuthenticationManager {
|
||||||
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
|
private boolean grantAccess = true;
|
||||||
|
|
||||||
|
//~ Constructors ===========================================================
|
||||||
|
|
||||||
|
public MockAuthenticationManager(boolean grantAccess) {
|
||||||
|
this.grantAccess = grantAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MockAuthenticationManager() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public Authentication authenticate(Authentication authentication)
|
public Authentication authenticate(Authentication authentication)
|
||||||
throws AuthenticationException {
|
throws AuthenticationException {
|
||||||
|
if (grantAccess) {
|
||||||
return authentication;
|
return authentication;
|
||||||
|
} else {
|
||||||
|
throw new BadCredentialsException(
|
||||||
|
"MockAuthenticationManager instructed to deny access");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user