* @throws AuthenticationException
*/
private boolean isLocked(String login, int attempts, int timeout) throws AuthenticationException
{
String sql;
DataAgent conn = null;
try
{
// Obtiene y abre la conexi�n a BBDD
conn = DataFactory.getInstance(workspace);
// Limpia bloqueos caducados (de m�s de [timeout] minutos)
sql = "DELETE FROM " + TABLE_LOCKS + " " +
"WHERE ((DATE_PART('day', CURRENT_TIMESTAMP - lastattempt) * 24 + " +
" DATE_PART('hour', CURRENT_TIMESTAMP - lastattempt)) * 60 + " +
" DATE_PART('minute', CURRENT_TIMESTAMP - lastattempt) >= " + timeout + ")";
conn.execute(sql);
// Consulta si el usuario dispone de un registro bloqueado:
// Dispone de N intentos (o m�s) y el �ltimo intento hace menos de M minutos que se produjo
sql = "SELECT Count(*) " +
"FROM " + TABLE_LOCKS + " " +
"WHERE ((DATE_PART('day', CURRENT_TIMESTAMP - lastattempt) * 24 + " +
" DATE_PART('hour', CURRENT_TIMESTAMP - lastattempt)) * 60 + " +
" DATE_PART('minute', CURRENT_TIMESTAMP - lastattempt) < " + timeout + ") And " +
" lower(login) = '" + DataAgent.sqlFormatTextValue(login) + "' And " +
" fails >= " + attempts;
int nregs = conn.executeScalar(sql);
return (nregs > 0);
}
catch (DataException ex)
{
throw new AuthenticationException(ex.getMessage(), ex);
}
catch (Exception ex)
{
throw new AuthenticationException(ex.getMessage(), ex);
}
finally
{
if (conn != null)
{
conn.disconnect();
}
}
}