• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Spring Security - problem with login form

 
Ranch Hand
Posts: 39
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
Ranch Hand
Posts: 39
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
Ranch Hand
Posts: 39
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
Ranch Hand
Posts: 39
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: 2266
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
Ranch Hand
Posts: 39
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: 2266
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: 2266
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic