{
boolean isAuthSuccess = false;
boolean isLockedOut = false;
Date dateNow = new Date();
String ipaddress = ServerSessionUtil.getIP();
IPLockout lockout = ipLockoutDAO.findByIP(ipaddress);
if (!isWhitelistIP(ipaddress))
{
if ((null != lockout) && (null != lockout.getLockoutDate()))
{
isLockedOut = true;
Date endLockout = new Date(lockout.getLockoutDate().getTime() + (lockoutLength * 60000));
if (dateNow.getTime() > endLockout.getTime())
{
isLockedOut = false;
lockout.setLockoutDate(null);
}
}
}
if (!isLockedOut)
{
isAuthSuccess = authenticator.authenticate(username, password);
if (!isWhitelistIP(ipaddress))
{
if (!isAuthSuccess)
{
lockout = (null == lockout) ? new IPLockout(ipaddress, 0) : lockout;
int failCount = lockout.getFailCount() + 1;
if (failCount >= failedLoginThreshold)
{
lockout.setFailCount(0);
lockout.setLockoutDate(dateNow);
LOG.debug("IPLockoutAuthenticator: "+ipaddress+" is locked out");
auditLogger.log(dateNow, username, ipaddress, "lockout", ipaddress, true, "IP blocked");
}
else
{
lockout.setFailCount(failCount);
}
ipLockoutDAO.makePersistent(lockout);
}
else
{
if (null != lockout)
{
lockout.setFailCount(0);
}
}
}
}