Несоответствие типов: несовместимая ссылка для 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
Несоответствие типов: несовместимая ссылка для DaoAuthenticationProvider в Spring Security 6 ⇐ JAVA
Программисты JAVA общаются здесь
1771235822
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;
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79889845/type-mismatch-incompatible-reference-for-daoauthenticationprovider-in-spring-se[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия