调用REST API时出现以下错误。
{
"timestamp": "2019-01-19T04:09:54.363+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/createorganization"
}
我是JWT的新手,只是根据教程添加了身份验证和授权代码。我拥有“ / createorganization” REST API,我允许所有这些API-基本上不需要身份验证。但是,尝试达到此错误时,我遇到了以上错误。
这是我的REST API的签名->
@GetMapping(path = "/createorganization")
public @ResponseBody CustomResponse createOrganization(String orgName, String, String email, String password) throws Exception {....
这是带有配置方法->
的WebSecurity类@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter {
private UserDetailsServiceImpl userDetailsService;
private BCryptPasswordEncoder bCryptPasswordEncoder;
public WebSecurity(UserDetailsServiceImpl userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) {
this.userDetailsService = userDetailsService;
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/createorganization").permitAll().anyRequest().authenticated().and()
.addFilter(new JWTAuthenticationFilter(authenticationManager()))
.addFilter(new JWTAuthorizationFilter(authenticationManager()))
// this disables session creation on Spring Security
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
return source;
}
这是我通过Chrome浏览器拨打的电话-
http://localhost:8080/createorganization?orgName=abcd&email=john@gmail.com&password=complex
我希望/ createorganization被调用,因为它是configure()方法中的allowAll()。
非常感谢您的帮助。