Issue
I am trying to implement spring security into my app based on rel="nofollow noreferrer">this example. However, I am not able to log in, only when I register and it does autologin. When I want to login after logout, example application performs this statements:
Hibernate: select user0_.id as id1_1_, user0_.email as email2_1_,
user0_.password as password3_1_, user0_.username as username4_1_
from user user0_ where user0_.username=?
Hibernate: select roles0_.users_id as users_id1_2_0_,
roles0_.roles_id as roles_id2_2_0_, role1_.id as id1_0_1_,
role1_.name as name2_0_1_
from user_roles roles0_ inner join role role1_ on roles0_.roles_id=role1_.id
where roles0_.users_id=?
On the other hand, my applicaiton performs only this statement:
Hibernate: select user0_.id as id1_1_, user0_.email as email2_1_,
user0_.password as password3_1_, user0_.username as username4_1_
from user user0_ where user0_.username=?
Something is missing there and i cant figure out what.
Solution
Not only do the roles not load, the user is not found. Because UserDetailsServiceImpl.loadUserByUsername
gets an empty username.
In login.html
change:
<input autofocus="true" name="nickname" type="text" placeholder="username"/>
into:
<input autofocus="true" name="username" type="text" placeholder="username"/>
Answered By - Kristof Neirynck
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)