Как разрешить один URL-адрес в весенней безопасности

У меня есть два URL-адреса для получения

  1. /api/appconsole/app/{appid}
  2. /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();

Заранее спасибо.

попробуйте добавить antMatchers("/api/appconsole/app/search ").authenticated()

Sudip Bolakhe 19.03.2019 16:43

Какой метод HTTP вы используете для /api/appconsole/app/search? Вы используете OPTION или GET?

dur 20.03.2019 12:17
3
2
121
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Порядок имеет значение:

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

Другие вопросы по теме