rajesh
11/20/2020, 6:56 AMnull
in UsernamePasswordAuthenticationToken(userDetails, "", userDetails.authorities)
gives error as authorities can not be null . Any tutorial or help is appreciated.rajesh
11/20/2020, 7:04 AMfun getAuthentication(token: String):Authentication {
val userDetails = myUserDetails.loadUserByUsername(getUsernameFromToken(token))
return UsernamePasswordAuthenticationToken(userDetails, "", userDetails.authorities)
}
jasper
11/20/2020, 9:37 AMalex
11/20/2020, 11:58 AMUsernamePasswordAuthenticationToken
, setAuthenticated(true)
is not called, and so your Authrorizarion
object will return false
for isAuthenticated
.
This will give you 403 exceptions in several places in spring security.
You need to pass at least one authority, you can create a fake one with SimpleGrantedAuthority
.jasper
11/20/2020, 12:06 PMjasper
11/20/2020, 12:06 PMjasper
11/20/2020, 12:07 PMrajesh
11/20/2020, 1:32 PMashmelev
11/20/2020, 1:36 PMROLE_USER
and granted it to everyone. Worked well in my scenariosjasper
11/20/2020, 2:28 PMrajesh
11/20/2020, 3:18 PMashmelev
11/20/2020, 3:24 PMsec_user
, sec_role
and sec_user_role
(this last was a cross-reference table so that User could have many Role). So, yes, sec_role
would have one row in which the authority
field contained ROLE_USER
. We've long since switched to using Keycloak as our OAuth2/OIDC provider so I don't have any source to link you to. That said, what I described above used to be fairly standard SpringSecurity layout for many years, so there would be plenty of doc/examples in Google.rajesh
11/20/2020, 5:37 PM