Как отключить базовую HTTP-аутентификацию в Grails 3.x?

Я начал с Grails 3 и работаю с системой безопасности Spring Boot Starter. Вот мой конфиг безопасности.

@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-адрес, который должен перенаправлять на страницу входа, продолжает запрашивать аутентификацию всплывающего окна! Любые идеи, как это можно исправить? Ваше здоровье!


person 89n3ur0n    schedule 05.09.2015    source источник


Ответы (2)


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

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

Использованная литература:

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

person KSTN    schedule 05.09.2015
comment
Привет, MangEngkus, спасибо за ваш ответ и предложение. Я реализовал это, я нашел проблему и отправил ответ сейчас. - person 89n3ur0n; 05.09.2015

Понятно,

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

customSecurityConfig(CustomSecurityConfig)

Я сделал контекстное сканирование моей конфигурации безопасности, и это исправило ее. Ваше здоровье!

person 89n3ur0n    schedule 05.09.2015