2017-01-31 2 views
2

Я создаю rest api и реализован Spring Security - все работает нормально, но я хочу (пока, когда я еще разрабатываю), чтобы иметь возможность для любого без разрешения открыть localhost: 8080/console. Мой код:H2 console и Spring Security - allowAll() не работает

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    // allow everyone to register an account; /console is just for testing 
    http.authorizeRequests().antMatchers("/register", "/console").permitAll(); 

    http.authorizeRequests().anyRequest().fullyAuthenticated(); 

    // making H2 console working 
    http.headers().frameOptions().disable(); 

    /* 
    https://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html#when-to-use-csrf-protection 
    for non-browser APIs there is no need to use csrf protection 
    */ 
    http.csrf().disable(); 
} 

И что действительно странно - локальный: 8080/регистр не требует аутентификации, но/консоль возвращается:

{ 
"timestamp": 1485876313847, 
"status": 403, 
"error": "Forbidden", 
"message": "Access Denied", 
"path": "/console" 
} 

Любой знает, как это исправить?

ответ

1

У меня такая же конфигурация. Можете ли вы попробовать это?

http 
    .authorizeRequests() 
     .antMatchers("/register").permitAll() 
     .and() 
    .authorizeRequests() 
     .antMatchers("/console/**").permitAll(); 
+1

Это прекрасно работает тоже, нет необходимости удвоить .authorazieRequests(), хотя. 'http.authorizeRequests(). AntMatchers ("/ register", "/ console/**"). AllowAll();' – doublemc

0

Я решить мою проблему:

http.headers().frameOptions().disable(); 
Смежные вопросы