Параметр 0 конструктора требует bean-компонент типа, который не может быть найден - PullRequest
0 голосов
/ 04 июня 2019

Я хочу пройти SSO-аутентификацию CAS, я следовал инструкциям руководства Bealdung (https://www.baeldung.com/spring-security-cas-sso часть 4), но когда я запускаю приложение для весенней загрузки, у меня появляется эта ошибка

Для параметра 0 конструктора в SecurityConfig требуется компонент типа org.springframework.security.cas.authentication.CasAuthenticationProvider ', который не найден.

Действие:

Рассмотримопределение bean-компонента типа 'org.springframework.security.cas.authentication.CasAuthenticationProvider' в вашей конфигурации.

Я видел такую ​​же проблему здесь, но с импортом другой весны, и я пытался добавить @Beanаннотации, но результатов больше нет


@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private AuthenticationProvider authenticationProvider;
    private AuthenticationEntryPoint authenticationEntryPoint;
    private SingleSignOutFilter singleSignOutFilter;
    private LogoutFilter logoutFilter;

    @Autowired
    public SecurityConfig(CasAuthenticationProvider casAuthenticationProvider, AuthenticationEntryPoint eP, LogoutFilter lF, SingleSignOutFilter ssF) {
        this.authenticationProvider = casAuthenticationProvider;
        this.authenticationEntryPoint = eP;

        this.logoutFilter = lF;
        this.singleSignOutFilter = ssF;

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
      http
        .authorizeRequests()
        .regexMatchers("/secured.*", "/login")
        .authenticated()
        .and()
        .authorizeRequests()
        .regexMatchers("/")
        .permitAll()
        .and()
        .httpBasic()
        .authenticationEntryPoint(authenticationEntryPoint);
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.authenticationProvider(authenticationProvider);
    }

    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
      return new ProviderManager(Arrays.asList(authenticationProvider));
    }

    @Bean
    public CasAuthenticationFilter casAuthenticationFilter(ServiceProperties sP) throws Exception {
      CasAuthenticationFilter filter = new CasAuthenticationFilter();
      filter.setServiceProperties(sP);
      filter.setAuthenticationManager(authenticationManager());
      return filter;
    }
}


Предполагается перенаправление на защищенную страницу входа (страницу входа на сервер cas), но теперь я не могу запустить приложение.

Спасибо за вашу помощь

РЕДАКТИРОВАТЬ: мой bean-компонент CasAuthenticationProvider находится в моем классе CasSecuredAppApplication, как сказано в tuto


public class CasSecuredAppApplication {

    @Bean
    public ServiceProperties serviceProperties() {
        ServiceProperties serviceProperties = new ServiceProperties();
        serviceProperties.setService("http://xxx/");
        serviceProperties.setSendRenew(false);
        return serviceProperties;
    }

    @Bean
    @Primary
    public AuthenticationEntryPoint authenticationEntryPoint(
      ServiceProperties sP) {

        CasAuthenticationEntryPoint entryPoint
          = new CasAuthenticationEntryPoint();
        entryPoint.setLoginUrl("https://xxx/cas/login");
        entryPoint.setServiceProperties(sP);
        return entryPoint;
    }

    @Bean
    public TicketValidator ticketValidator() {
        return new Cas30ServiceTicketValidator(
          "https:///cas");
    }

    @Bean
    public CasAuthenticationProvider casAuthenticationProvider() {

        CasAuthenticationProvider provider = new CasAuthenticationProvider();
        provider.setServiceProperties(serviceProperties());
        provider.setTicketValidator(ticketValidator());
        provider.setUserDetailsService(
          s -> new User("casuser", "Mellon", true, true, true, true,
            AuthorityUtils.createAuthorityList("ROLE_ADMIN")));
        provider.setKey("CAS_PROVIDER_LOCALHOST_8080");
        return provider;
    }

}

Его должен найти мой SecurityConfig clзадница нет?

1 Ответ

0 голосов
/ 05 июня 2019

Вы класс CasSecuredAppApplication {не класс конфигурации.

Если это ваш основной класс, добавьте @SpringBootApplication в других случаях @Configuration аннотацию на уровне класса.

...