当前位置: 首页 > news >正文

地方门户网站管理系统美食网站程序

地方门户网站管理系统,美食网站程序,佛山手机建网站,2023营业执照年检在上一篇文章中#xff0c;我们使用jdbc和md5密码编码将密码编码添加到了我们的spring安全配置中。 但是#xff0c;在定制UserDetailsS​​ervices的情况下#xff0c;我们需要对安全配置进行一些调整。 我们需要创建一个DaoAuthenticationProvider bean#xff0c;并将… 在上一篇文章中我们使用jdbc和md5密码编码将密码编码添加到了我们的spring安全配置中。 但是在定制UserDetailsS​​ervices的情况下我们需要对安全配置进行一些调整。 我们需要创建一个DaoAuthenticationProvider bean并将其设置为AuthenticationManagerBuilder。 由于我们需要一个Custom UserDetailsS​​ervice因此我将使用Spring Security / MongoDB示例代码库。 我们要做的是更改我们的Spring Security配置。 package com.gkatzioura.spring.security.config;import com.gkatzioura.spring.security.service.CustomerUserDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Profile; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.authentication.encoding.Md5PasswordEncoder; 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.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;import javax.sql.DataSource;/*** Created by gkatzioura on 10/5/16.*/ EnableWebSecurity Profile(encodedcustompassword) public class PasswordCustomEncodedSecurityConfig extends WebSecurityConfigurerAdapter {Beanpublic UserDetailsService mongoUserDetails() {return new CustomerUserDetailsService();}Beanpublic DaoAuthenticationProvider authProvider() {DaoAuthenticationProvider authProvider new DaoAuthenticationProvider();authProvider.setUserDetailsService(mongoUserDetails());authProvider.setPasswordEncoder(new BCryptPasswordEncoder());return authProvider;}Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.authenticationProvider(authProvider());}Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers(/public).permitAll().anyRequest().authenticated().and().formLogin().permitAll().and().logout().permitAll();}} 在大多数情况下这可以。 但是我们也可能希望推出自己的PasswordEncoder这非常简单。 package com.gkatzioura.spring.security.encoder;import org.springframework.security.crypto.bcrypt.BCrypt; import org.springframework.security.crypto.password.PasswordEncoder;/*** Created by gkatzioura on 10/5/16.*/ public class CustomPasswordEncoder implements PasswordEncoder {Overridepublic String encode(CharSequence rawPassword) {String hashed BCrypt.hashpw(rawPassword.toString(), BCrypt.gensalt(12));return hashed;}Overridepublic boolean matches(CharSequence rawPassword, String encodedPassword) {return BCrypt.checkpw(rawPassword.toString(), encodedPassword);}} 因此我们将更改配置以使用新的PasswordEncoder Beanpublic DaoAuthenticationProvider authProvider() {DaoAuthenticationProvider authProvider new DaoAuthenticationProvider();authProvider.setUserDetailsService(mongoUserDetails());authProvider.setPasswordEncoder(new CustomPasswordEncoder());return authProvider;} 下一步将是创建编码后的密码。 Testpublic void customEncoder() {CustomPasswordEncoder customPasswordEncoder new CustomPasswordEncoder();String encoded customPasswordEncoder.encode(custom_pass);LOGGER.info(Custom encoded encoded);} 然后将具有哈希密码的用户添加到我们的mongodb数据库中。 db.users.insert({name:John,surname:doe,email:john2doe.com,password:$2a$12$qB.L7buUPi2RJHZ9fYceQ.XdyEFxjAmiekH9AEkJvh1gLFPGEf9mW,authorities:[user,admin]}) 我们所需要做的就是更改gradle脚本上的默认配置文件我们一切顺利。 bootRun {systemProperty spring.profiles.active, encodedcustompassword } 您可以在github上找到源代码。 翻译自: https://www.javacodegeeks.com/2016/10/spring-security-custom-password-encoding.html
http://www.pierceye.com/news/620899/

相关文章:

  • 深圳 网站建设公司南宁网站忧化
  • 做油和米的网站山西省网站备案
  • 做网站有陪标现象吗成都建设网站专业公司
  • 莱阳 网站建设博罗做网站公司
  • 简易个人网站模板推广一款app的营销方案
  • 小城镇建设有关网站起飞页怎么做网站
  • 网站影响seo的标签网站用国外的服务器打不开
  • 仿站 做网站网站备案 图标
  • 网站怎么做留言提交功能wordpress个人支付接口
  • 有哪些做室内设计好用的网站廊坊网站制作推广
  • 做村易通网站站长要收费吗?elegant wordpress
  • 网站建设专业培训网站开发网页加载缓慢查询数据库慢
  • 网站开发中 视频播放卡做soho建立网站
  • 面试网站开发员安徽建工集团网站
  • 公司制作网站价格表app系统开发费用
  • 网站建设需要学什么h5海报是怎么做出来的
  • 西平企业网站建设美媒中国或已建立了51区
  • 柯城区住房和城乡建设局网站免费搭建淘宝客网站
  • 低价机票 网站建设网站模板
  • 手机网站建设的教程视频做的网站怎么放在网上
  • 做视频网站视频空间设计是什么
  • 怎么把网站推广wordpress 百万数据
  • 乐陵市人力资源中心网站网站的内容和功能
  • wordpress网站搬家图片路径做网站的算什么行业
  • 个人网站logo重庆网络优化平台
  • 河南 网站建设静态网站是什么意思
  • 上海正规做网站公司电话基于flash网站设计
  • 每个城市建设规划在哪个网站wordpress 无法安装主题
  • 自建网站做外贸谷歌推广网站内部资源推广方法
  • 网站数据库5g一个人看的免费视频高清直播