2014-01-16 5 views
6

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

@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 Логин всплывающую панель, когда я попал в домашний адрес. Мне кажется, что приведенная выше конфигурация не вступает в силу, но по умолчанию Конфигурация Spring Security в Spring Boot нет. Если да, то как переопределить значение по умолчанию?

ответ

9

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

security.basic.enabled=false 

и поместить этот файл в SRC/основной/ресурса. Вот и все.

+1

для дальнейшего использования, пожалуйста, отметьте свой ответ как принятый – rodrigorgs

0

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

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



} 
Смежные вопросы