zoukankan      html  css  js  c++  java
  • springboot2.x+security对明文密码加密

    1---添加依赖

     <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>

    2---在与启动类同包下创建配置类

    @Configuration
    public class securityUtils extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().antMatchers("/**").permitAll()//放行所有权限
            .and().csrf().disable();//相当于<security:csrf enabled=false/>
    
        }
    
    }
    

    3---service层注入并加入:

       @Autowired
        private BCryptPasswordEncoder encoder;
    
    
    
       public int insertUser(User user){
            user.setPassword(encoder.encode(user.getPassword()));//加入
            return userRepository.insertUser(user);
        }

    4---启动类

       @Bean
        public BCryptPasswordEncoder encoder(){
            return  new BCryptPasswordEncoder();
        }
    不经一番彻骨寒,哪有梅花扑鼻香?
  • 相关阅读:
    Explain执行计划
    SQL优化(SQL + 索引)
    SQL(含索引)
    分组聚合 merger
    服务分组 group
    多注册中心 registry
    多协议 protocol
    常用协议 —— webservice://
    常用协议 —— http://
    最强AngularJS资源合集
  • 原文地址:https://www.cnblogs.com/zongyao/p/13831145.html
Copyright © 2011-2022 走看看