简体   繁体   English

如何配置 spring-boot-starter-security

[英]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.

相关问题 如何安装spring-boot-starter-security依赖项 - How to install spring-boot-starter-security dependency 在一个简单的 Maven 项目中找不到依赖 spring-boot-starter-security - The dependency spring-boot-starter-security is not found in a simple Maven project 在Spring Boot应用程序中添加spring-boot-starter-security会导致错误“ entityManagerFactory”或“ persistenceUnitName” - Adding spring-boot-starter-security to Spring Boot application causes error 'entityManagerFactory' or 'persistenceUnitName' is required 未找到依赖项 'org.springframework.boot:spring-boot-starter-security:2.2.6.RELEASE' - Dependency 'org.springframework.boot:spring-boot-starter-security:2.2.6.RELEASE' not found Maven spring-boot-starter-security将org.springframework.security限制为3.2.8版本且未使用4.0.2 - Maven spring-boot-starter-security limiting org.springframework.security to version 3.2.8 and not using 4.0.2 在没有 spring-boot-starter-web 的情况下配置 Spring Security AuthenticationManager - Configure Spring Security AuthenticationManager without spring-boot-starter-web 如何为 spring 启动项目配置 spring 安全性 - how to configure spring security for spring boot project spring boot starter security post方法不起作用 - spring boot starter security post methods not working Spring Boot,安全启动器和OAuth2客户端 - Spring boot, security starter and OAuth2 client Spring boot starter 安全性 - 缺少 RsaKeyConverters - Spring boot starter security - missing RsaKeyConverters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM