Конфигурация безопасности Spring в Spring Boot

Я работаю над преобразованием проекта Spring 3 в Spring 4 + Spring Boot. Я пока не знаю, правильно это делать или нет. Я преобразовываю конфигурацию Spring Security XML в конфигурацию на основе Java следующим образом:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/", "/home").permitAll()
            .anyRequest().authenticated();
    http.formLogin()
            .defaultSuccessUrl("/afterLogin")
            .loginPage("/profiles/lognin/form")
            .failureUrl("/accessDenied")
            .and()
            .authorizeRequests()
            .regexMatchers("....")
            .hasRole("ROLE_USER")
            .antMatchers("....")
            .hasRole("ROLE_USER")
            //....
            ;
}

@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder)
        throws Exception {
           authManagerBuilder.authenticationProvider(this.getDaoAuthenticationProvider());
}
   // ....
} 

Я получаю всплывающую панель входа Spring Security по умолчанию, когда нажимаю домашний URL. Мне кажется, что приведенная выше конфигурация не действует, но конфигурация Spring Security по умолчанию в Spring Boot не работает. Если да, то как переопределить значение по умолчанию?


person vic    schedule 16.01.2014    source источник


Ответы (2)


Я нашел ответ. Мне нужно создать файл с именем application.properties со следующей строкой:

security.basic.enabled=false

и поместите этот файл под src/main/resource. Вот и все.

person vic    schedule 17.01.2014

Настройте свою пружину так.

protected void configure(HttpSecurity http) throws Exception {

    http
                .csrf()
            .and()
                .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
                .exceptionHandling()
            .and()
                .rememberMe()
            .and()
                .formLogin()
                .loginProcessingUrl("/user")   // rest apiyi yaz.
                //.usernameParameter("username")
                //.passwordParameter("password")
                .permitAll()
            .and()
                .logout()
                //.logoutUrl("/api/logout")
                //.deleteCookies("JSESSIONID", "CSRF-TOKEN")
                .permitAll()
            .and()
                .headers()
                .frameOptions()
                .disable()
                .authorizeRequests()
                .antMatchers("/login").permitAll()
                .antMatchers("/#/dashboard/home").permitAll()
            ;



}
person Gökhan Ayhan    schedule 28.12.2015