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

java – H2控制台和Spring Security – permitAll()无法正常工作

发布时间:2020-12-15 04:37:25 所属栏目:Java 来源:网络整理
导读:我正在创建rest api并实现 Spring Security – 一切正常但我想(现在,当我还在开发时)能够让任何未经授权的人打开localhost:8080 / console. 我的代码: @Overrideprotected void configure(HttpSecurity http) throws Exception { // allow everyone to reg
我正在创建rest api并实现 Spring Security – 一切正常但我想(现在,当我还在开发时)能够让任何未经授权的人打开localhost:8080 / console.
我的代码:

@Override
protected void configure(HttpSecurity http) throws Exception {
    // allow everyone to register an account; /console is just for testing
    http.authorizeRequests().antMatchers("/register","/console").permitAll();

    http.authorizeRequests().anyRequest().fullyAuthenticated();

    // making H2 console working
    http.headers().frameOptions().disable();

    /*
    https://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html#when-to-use-csrf-protection
    for non-browser APIs there is no need to use csrf protection
    */
    http.csrf().disable();
}

真正奇怪的是 – localhost:8080 / register不需要任何身份验证,但/ console返回:

{
"timestamp": 1485876313847,"status": 403,"error": "Forbidden","message": "Access Denied","path": "/console"
}

任何人都知道如何解决它?

解决方法

我有类似的配置.你能试试吗?

http
    .authorizeRequests()
        .antMatchers("/register").permitAll()
        .and()
    .authorizeRequests()
        .antMatchers("/console/**").permitAll();

(编辑:李大同)

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

    推荐文章
      热点阅读