• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Spring Security - problem with login form

 
Greenhorn
Posts: 28
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I have got Spring Security issue-its kinda silly but I cannot login to my app on tomcat server using login form provided by spring security.
I added admin account using application.properties



When I provided admin login (admin/admin or even this bcrypted code to the form) app throwing me an error

This is my:
UserDetailsServiceImpl

 
Jan Kaczmarek
Greenhorn
Posts: 28
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SecurityConfiguration
 
Jan Kaczmarek
Greenhorn
Posts: 28
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JWTAuthenticationFilter

 
Jan Kaczmarek
Greenhorn
Posts: 28
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JWTAuthorization

 
Bartender
Posts: 2008
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess your issue comes from the JWTAuthenticationFilter:

Your request.getInputStream() cannot be parsed into JSON format of AppUser.

How about
String username = obtainUsername(request);
String password = obtainPassword(request);

In the request, set the headers of username and password to your username / password.
Pass the username and password to your authenticationManager.authenticate() method.
 
Jan Kaczmarek
Greenhorn
Posts: 28
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
Thank you for your answer. So I tried several approaches with this advice.

Version no.1 (this one looks better)


Version no.2

In browser when I login it redirects me me to the blank page instead of calling login form again-so I think this means that everything is ok with both methods.
When I try to send credentials using postman- app throwing me InternalAuthenticationServiceException in authenticate method (in both versions). And Im not sure right now if it is lack of experience and basic knowledge about postman or still something is wrong with this code.
Thank you for review!
Best regards
 
Himai Minh
Bartender
Posts: 2008
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, in Postman, do you set username and password in the header of the request?
I mean click on the "Headers" and input username as the key , admin as the value. Also input password as the key , BASIC $2a$10$7F7xGm8iuzafFA7RPS8gzeKJm9qNBwtejT4hSuBKXMNlc/4NxOy1G as the value.

Also, do  you specify formLogin().loginPage("/login")  in your security config ?

Reference:
https://www.baeldung.com/spring-security-extra-login-fields
 
Himai Minh
Bartender
Posts: 2008
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more note. I guess you may need to define a bean for PasswordEncoder. Example :
spring boot security example
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic