Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
45
Issues
45
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
16539858
Commit
16539858
authored
Jun 09, 2016
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AccountLockoutManager has to use a distributed map
parent
dde8f323
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
src/main/java/org/genesys2/server/security/lockout/AccountLockoutManager.java
...nesys2/server/security/lockout/AccountLockoutManager.java
+13
-8
src/main/java/org/genesys2/spring/config/SpringCacheConfig.java
...in/java/org/genesys2/spring/config/SpringCacheConfig.java
+13
-6
No files found.
src/main/java/org/genesys2/server/security/lockout/AccountLockoutManager.java
View file @
16539858
...
...
@@ -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
();
...
...
src/main/java/org/genesys2/spring/config/SpringCacheConfig.java
View file @
16539858
...
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment