gpt4 book ai didi

spring - 如何在 Spring Security 中允许单个 URL

转载 作者:可可西里 更新时间:2023-11-01 16:22:38 26 4
gpt4 key购买 nike

我有两个获取 url

  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();

提前致谢。

最佳答案

订单事项:

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

关于spring - 如何在 Spring Security 中允许单个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55244655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com