加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 在特定方法中禁用spring安全性身份验证

发布时间:2020-12-15 02:07:53 所属栏目:Java 来源:网络整理
导读:我在我的应用程序上使用 spring security 4.在我的应用程序中我有注册页面,我想从检查身份验证中排除此页面. 如何排除特定控制器方法的身份验证? 我的安全配置: http.antMatcher("/test") .httpBasic() .and() .authorizeRequests() .antMatchers("/index.
我在我的应用程序上使用 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.我已经添加/注册到您的spring安全配置

http.antMatcher("/test")
            .httpBasic()
            .and()
            .authorizeRequests()
            .antMatchers("/index.html","/api/user/**","/registration").permitAll().anyRequest()
            .authenticated().and().logout().logoutUrl("/api/logout").and()
            .csrf().csrfTokenRepository(csrfTokenRepository()).and()
            .addFilterAfter(csrfHeaderFilter(),CsrfFilter.class);

更新

请将/ api / user / *更改为/ api / user / **.它应该工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读