NIHVIVO-2694 Make sure that the BasicAuthenticator and the AuthenticatorStub comply to the contract on throwing LoginNotPermitted exceptions.

This commit is contained in:
j2blake 2012-02-02 16:18:22 +00:00
parent 19f9e10ffb
commit 78c19dde80
3 changed files with 12 additions and 2 deletions

View file

@ -92,6 +92,9 @@ public abstract class Authenticator {
* Behavior when userAccount is null depends on the particular * Behavior when userAccount is null depends on the particular
* Authenticator. An answer of "true" presumably means that the user will be * Authenticator. An answer of "true" presumably means that the user will be
* permitted to login and create an account on the fly. * permitted to login and create an account on the fly.
*
* Note that this method may rely on the HttpServletRequest object that was
* provided to the factory when this instance was created.
*/ */
public abstract boolean isUserPermittedToLogin(UserAccount userAccount); public abstract boolean isUserPermittedToLogin(UserAccount userAccount);

View file

@ -142,7 +142,10 @@ public class BasicAuthenticator extends Authenticator {
@Override @Override
public void recordLoginAgainstUserAccount(UserAccount userAccount, public void recordLoginAgainstUserAccount(UserAccount userAccount,
AuthenticationSource authSource) { AuthenticationSource authSource) throws LoginNotPermitted {
if (!isUserPermittedToLogin(userAccount)) {
throw new LoginNotPermitted();
}
if (userAccount == null) { if (userAccount == null) {
log.error("Trying to record the login of a null user. "); log.error("Trying to record the login of a null user. ");
return; return;

View file

@ -137,7 +137,11 @@ public class AuthenticatorStub extends Authenticator {
@Override @Override
public void recordLoginAgainstUserAccount(UserAccount userAccount, public void recordLoginAgainstUserAccount(UserAccount userAccount,
AuthenticationSource authSource) { AuthenticationSource authSource) throws LoginNotPermitted {
if (!isUserPermittedToLogin(userAccount)) {
throw new LoginNotPermitted();
}
recordedLogins.add(userAccount.getEmailAddress()); recordedLogins.add(userAccount.getEmailAddress());
LoginStatusBean lsb = new LoginStatusBean(userAccount.getUri(), LoginStatusBean lsb = new LoginStatusBean(userAccount.getUri(),