WebSecurityConfigurerAdapter cannot be resolved to a type
При попытке импорта так же выдает:
The import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter cannot be resolved
Вот файл:
package config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
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.WebSecurityConfiguration;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import service.UserService;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UserService userService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user")
.password("user")
.authorities("ROLE_USER")
.and()
.withUser("admin")
.password("admin")
.authorities("ROLE_ADMIN");
}
@SuppressWarnings("removal")
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.
csrf((csrf) -> csrf.disable())
.authorizeHttpRequests(authz -> authz.anyRequest().permitAll()
//Доступ только для не зарегистрированных пользователей
.requestMatchers("/registration").not().fullyAuthenticated()
//Доступ только для пользователей с ролью Администратор
.requestMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/**").permitAll()
.anyRequest().permitAll())
//Настройка для входа в систему
.formLogin()
.loginPage("/login")
//Перенарпавление на главную страницу после успешного входа
.defaultSuccessUrl("/")
.permitAll()
.and()
.logout()
.permitAll()
.logoutSuccessUrl("/");
}
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService).passwordEncoder(bCryptPasswordEncoder());
}
}
Источник: Stack Overflow на русском