【发布时间】:2019-08-10 04:42:28
【问题描述】:
我有两个获取网址
- /api/appconsole/app/{appid}
- /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