2014-09-16 2 views
2

Я хочу открыть незащищенную конечную точку в защищенном приложении Springboot. GET-запросы к работе endpoint/api/notify, но запросы POST приводят к 403. Как настроить, чтобы удаленные клиенты могли POST/api/уведомлять оттуда сервер?Выставить незащищенную конечную точку в защищенном от Springboot приложении

Моя расширенная WebSecurityConfigurerAdapter выглядит следующим образом:

protected void configure(HttpSecurity http) throws Exception { 
    http 
     .authorizeRequests() 
     .antMatchers("/").permitAll() 
     .antMatchers("/signup").permitAll() 
     .antMatchers("/reset").permitAll() 
     .antMatchers("/api/notify").permitAll() 
     .anyRequest().authenticated(); 
    http 
     .formLogin() 
      .defaultSuccessUrl("/home") 
     .failureUrl("/login?error") 
     .loginPage("/login") 
     .permitAll() 
     .and() 
     .logout() 
     .permitAll(); 
} 
+0

Может вы показываете нам методы контроллера, которые/api/notify map? – gyoder

+1

Я подозреваю, что защита csfr удерживает вас. При публикации Spring Security проверяет, является ли токен csfr частью формы, он не разрешен. При использовании java-config это активируется по умолчанию с помощью 'http.csfr(). Disable();'. –

ответ

0

Я предлагаю вам попробовать folllowing конфигурацию:

protected void configure(HttpSecurity http) throws Exception { 
    //This reads, invoke this configuration only when 
    //the pattern "/api/notify" is found. 
    //When this configuration is invoked, restrict access, 
    //disable CSRF, and if the path matches "/api/notify" permit all. 
    http.antMatcher("/api/notify") 
     .csrf().disable() 
     .authorizeRequests() 
     .antMatchers("/api/notify") 
     .permitAll(); 

    //Your other configuration... 
    http 
     .authorizeRequests() 
     .antMatchers("/").permitAll() 
     .antMatchers("/signup").permitAll() 
     .antMatchers("/reset").permitAll() 
     .anyRequest().authenticated(); 
    http 
     .formLogin() 
      .defaultSuccessUrl("/home") 
     .failureUrl("/login?error") 
     .loginPage("/login") 
     .permitAll() 
     .and() 
     .logout() 
     .permitAll(); 
} 
+0

GET принимается, POST по-прежнему запрещен, я добавил свой контроллер выше. –

+0

И мой контроллер аннотируется с @RestController –

+0

@darrenrose, я обновил свой ответ. Тем не менее, этот ответ призван дать вам представление о том, как реализовать свое окончательное решение. – Newbie

3

Я думаю, что это то, что вы ищете:

@Configuration 
@EnableWebMvcSecurity 
public class SecurityCtxConfig extends WebSecurityConfigurerAdapter { 
    @Override 
    public void configure(WebSecurity web) throws Exception { 
     web.ignoring() 
       .antMatchers(HttpMethod.POST, 
         "<YOUR URL>"); 
    }