I would like to log in knowing only the username
Then you have to dive a bit into spring security. Here is some kotlin example code, maybe it will help you a bit:
@Autowired
private lateinit var userDetailsService: UserDetailsService
...
val loadedUser: UserDetails = userDetailsService.loadUserByUsername(username)
val authentication = UsernamePasswordAuthenticationToken.authenticated(
loadedUser,
null,
loadedUser.authorities
)
SecurityContextHelper.setAuthentication(authentication)
1 Like