繁体   English   中英

在特定方法中禁用Spring安全认证

[英]Disable spring security authentication in specific method

我在我的应用程序上使用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 {

}

将注册URL添加到配置中的permit all。 我已经添加/registration到您的spring安全配置

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/** 它应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM