zoukankan      html  css  js  c++  java
  • withDefaultPasswordEncoder() 过时弃用问题

      在学springsecurity5.X时,在demo里,内存配置用户的时候,提示withDefaultPasswordEncoder过时,特查看了源码,官方给出的理由是:

        /** @deprecated */
        @Deprecated
        public static User.UserBuilder withDefaultPasswordEncoder() {
            logger.warn("User.withDefaultPasswordEncoder() is considered unsafe for production and is only intended for sample applications.");
            PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
            User.UserBuilder var10000 = builder();
            encoder.getClass();
            return var10000.passwordEncoder(encoder::encode);
        }

     @Deprecated  弃用的意思

    日志里也写得清楚弃用的原因:不安全

    所以,换了个写法,如下:

       /**
         * 在内存中配置一个用户,admin/admin分别是用户名和密码,这个用户拥有USER角色。
         * withDefaultPasswordEncoder 被遗弃,原因是不安全,只能在例子中使用
         * @param auth
         * @throws Exception
         */
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            // withDefaultPasswordEncoder被弃用,用以下方式
            PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
            auth.inMemoryAuthentication()
    //                .withUser(User.withDefaultPasswordEncoder().username("admin")
                    .withUser("admin")
                    .password(encoder.encode("admin")).roles("USER");
        }

     

  • 相关阅读:
    CodeForces gym Nasta Rabbara lct
    bzoj 4025 二分图 lct
    CodeForces 785E Anton and Permutation
    bzoj 3669 魔法森林
    模板汇总——快读 fread
    bzoj2049 Cave 洞穴勘测 lct
    bzoj 2002 弹飞绵羊 lct裸题
    HDU 6394 Tree 分块 || lct
    HDU 6364 Ringland
    nyoj221_Tree_subsequent_traversal
  • 原文地址:https://www.cnblogs.com/hsz-csy/p/9675641.html
Copyright © 2011-2022 走看看