Commit ca8539f4 authored by Matija Obreza's avatar Matija Obreza

AccountLockoutManager has to use a distributed map

parent 50d6485b
......@@ -16,12 +16,14 @@
package org.genesys2.server.security.lockout;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.User;
......@@ -30,9 +32,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* {#link {@link AccountLockoutManager} keeps track of successive failed login
* attempts and locks the user account if there are more than {
* {@link #lockAfterXFailures} successive failures.
* {#link {@link AccountLockoutManager} keeps track of successive failed login attempts and locks the user account if there are more than { {@link #lockAfterXFailures} successive
* failures.
*
* @author Matija Obreza, matija.obreza@croptrust.org
*
......@@ -41,7 +42,8 @@ import org.springframework.stereotype.Component;
public class AccountLockoutManager {
private final Log _log = LogFactory.getLog(getClass());
private final Map<String, AttemptStatistics> loginAttempts = new HashMap<String, AttemptStatistics>();
@Resource(name = "accountLockoutMap")
private Map<String, AttemptStatistics> loginAttempts;
@Autowired
private UserService userService;
......@@ -49,8 +51,7 @@ public class AccountLockoutManager {
private int lockAfterXFailures = 5;
/**
* Set number of successive failed login attempts that result in account
* lockout
* Set number of successive failed login attempts that result in account lockout
*
* @param lockAfterXFailures
*/
......@@ -100,6 +101,8 @@ public class AccountLockoutManager {
if (stats != null) {
stats.count++;
stats.lastAttempt = new Date();
loginAttempts.put(userName, stats);
_log.info("Updated failed login statistics for username=" + userName + " " + stats);
if (stats.count >= lockAfterXFailures) {
......@@ -144,7 +147,9 @@ public class AccountLockoutManager {
}
}
private class AttemptStatistics {
public static class AttemptStatistics implements Serializable {
private static final long serialVersionUID = -5966606439944355735L;
String uuid;
int count = 0;
Date lastAttempt = new Date();
......
......@@ -18,12 +18,6 @@ package org.genesys2.spring.config;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IExecutorService;
import com.hazelcast.core.IMap;
......@@ -31,6 +25,13 @@ import com.hazelcast.core.IQueue;
import com.hazelcast.spring.cache.HazelcastCacheManager;
import com.hazelcast.web.WebFilter;
import org.genesys2.server.security.lockout.AccountLockoutManager.AttemptStatistics;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@EnableCaching
@Import({ HazelcastConfig.class })
......@@ -74,6 +75,12 @@ public class SpringCacheConfig {
IExecutorService executorService = hazelcast.getExecutorService("hazel-exec");
return executorService;
}
@Bean
public IMap<String, AttemptStatistics> accountLockoutMap(HazelcastInstance hazelcast) {
IMap<String, AttemptStatistics> x = hazelcast.getMap("accountLocks");
return x;
}
@Bean
public WebFilter hazelcastWebFilter() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment