Java 拒绝从spring security访问html资源
我正在尝试使用SpringBoot和SpringSecurity创建一个简单的登录,我不明白为什么它不起作用。 基本上,我有两个视图,分别位于resources/login/login.html和resources/login/registerUser.html中 无论何时我尝试登录或注册,它都会拒绝我的访问: 我猜它无法访问这两种资源,但我不明白出了什么问题: 控制器:Java 拒绝从spring security访问html资源,java,spring,security,Java,Spring,Security,我正在尝试使用SpringBoot和SpringSecurity创建一个简单的登录,我不明白为什么它不起作用。 基本上,我有两个视图,分别位于resources/login/login.html和resources/login/registerUser.html中 无论何时我尝试登录或注册,它都会拒绝我的访问: 我猜它无法访问这两种资源,但我不明白出了什么问题: 控制器: @RequestMapping("/showReg") public String showRegistration
@RequestMapping("/showReg")
public String showRegistrationPage() {
return "login/registerUser";
}
@RequestMapping(value = "/registerUser", method = RequestMethod.POST)
public String register(@ModelAttribute("user") User user) {
user.setPassword(encoder.encode(user.getPassword()));
userRepository.save(user);
return "login/login";
}
@RequestMapping(value = "/loginForm", method = RequestMethod.POST)
public String login(@RequestParam("email") String email, @RequestParam("password") String password, Model model) {
boolean loginResponse = securityService.login(email, password);
System.out.println(loginResponse);
if (loginResponse) {
return "findFlights";
} else {
model.addAttribute("msg", "Invalid username or password.Please try again!");
}
return "login/login";
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String getLogin() {
return "login/login";
}
WebSecurity配置类
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/assets/**" ,"/showReg", "/", "/index.html", "/registerUser", "/login", "/showLogin",
"/login/*", "/reservations/*")
.permitAll().antMatchers("/admin/showFlight").hasAnyAuthority("ADMIN").anyRequest().authenticated()
.and().csrf().disable();
}
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
使用重载方法
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/assets/**" ,"/showReg", "/", "/index.html", "/registerUser", "/login", "/showLogin", "/login/*", "/reservations/*");
}