Spring WebFlux с традиционной веб-безопасностью - PullRequest
0 голосов
/ 19 декабря 2018

Я пытался протестировать Spring WebFlux с традиционной веб-безопасностью (@EnableWebSecurity).Я использовал Tomcat Intead Netty.Я получил следующее сообщение об ошибке.

*************************** Приложение не удалось запустить


Описание:

Компонент 'springSecurityFilterChain', определенный в ресурсе пути к классу [org / springframework / boot / activate / autoconfigure / security / реактивный / ReactiveManagementWebSecurityAutoConfiguration.class], не может быть зарегистрирован.Компонент с таким именем уже определен в ресурсе пути к классу [org / springframework / security / config / annotation / web / configuration / WebSecurityConfiguration.class], и переопределение отключено.

Действие:

Рассмотрите возможность переименования одного из компонентов или включения переопределения, установив spring.main.allow-bean-definition-overriding = true

И я добавлю spring.main.allow-bean-definition-overriding=true в application.properties.Оно работает. Но он генерирует новый пароль .Я уверен, что он не читал мой пользовательский SecurityConfig класс адаптера.

Я хотел бы знать, зачем мне это значение свойства?

А почему не загрузили мой класс адаптера после добавления свойств?

вот мой SecurityConfig класс адаптера.

@Configuration
//@EnableWebFluxSecurity
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
    protected void configure(AuthenticationManagerBuilder auth)
        throws Exception {
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        auth
        .inMemoryAuthentication()
          .withUser("user")
            .password(encoder.encode("user"))
            .authorities("ROLE_USER")
          .and()
          .withUser("woody")
            .password(encoder.encode("bullseye"))
            .authorities("ROLE_ADMIN");
    }

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
          .antMatchers("/hello")
          .authenticated()
          .antMatchers("/**")
          .permitAll()
          .and()
          .httpBasic();
    }

}

pom.xml

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-reactor-netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!--<scope>provided</scope>-->
        </dependency>
...