Suman Khanal
Suman Khanal

Reputation: 23

How to resolve DefaultSecurityFilterChain in spring security?

I get this problem thrown which says-the type org.springframework.security.web.DefaultSecurityFilterChain cannot be resolved. It is indirectly referenced from required .class files.


import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.User.UserBuilder;

@Configuration
@EnableWebSecurity
public class DemoSecurityconfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        UserBuilder users=User.withDefaultPasswordEncoder();
        auth.inMemoryAuthentication()
            .withUser(users.username("John").password("john123").roles("EMPLOYEE"))
            .withUser(users.username("Mac").password("mac123").roles("MANAGER"))
            .withUser(users.username("Lily").password("lily123").roles("ACCOUNTANT"));
    }

}```

Upvotes: 0

Views: 10927

Answers (1)

Ken Chan
Ken Chan

Reputation: 90457

DefaultSecurityFilterChain is located in spring-security-web-x.y.z.RELEASE.jar. This error is most probably because this class cannot be found from the class-path.

So go to class path to check if this jar is really included .If not and you are using spring-boot , you can use spring-boot-starter-security starter which will automatically include it.

If you are not using spring-boot, make sure the following dependency is included. For Maven, pom.xml should include

 <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
    </dependency>

And for Gradle , build.gradle should include :

dependencies {
    compile "org.springframework.security:spring-security-web"
}

Upvotes: 3

Related Questions