Javascript 使用@CrossOrigin时,Spring引导安全性未进行身份验证
我一直在绞尽脑汁研究如何让SpringSecurity正常工作,以及如何让所有的源代码都支持我的REST完整应用程序。我查过这个问题,并尝试了大多数建议,但似乎没有什么独立的工作,他们工作得很好,但不能在一起 我的控制器非常简单,因为我只是在做一些测试Javascript 使用@CrossOrigin时,Spring引导安全性未进行身份验证,javascript,java,spring-boot,spring-security,Javascript,Java,Spring Boot,Spring Security,我一直在绞尽脑汁研究如何让SpringSecurity正常工作,以及如何让所有的源代码都支持我的REST完整应用程序。我查过这个问题,并尝试了大多数建议,但似乎没有什么独立的工作,他们工作得很好,但不能在一起 我的控制器非常简单,因为我只是在做一些测试 @RestController @CrossOrigin public class TestController { @RequestMapping(path="/test/{name}", method= RequestMethod.
@RestController
@CrossOrigin
public class TestController
{
@RequestMapping(path="/test/{name}", method= RequestMethod.GET)
public String test(@PathVariable final String name)
{
return "Welcome " + name + "!";
}
@RequestMapping(path="/private/{name}", method= RequestMethod.GET)
public String privateTest(@PathVariable final String name)
{
return "Welcome private " + name + "!";
}
}
我的securityconfig如下所示:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
public void configure(HttpSecurity httpSecurity) throws Exception
{
httpSecurity.cors().and().authorizeRequests()
.antMatchers("/*").hasRole("USER")
.and()
.formLogin();
}
}
有人有什么建议吗?另外,在默认情况下不允许javascript执行REST full http请求时,通常如何创建安全的restfull服务
.antMatchers("/**").hasRole("USER")
// or anyRequest().hasRole("USER")
有关蚂蚁匹配的更多信息,请参见