鉴于:
上的项目spring。数据库已连接,用户在其中,您可以在http://localhost:8080/users/all.
一个任务:
请求用户时需要登录,但让它进入根目录。
问题:
无法设置免费访问/. 已连接security- 现在所有路径都显示登录表单,我可以在其中使用数据库中的用户数据登录,但没有一种尝试过的方法允许我自由地进入根目录。
问题:
为什么这样一个简单的操作比为其创建数据库和 API 更困难- 我如何为所有请求打开根目录?
目前配置如下所示:
@Configuration
@EnableWebSecurity
class WebSecurityConfiguration : WebSecurityConfigurerAdapter() {
@Autowired
lateinit var dataSource: DataSource
@Autowired
@Bean
fun passwordEncoder() = NoOpPasswordEncoder.getInstance() as NoOpPasswordEncoder
override fun configure(auth: AuthenticationManagerBuilder) {
auth
.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(passwordEncoder())
}
}
我试图为每个人设置路径,例如这样,但似乎我写的所有内容都被忽略了:
override fun configure(http: HttpSecurity) {
http
.csrf().disable()
.anonymous().disable()
.antMatcher("/users/**").authorizeRequests()
//и как только я не пробовал, ничего не меняется
}
我尝试了一个特殊的东西来忽略 - 它也不起作用
override fun configure(webSecurity: WebSecurity) {
webSecurity.ignoring().antMatchers("/")
}
或者
override fun configure(webSecurity: WebSecurity) {
webSecurity.ignoring().antMatchers("/**")
}
UPD_0:
这是一个包含整个项目的存储库:要启动和工作,您需要安装并创建一个名称postgresql为用户名postgres和密码的数据库- 然后在启动时将在数据库中创建一个包含用户的表,并且用户将是在那里添加,您可以在其中使用登录名和密码登录testtestspringbootdbtest@test.rupassword
你有2个问题。
您已将@CompnentScan配置为忽略所有使用 @Configuration注释的类
excludeFilters = [ComponentScan.Filter(type = FilterType.ANNOTATION, value = [Configuration::class])],它应该已被删除。配置Security没有必要的依赖项,有必要添加
compile "org.springframework.boot:spring-boot-starter-security"以及 spring-security 本身的实际配置: