Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Can not understand why I can't login?

 
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried the password and users but cannot login


//HelloController




Ska-rmavbild-2020-07-23-kl.-01.05.19.png
[Thumbnail for Ska-rmavbild-2020-07-23-kl.-01.05.19.png]
 
Saloon Keeper
Posts: 12251
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What URL are you browsing to. What happens when you do that? What were you expecting to happen?
 
martin codey
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I go from http://localhost:8080/login to http://localhost:8080/login?error when I type in the user name emma and password emma.
I want to go to http://localhost:8080/index
 
Stephan van Hulst
Saloon Keeper
Posts: 12251
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The password() method should take an encoded password, not a plain password.
 
martin codey
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When adding encryption:


Multiple markers at this line
- Syntax error on token ".", delete this token
- Syntax error, insert ")" to complete Expression
- The method passwordEncoder(BCryptPasswordEncoder) is undefined for the type
WebConfigur


Uploaded my code to github  if it makes it easier to see the problem.

github
 
Master Rancher
Posts: 4663
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the end of line 10.
 
Stephan van Hulst
Saloon Keeper
Posts: 12251
259
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, your latest problem is caused by the fact that you didn't write valid Java code: You didn't using a closing parenthesis for the passwordEncoder() method.

However, calling passwordEncoder() won't fix your original problem.

This issue is caused by Spring 5 using a default password encoder, whereas Spring 4 just stored passwords as plaintext by default. The password() method expects you to pass it a password in encoded form, not in plaintext form. So what you need to do is get the encoder that Spring is already using, and use it to encode the password that you pass to the password() method.

Try this:
 
martin codey
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the explanation and  I made the change you told me to and did not get any visible error but when I started the project I got this error trace:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project webapp: Compilation failure
[ERROR] /Users//Downloads/webapp/src/main/java/config/WebConfigur.java:[24,9] cannot find symbol
[ERROR]   symbol:   class var
[ERROR]   location: class config.WebConfigur
[ERROR] -> [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/MojoFailureException
 
Stephan van Hulst
Saloon Keeper
Posts: 12251
259
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
var is a special identifier that was added in Java 10. If your compiler reports that it can't find the symbol var, it means that you're on an older Java version. The solution is to use the formal type name instead of the identifier var.

Replace var with PasswordEncoder.
 
martin codey
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright I understand and It is fixed. This is the code:



Shouldn't I be authorized to login when typing emma for password and user? It does not work
 
Bartender
Posts: 1944
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martin,
So, when you log on as emma , you got a 403 Forbidden error?
Is your method or class annotated with either @Secured(ROLE_BOSS) or @Secured (ROLE_DEV) ?
But putting this annotation, it means the class or method can only permit BOSS or DEV to access.
 
Stephan van Hulst
Saloon Keeper
Posts: 12251
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What URL are you browsing to. What happens when you do that? What were you expecting to happen?

 
martin codey
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get to the spring default login form and i can only login with the generated password. Do I have to create a login html file too or can the default password be replaced without creating a login form.

I go from http://localhost:8080/login to http://localhost:8080/login?error when I type in the user name emma and password emma.
I want to go to http://localhost:8080/index

 
Himai Minh
Bartender
Posts: 1944
13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martin,
You may want to have a controller like this:

 
martin codey
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Himai. It is changed.
 
Stephan van Hulst
Saloon Keeper
Posts: 12251
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

martin codey wrote:I get to the spring default login form and i can only login with the generated password.


What generated password are you referring to? Why is that a problem? What do you want instead?
 
    Bookmark Topic Watch Topic
  • New Topic