У меня есть два URL-адреса для получения
- /api/appconsole/app/{appid}
- /api/appconsole/app/search
Я хочу защитить второй API, но хочу разрешить первый API.
ниже приведен файл websecurityconfig.java. Что я должен написать, чтобы он разрешал только 1-й 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 вы используете для /api/appconsole/app/search? Вы используете OPTION или GET?
Порядок имеет значение:
http ...
.antMatchers(HttpMethod.GET, "/api/appconsole/app/search").authenticated()
.antMatchers(HttpMethod.GET, "/api/appconsole/app/*").permitAll()
попробуйте добавить antMatchers("/api/appconsole/app/search ").authenticated()