我在我的应用上使用spring security 4。在我的应用程序中我有注册页面,我想从检查身份验证中排除此页面。 如何排除特定控制器方法的身份验证?
我的安全配置:
http.antMatcher("/test")
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/index.html", "/login.html", "/", "/scripts/**",
"/bower_components/**", "/styles/**", "/views/**",
"/login", "/api/user/*").permitAll().anyRequest()
.authenticated().and().logout().logoutUrl("/api/logout").and()
.csrf().csrfTokenRepository(csrfTokenRepository()).and()
.addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);
我的控制器方法:
@RequestMapping(method = RequestMethod.POST, value = "/registration")
public ResponseEntity<RestUser> registration(
@RequestBody RestUser restuser, Principal p) throws Exception {
}
答案 0 :(得分:0)
将注册URL添加到配置中的permit all。我已将/registration
添加到您的spring security config
http.antMatcher("/test")
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/index.html", "/login.html", "/", "/scripts/**",
"/bower_components/**", "/styles/**", "/views/**",
"/login", "/api/user/**","/registration").permitAll().anyRequest()
.authenticated().and().logout().logoutUrl("/api/logout").and()
.csrf().csrfTokenRepository(csrfTokenRepository()).and()
.addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);
请将/api/user/*
更改为/api/user/**
。它应该工作。