2017-01-31 5 views
2

Ich erstelle Rest api und implementiert Spring Security - alles funktioniert gut, aber ich will (für jetzt, wenn ich noch entwickle) für jeden ohne Berechtigung zu können Öffne localhost: 8080/Konsole. Mein Code:H2-Konsole und Spring Security - permitAll() funktioniert nicht

@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(); 
} 

Und was ist wirklich seltsam - localhost: 8080/Register benötigt keine Authentifizierung aber/console kehrt:

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

Wer weiß, wie man es beheben?

Antwort

1

Ich habe eine ähnliche Konfiguration wie folgt. Kannst du das versuchen?

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

Auch dies funktioniert gut, wenn auch keine Notwendigkeit zu verdoppeln .authorazieRequests(). 'http.authorizeRequests(). AntMatchers ("/ register", "/ console/**"). PermitAll();' – doublemc

0

ich mein Problem gelöst durch:

http.headers().frameOptions().disable(); 
Verwandte Themen