Несоответствие типов: несовместимая ссылка для DaoAuthenticationProvider в Spring Security 6JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Несоответствие типов: несовместимая ссылка для DaoAuthenticationProvider в Spring Security 6

Сообщение Anonymous »

Несоответствие типов: несовместимая ссылка для DaoAuthenticationProvider в Spring Security 6 и невозможность использования метода setUserDetailsService() для ссылки на ссылку DaoAuthenticationProvider.
Я столкнулся с ошибкой компиляции в Spring Security 6 при настройке DaoAuthenticationProvider. Несмотря на документацию, предполагающую существование конструктора без аргументов, моя IDE сообщает, что новый DaoAuthenticationProvider() ожидает 1 аргумент. Кроме того, метод setUserDetailsService(UserDetailsService) помечен как неопределенный для типа DaoAuthenticationProvider. Может ли кто-нибудь предоставить анализ первопричин (RCA) и правильные шаги настройки для этой версии?
SecurityConfig.class:
package com.vivek.SpringSecurityDemo.config;

import java.net.Authenticator.RequestorType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsPasswordService;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

import jakarta.security.auth.message.callback.SecretKeyCallback.Request;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Autowired
private UserDetailsService userDetailsService;

@Bean
public SecurityFilterChain sfc(HttpSecurity hp) {
// to disable csrf protection for testing purposes, but in production, you should enable it and handle CSRF tokens properly.
hp.csrf(Customizer -> Customizer.disable());

// Allow all requests with authentication
hp.authorizeHttpRequests(request -> request.anyRequest().authenticated());

// Form login configuration
hp.formLogin(Customizer.withDefaults());

// Http Basic authentication configuration : To make the API accessible via tools like POSTMAN
hp.httpBasic(Customizer.withDefaults());

// To make API stateless, which is common for REST APIs. This means that the server will not maintain any session information about the client.
hp.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

return hp.build();
}

@Bean
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(NoOpPasswordEncoder.getInstance()); // For testing purposes only, use a proper password encoder in production
return authProvider;
}

}



Подробнее здесь: https://stackoverflow.com/questions/798 ... -spring-se
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»