[英]how to configure spring-boot-starter-security
how I can configure spring-boot-starter-security, to my own needs?我如何根据自己的需要配置 spring-boot-starter-security?
(I'm using spring with kotlin) (我将 spring 与 kotlin 一起使用)
I mean, I have this configuration file, but it seems that spring container just ignore.我的意思是,我有这个配置文件,但似乎 spring 容器只是忽略了。
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.crypto.bcrypt.BCryptPasswordEncoder
import java.lang.Exception
@Configuration
@EnableWebSecurity
class WebSecurity : WebSecurityConfigurerAdapter() {
@Bean
public fun encriptator () : BCryptPasswordEncoder{
return BCryptPasswordEncoder();
}
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http .authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
is always redirect me to /login.总是将我重定向到 /login。
And the file location is at the same level of the app.kt并且文件位置与app.kt处于同一级别
I got the solution, my problem was the package keyword was missing, so I move the config file to a package called config, and now its works我得到了解决方案,我的问题是缺少 package 关键字,所以我将配置文件移动到名为 config 的 package 中,现在它可以工作了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.