【发布时间】:2017-05-10 09:47:31
【问题描述】:
我一直在努力解决如何让 Spring Security 工作并允许所有来源进入我的 REST-full 应用程序。我已经查找了问题并尝试了大多数建议,但似乎没有任何东西可以独立工作,它们可以正常工作,但不能一起工作。
我的控制器非常简单,因为我只是在做一些测试
@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 + "!";
}
}
我的安全配置如下所示:
@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 服务?
【问题讨论】:
标签: javascript java spring-boot spring-security