Ich habe das Gefühl, dass ich mit Springbootsicherheit für immer kämpfen werde. Was ich will (@least) ist recht einfach: ein REST-Dienst mit 3 verschiedenen Sicherheitsstufen:SpringBoot + REST + Sicherheit - entweder alle Zugriffe offen oder alle geschlossen
- A "public" RestService zugänglich von allen
- A "geschützt" RestService für "USER" s
- A „privates“ RestService für „ADMIN“ s
aber entweder ich Zugriff auf alle habe - oder mit der aktuellen Konfiguration bekam ich Zugang zu NONE, denn ohne BasicAuth immer ich
bekam- vollständige Authentifizierung erforderlich, um diese Ressource zuzugreifen
und mit dem "uuu" + "ppp" Ich habe immer
- Bad Credentials
Durch die Art, wie ich mit Federschuh 1.5.3
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@Configuration
@EnableWebSecurity
public class RestSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("aaa").password("ppp").roles("USER", "ADMIN");
auth.inMemoryAuthentication().withUser("uuu").password("ppp").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/public/**").permitAll()
.antMatchers("/protected/**").hasRole("USER")
.antMatchers("/private/**").hasRole("ADMIN")
.and().httpBasic()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); // We don't need sessions to be created.
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**"); /* To allow Pre-flight [OPTIONS] request from browser */
}
}
'auth.inMemoryAuthentication(). WithUser ("aaa"). Passwort (“ ppp "). roles (" USER "," ADMIN ") .und(). mitUser (" uuu "). password (" ppp "). roles (" USER ") – pvpkiran