嗯,我目前正在一个springsecurity项目上编程,我想在数据库中注册一个用户。
问题是,如果我访问应该注册的端点,我会被重定向到spring boot的默认登录页,而这不应该发生。
这是我的 SecurityConfiguration.java
```
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder encodePasswd(){
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/").permitAll();
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/**");
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
}
}
我的控制器打电话来了 `UserController.java` 看起来像这样:
@RestController
@RequestMapping("/secure/rest")
public class UserController {
@Autowired
private UserRepository userRepository;
private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
@PostMapping("user/register")
public String addUser(@RequestBody User user){
String passwd = user.getPasswordUser();
String encryptPasswd = passwordEncoder.encode(passwd);
user.setPasswordUser(encryptPasswd);
userRepository.save(user);
return "addedUser";
}
}
1条答案
按热度按时间mv1qrgav1#
试试这个。