我尝试使用BD用户进行身份验证,而不是使用InMemory Auth,因此创建了类用户和角色,并将此代码添加到该类中
@EnableWebSecurity
@Configuration
public class SecurityConfig extends VaadinWebSecurityConfigurerAdapter {
@Autowired
private CustomUserDetails customUserDetails;
@Autowired
CustomAuthenticationProvider customAuthenticationProvider;
@Override
protected void configure(HttpSecurity http) throws Exception {
// Set default security policy that permits Vaadin internal requests and
// denies all other
super.configure(http);
setLoginView(http, LoginView.class, "/logout");
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//auth.inMemoryAuthentication().withUser("user").password("{noop}userpass").roles("USER");
auth.userDetailsService(customUserDetails).passwordEncoder(passwordEncoder());
}
@Bean
public DaoAuthenticationProvider createDaoAuthenticationProvider() {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(customUserDetails);
provider.setPasswordEncoder(passwordEncoder());
return provider;
}
}
但当我尝试验证时,它不接受
1条答案
按热度按时间8yoxcaq71#
有不止一种方法可以做到这一点,但通常大致是这样的。相关的部分,完整的解决方案是太长的SO。不应该有任何Vaadin的具体,但只是遵循Spring文档的问题。
然后根据Spring规范实现
UserDetailsService
。