首页 > 编程语言 > 详细

springsecurity三种认证方式

时间:2021-05-15 19:22:56      阅读:76      评论:0      收藏:0      [点我收藏+]

springsecurity有三种认证方式

第一种方式:通过配置文件设置登录名和密码

在application.yml文件中写入

  spring:

    security:

      user:

        name: admin

        password: 123

 

第二种方式:通过配置类实现

    

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//this.disableLocalConfigureAuthenticationBldr = true;

BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = passwordEncoder.encode("123");
auth.inMemoryAuthentication().withUser("lucy").password(password).roles("admin");
}

@Bean
PasswordEncoder password(){
return new BCryptPasswordEncoder();
}

}

第三种方式:通过自定义编写实现类 




springsecurity三种认证方式

原文:https://www.cnblogs.com/dgq000/p/14771141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!