【发布时间】:2022-04-10 03:37:20
【问题描述】:
我只想用用户名验证用户。为此,我仍在使用UsernamePasswordAuthenticationToken,但也通过了额外的权限。
下面是代码:
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(username,null,authorities)
);
不幸的是,这会引发错误的凭据异常。我在这里错过了什么?
当用正确的用户名密码替换上面的代码时,它可以完美地工作。
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(username,password,authorities)
);
【问题讨论】:
标签: java spring-boot authentication spring-security jwt