spring-security-tutorial icon indicating copy to clipboard operation
spring-security-tutorial copied to clipboard

Problem with bean creation when I add security config in client yaml

Open milosk015 opened this issue 3 years ago • 6 comments

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloController': Unsatisfied dependency expressed through field 'webClient'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webClient' defined in class path resource

milosk015 avatar Aug 15 '22 21:08 milosk015

I am also facing the same issue.

singhsuryanshu avatar Nov 10 '22 10:11 singhsuryanshu

did you guys figure out the error?? i got the same error too !!

kizogiri avatar May 05 '23 23:05 kizogiri

I also got the same error creating bean Securityfilterchain unsatisfiedDependencyException

lonecodebreaker avatar Aug 27 '23 12:08 lonecodebreaker

spring security version 6 depricated some of the methods, therefor you have to change 'WebSecurityConfig' syntax like this -

@EnableWebSecurity @Configuration public class WebSecurityConfig {

@Bean
public PasswordEncoder passwordEncoder(){
    return new BCryptPasswordEncoder(11);
}

private static final String[] WHIT_LIST_URLS = {
        "/hello",
        "/register",
        "/verifyRegistration*",
        "/resendVerificationToken*",
        "/changePassword*"
};

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    http
            .csrf(csrf->csrf.disable())
            .cors(cors->cors.disable())
            .authorizeHttpRequests((authz)-> authz
            .requestMatchers(WHIT_LIST_URLS).permitAll()
            .anyRequest().authenticated()
    );
    return http.build();
}

}

Rahu09 avatar Jan 29 '24 08:01 Rahu09

        .requestMatchers(WHIT_LIST_URLS).permitAll()

@Rahu09 I got Cannot resolve method 'requestMatchers(String[])' error in WHIT_LIST_URLS

43v3rn88b avatar Mar 30 '24 03:03 43v3rn88b

hey @Rahu09 I think you got that problem due to the naming convention of the String

`

private static final String[] WHITE_LIST_URLS = {
        "/","/login","/hello","/register",
        "/verifyRegistration*","/resendVerifyToken*",
        "/resetPassword*","/savePassword*","/changePassword*",};

@Bean
public PasswordEncoder passwordEncoder(){
    return new BCryptPasswordEncoder(11);
}

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http, HttpSecurity httpSecurity) throws Exception {

    http
            .csrf(AbstractHttpConfigurer::disable)
            .cors(AbstractHttpConfigurer::disable)
            .authorizeHttpRequests((auth)-> auth
                    .requestMatchers(WHITE_LIST_URLS).permitAll()
                    .anyRequest().authenticated()
            );
    return http.build();

}

`

devxadarsh avatar Apr 11 '24 18:04 devxadarsh