2015-09-05 6 views
0

Я начал с grails 3 и работал с весной безопасности стартера. Вот мой конфиг безопасности.Как отключить базовый http auth в grails 3.x?

@Configuration 
@EnableWebSecurity 
@EnableWebMvcSecurity 
@EnableGlobalMethodSecurity(jsr250Enabled = true) 
class CustomSecurityConfig extends WebSecurityConfigurerAdapter{ 

    CustomUserDetailsService userDetailsService 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) 
      throws Exception { 
     auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()) 
    } 

    @Bean 
    CustomAuthenticationProvider authenticationProvider() { 
     CustomAuthenticationProvider provider = new CustomAuthenticationProvider(); 
     return provider; 
    } 

    @Override 
    public void configure(WebSecurity web) throws Exception { 
     // This is here to ensure that the static content (JavaScript, CSS, etc) 
     // is accessible from the login page without authentication 

     web.ignoring().antMatchers("/assets/**"); 
     web.ignoring().antMatchers("/views/**"); 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     println "configuring security" 
     http.httpBasic().disable() 
     http.authorizeRequests().expressionHandler() 
     http.formLogin().loginPage("/login").permitAll().and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
       .logoutSuccessUrl("/").deleteCookies("JSESSIONID") 
       .invalidateHttpSession(true); 
     http.authorizeRequests().antMatchers("/").permitAll(); 
     http.csrf().disable(); 

    } 

    @Bean 
    public BCryptPasswordEncoder passwordEncoder() { 
     return new BCryptPasswordEncoder(); 
    } 

} 

Ребята, вы видите ошибки? При такой конфигурации всякий раз, когда я открываю свой корневой URL-адрес, который должен перенаправляться на страницу входа, он продолжает запрашивать всплывающее удостоверение! Любые идеи, как это можно исправить? Приветствия!

ответ

0

Вы должны использовать один из этих аннотаций @EnableWebSecurity, @EnableWebMvcSecurity и @EnableGlobalMethodSecurity.

Тем не менее, важно настроить только AuthenticationManagerBuilder в классе с аннотацией либо @EnableWebSecurity, @EnableGlobalMethodSecurity или @EnableGlobalAuthentication. В противном случае непредсказуемые результаты.

Ссылки:

http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#hello-web-security-java-configuration

+0

Привет, MangEngkus, Спасибо за ваш ответ и предложение. Я реализовал это, я нашел проблему и отправил ответ сейчас. – 89n3ur0n

0

Понял,

Проблема была моя конфигурация безопасности не регистрировал автоматически. Мне пришлось создавать bean-компоненты в ресурсах.groovy и это исправляло.

customSecurityConfig(CustomSecurityConfig) 

Я сделал контекстное сканирование моей конфигурации безопасности и исправил ее. Приветствия!

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