我有两个获取网址
- / 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();
谢谢。
答案 0 :(得分:0)
订单很重要:
http ...
.antMatchers(HttpMethod.GET, "/api/appconsole/app/search").authenticated()
.antMatchers(HttpMethod.GET, "/api/appconsole/app/*").permitAll()