@Override protectedboolean removeEldestEntry(Map.Entry<String,LockRecord> eldest) { if (size() > cacheSize) { // Check to see if this element has been removed too quickly long timeInCache = (System.currentTimeMillis() - eldest.getValue().getLastFailureTime()) / 1000;
/* *Filtersauthenticatedprincipalstoensurethat<code>null</code>isreturnedforanyuserthatiscurrently *lockedout.
*/ private Principal filterLockedAccounts(String username, Principal authenticatedUser) { // Register all failed authentications if (authenticatedUser == null && isAvailable()) {
registerAuthFailure(username);
}
if (isLocked(username)) { // If the user is currently locked, authentication will always fail
log.warn(sm.getString("lockOutRealm.authLockedUser", username)); returnnull;
}
if (authenticatedUser != null) {
registerAuthSuccess(username);
}
return authenticatedUser;
}
/** *Unlockthespecifiedusername.Thiswillremoveallrecordsofauthenticationfailuresforthisuser. * *@paramusernameTheusertounlock
*/ publicvoid unlock(String username) { // Auth success clears the lock record so...
registerAuthSuccess(username);
}
// No lock record means user can't be locked if (lockRecord == null) { returnfalse;
}
// Check to see if user is locked if (lockRecord.getFailures() >= failureCount &&
(System.currentTimeMillis() - lockRecord.getLastFailureTime()) / 1000 < lockOutTime) { returntrue;
}
// User has not, yet, exceeded lock thresholds returnfalse;
}
/* *Aftersuccessfulauthentication,anyrecordofpreviousauthenticationfailureisremoved.
*/ privatesynchronizedvoid registerAuthSuccess(String username) { // Successful authentication means removal from the list of failed users
failedUsers.remove(username);
}
/* *Afterafailedauthentication,addtherecordofthefailedauthentication.
*/ privatevoid registerAuthFailure(String username) {
LockRecord lockRecord = null; synchronized (this) { if (!failedUsers.containsKey(username)) {
lockRecord = new LockRecord();
failedUsers.put(username, lockRecord);
} else {
lockRecord = failedUsers.get(username); if (lockRecord.getFailures() >= failureCount &&
((System.currentTimeMillis() - lockRecord.getLastFailureTime()) / 1000) > lockOutTime) { // User was previously locked out but lockout has now // expired so reset failure count
lockRecord.setFailures(0);
}
}
}
lockRecord.registerFailure();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.