如果我正确实施了 OAuth 2.0 授权,我将尝试使用 Postman 测试它。
我正在通过邮递员发送这个期待令牌作为回报
http://localhost:8080/oauth/token/grant_type=password&username=user&password=user
但是我在这部分代码中有错误:
@SpringBootApplication
public class KamehouseApplication {
public static void main(String[] args) {
SpringApplication.run(KamehouseApplication.class, args);
}
@Autowired
public void configure(AuthenticationManagerBuilder auth, UserRepository repo, User user) throws Exception {
if (repo.count() == 0)
user = (new User("user", // username
"user", // password
Arrays.asList(new Role("USER"), new Role("ACTUATOR"))));// roles
repo.save(user);
auth.userDetailsService(s -> new CustomUserDetails(repo.findByUsername(s)));
}
}
红色下划线的部分是
Arrays.asList(new Role("USER"), new Role("ACTUATOR"))));
说
The method asList(T...) in the type Arrays is not applicable for the arguments (Role, Role)
这是我的用户类
@Entity
@Table(name = "user")
public class User {
@Id
@GeneratedValue
public int id;
public String firstname;
public String lastname;
public String username;
public String password;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Role> roles;
public User() {
}
//Getters/Setters
相关分类