Arjun
Arjun

Reputation: 1262

The type org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter cannot be resolved

I've been trying to learn spring security. The following code is from Spring.io, and i have used the same pom.xml file and spring boot version.

package com.demo.hello;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

    @Bean
    @Override
    public UserDetailsService userDetailsService() {
        UserDetails user =
             User.withDefaultPasswordEncoder()
                .username("user")
                .password("password")
                .roles("USER")
                .build();

        return new InMemoryUserDetailsManager(user);
    }
}

Still Iam getting the following error in the configure method

The type org.springframework.security.web.authentication.UsernamePassw
     ordAuthenticationFilter cannot be resolved. It is indirectly 
     referenced from required .class files


The error is not showing up when i use spring-boot-1.5.14, But its not working with spring-boot-2.0.3 and Spring.io's code uses 2.0.3 version. I'm not able to figure out what's going wrong

Upvotes: 0

Views: 4981

Answers (2)

Aravind Shankar
Aravind Shankar

Reputation: 53

Came Across the same issue. In my case, the issue was due to a mismatch of "spring-boot-starter-security" dependency. added new "spring-boot-starter-security" with compatible version solved this issue

by compatibility, I meant versions of other <groupId>org.springframework.boot</groupId> dependencies.

Hope this may help someone !!

Upvotes: 0

Arjun
Arjun

Reputation: 1262

I solved the issue by deleting following folders from the

maven repository and updated the project

  1. .m2\repository\org\springframework\security\spring-security-config\5.0.6.RELEASE
  2. .m2\repository\org\springframework\security\spring-security-web\5.0.6RELEASE
  3. .m2\repository\org\springframework\security\spring-security-core\5.0.6RELEASE
  4. .m2\repository\org\springframework\boot\spring-boot-starter-security\2.0.3.RELEASE

Upvotes: 1

Related Questions