27 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
renekton
9 years ago

Could you write this guide using AuthenticationFailureHandler?

saket tiwari
3 years ago

how to download src code becas this link is not working
spring-security-limit-login-annotation.zip

Ellis
5 years ago

wouldn’t this allow a denial of service attack by locking all the accounts?

yuni
6 years ago

why any incorrect username or password cannot insert into the user_attempts table? Please help me

Bossini
7 years ago

Excellent tutorial, but i’m having some issue with password encoder (using BCrypt), i map my WebSecurityConfigurerAdapter implementor using:
auth.userDetailsService(customUserDetailsService).passwordEncoder(new BCryptPasswordEncoder());
but when i use:
@Autowired
public void configureGlobal
the spring send me null pointer because don’t find a valid encript id.
=/

Sean K
8 years ago

This fails to build.

[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 5.988 s
[INFO] Finished at: 2017-11-26T23:45:57-08:00
[INFO] Final Memory: 21M/69M
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring-security-limit-login-annotation: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

mohammad iliyas
9 years ago

how to encrypt username and save to database and decrypt when login is performed using rsa.

mohammad iliyas
9 years ago

I have successfully run your project using oracle db.In addition to this ,I want to fetch roles from db dynamically without hardcode using intercept-url in security.xml.How i can achieve this.

Pradeep Gowda
10 years ago

can you do this in struts2

Pradeep Gowda
10 years ago

every works fine mk can you expalin me how this project flow…. or anyone

Farooq Kassam
10 years ago

Thank you so much dude! You are the best

OG
10 years ago

I’m using hibernate and there seems to be a problem with my transaction management because the update for the field accountNonLocked is not updated. I checked the sql query on the console and it is executed. What could be the problem

Pradeep Gowda
10 years ago
Reply to  OG

yes you are right in my case the same program i download and run firstly but first time i have not changed database password then i changed even though user_attempts tables not update do you know the reason

DEADForMojo666 (NOT AUTOLIKE)
10 years ago

correct column of the table field lastModified
————————————————————————

CREATE TABLE user_attempts (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(45) NOT NULL,
attempts varchar(45) NOT NULL,
lastModified datetime,
PRIMARY KEY (id)
);

Naresh
10 years ago

Thanks for mkyong… above program running. thanks a lot..

hemant saini
10 years ago

Why there isn’t any kind of relationship n users and user_attempts table?

S.Jose
11 years ago

Is it more easier if we user
AuthenticationFailureHandler?

Sudheer Tupilli
11 years ago

Can we unlock the user through code or by firing the query on database by changing ‘accountNonLocked’ to 1 ?

Jagadeesh
11 years ago

Hi Mkyong, Awesome Tutorial!! I am trying to add “Password Hashing functionality” in this code by using BCryptPasswordEncoder .. Where do we actually add “encoder” reference? Could you please help in this.. I was following your password hashing tutorial. But unable to integrate here. “Please help me, what are the steps i have to take, to integrate password hashing mechanism”.

Hiten
11 years ago

Thanks for sharing simplest yet effective examples.
Little correction on the above program. It gives sql exception when setting ‘lastmodifieddate = null’ in UserDetailsDaoImpl.java.
I had to change 2 lines of code there in the class (same db – mysql) ie.
private static final String SQL_USER_ATTEMPTS_UPDATE_ATTEMPTS = “UPDATE USER_ATTEMPTS SET attempts = attempts + 1, lastmodified = now() WHERE username = ?”;
private static final String SQL_USER_ATTEMPTS_RESET_ATTEMPTS = “UPDATE USER_ATTEMPTS SET attempts = 0, lastmodified = now() WHERE username = ?”;

Pradip Saha
12 years ago

really useful

Mahendra H. Bagul
12 years ago

getting this “Invalid username and password!” even if provide correct username and password.

In catalina.out, following is being printed.

Populated SecurityContextHolder with anonymous token: ‘org.springframework.security.authentication.AnonymousAuthenticationToken@6fabe8e0: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffe9938: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: F7A5817B451666073B753408F6713FBA; Granted Authorities: ROLE_ANONYMOUS’

Please help to solve this issue. Any help will be appreciated. Thanks in advance.

Cristi
11 years ago

I get the same error. Please help.

mkyong
12 years ago

Try run in debug mode (via log setting), observe on the sql output, also, make sure the database connection is correct and established.

suresh
9 years ago
Reply to  mkyong

can you please share how to unlock the account after some time

Guest
12 years ago

Try run in debug mode (via log setting), observe on the sql output, also, make sure the database connection is correct and established.