【问题标题】:How to permit single url in spring security如何在 Spring Security 中允许单个 url
【发布时间】:2019-08-10 04:42:28
【问题描述】:

我有两个获取网址

  1. /api/appconsole/app/{appid}
  2. /api/appconsole/app/search

我想保护第二个 API,但想允许第一个 api。

下面是 websecurityconfig.java 文件。 我应该写什么以便它只允许第一个 api 即 /api/appconsole/app/{appid}

httpSecurity.csrf().disable()

                .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()

                // don't create session
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()

                .authorizeRequests()
                //.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()

                // allow anonymous resource requests
                .antMatchers(
                        HttpMethod.GET,
                        "/",
                        "/file/**/*.*",
                        "/*.html",
                        "/favicon.ico",
                        "/**/*.html",
                        "/**/*.css",
                        "/**/*.js"
                ).permitAll()
                .antMatchers(HttpMethod.GET, "/api/appconsole/app/{appid}").permitAll()
                .antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll()
                .antMatchers("/ws/**").permitAll()
                .antMatchers("/upload").permitAll()
                .antMatchers("/login/**").permitAll()
                .antMatchers("/registration/**").permitAll()
                .antMatchers("/api/orbeon/**").permitAll()
                .anyRequest().authenticated();

提前致谢。

【问题讨论】:

  • 尝试添加antMatchers("/api/appconsole/app/search ").authenticated()
  • /api/appconsole/app/search 使用什么 HTTP 方法?你用OPTION还是GET

标签: spring http spring-security jwt


【解决方案1】:

订单很重要:

http ...
   .antMatchers(HttpMethod.GET, "/api/appconsole/app/search").authenticated()
   .antMatchers(HttpMethod.GET, "/api/appconsole/app/*").permitAll()

【讨论】:

    猜你喜欢
    • 2017-11-06
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 2018-11-20
    • 2021-10-23
    • 2018-01-03
    • 1970-01-01
    • 2022-10-24
    相关资源
    最近更新 更多