Уважаемые профессионалы Java, я пытаюсь защитить приложение Spring-boot MVC с помощью механизма LDAP, используя инструкции по этой ссылке: http://LDAP%20error
Но я столкнулся со следующей проблемой:
org.springframework.beans.factory.BeanCreationException: ошибка при создании bean-компонента с именем «springSecurityFilterChain», определенным в ресурсе пути к классу [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: создание экземпляра bean-компонента с помощью фабричного метода не удалось; вложенным исключением является org.springframework.beans.BeanInstantiationException: не удалось создать экземпляр [javax.servlet.Filter]: фабричный метод 'springSecurityFilterChain' вызвал исключение; вложенным исключением является java.lang.NoClassDefFoundError: org/springframework/security/ldap/DefaultSpringSecurityContextSource
Я понятия не имею, почему я получаю эту ошибку. Я пытался выполнить поиск по этому форуму, думал, что нашел аналогичную проблему, но безуспешно: http://LDAP%20error
Кто-нибудь может подсказать, что я делаю неправильно? Заранее спасибо.
Вот как выглядит класс WebSecurityConfig:
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
@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();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("uid={0},ou=people")
.groupSearchBase("ou=groups")
.contextSource()
.url("ldap://localhost:8389/dc=springframework,dc=org")
.and()
.passwordCompare()
.passwordEncoder(new LdapShaPasswordEncoder())
.passwordAttribute("userPassword");
}
}
А это класс MvcConfig:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MvcConfig implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
}
Соответствующая часть файла pom.xml:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>ba.epbih.zastoji</groupId>
<artifactId>Zastoji_v1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MyApp</name>
<description>lalala</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>