PreAuthorize, die nicht am Controller

Ich versuche zu definieren, die den Zugriff Regeln in der Methode-Niveau, aber es funktioniert nicht, was so überhaupt.

SecurityConfiguration

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().
                withUser("user").password("user").roles("USER").and().
                withUser("admin").password("admin").roles("ADMIN");
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                .antMatchers("/v2/**").authenticated()
                .and()
                .httpBasic()
                .realmName("Secure api")
                .and()
                .csrf()
                .disable();
    }
}

ExampleController

@EnableAutoConfiguration
@RestController
@RequestMapping({"/v2/"})
public class ExampleController {
    @PreAuthorize("hasAuthority('ROLE_ADMIN')")
    @RequestMapping(value = "/home", method = RequestMethod.GET)
    String home() {
        return "Hello World";
    }
}

Immer, wenn ich versuche, auf /v2/home mit user:user es führt nur in Ordnung, sollte es nicht geben mir eine Fehlermeldung "Zugriff Verweigert" aufgrund der 'user' nicht mit ROLE_ADMIN?

Ich bin eigentlich denken der Notwasserung access-Regeln in der Methode-Ebene und bleibe http() ant Regeln, aber ich habe zu wissen, warum es funktioniert nicht für mich.

InformationsquelleAutor der Frage prettyvoid | 2015-09-07

Schreibe einen Kommentar