【发布时间】:2018-06-04 06:45:39
【问题描述】:
我启用了 Websecurity,但我启用了 anyRequest() 和 permitAll() 方法,但我仍然在邮递员中收到此错误。以下是我在配置中的代码。
@EnableWebSecurity
@Configuration
public class SecurityConfifguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests()
.anyRequest()
.permitAll()
.and().httpBasic().disable();
httpSecurity.csrf().disable();
}
}
以下是控制器代码
@RestController
@RequestMapping("/rest/hello")
public class HelloResource {
@GetMapping
public String hello() {
return "Hello World";
}
}
应用程序类
@ComponentScan
@SpringBootApplication
public class SpringSecurityExampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSecurityExampleApplication.class, args);
}
}
邮递员出错
{
"timestamp": 1513867805556,
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/rest/hello"
}
推荐但需要帮助
httpSecurity
.anonymous() //allow anonymous access
.and()
.authorizeRequests()
.antMatchers("**/rest/**").permitAll();
我希望它返回“Hello World”作为响应。
第二次推荐但没有帮助
httpSecurity
//some configuration
// .and()
.anonymous() //allow anonymous access
.and()
.authorizeRequests()
.antMatchers("/rest/**").permitAll();
【问题讨论】:
标签: java spring spring-boot spring-security