• <bdo id='MYITt'></bdo><ul id='MYITt'></ul>
  • <tfoot id='MYITt'></tfoot>
  • <i id='MYITt'><tr id='MYITt'><dt id='MYITt'><q id='MYITt'><span id='MYITt'><b id='MYITt'><form id='MYITt'><ins id='MYITt'></ins><ul id='MYITt'></ul><sub id='MYITt'></sub></form><legend id='MYITt'></legend><bdo id='MYITt'><pre id='MYITt'><center id='MYITt'></center></pre></bdo></b><th id='MYITt'></th></span></q></dt></tr></i><div id='MYITt'><tfoot id='MYITt'></tfoot><dl id='MYITt'><fieldset id='MYITt'></fieldset></dl></div>

  • <small id='MYITt'></small><noframes id='MYITt'>

        <legend id='MYITt'><style id='MYITt'><dir id='MYITt'><q id='MYITt'></q></dir></style></legend>

        通过 Java 更新 LDAP 时如何指定哈希算法?

        时间:2024-05-10

          <legend id='PCGj2'><style id='PCGj2'><dir id='PCGj2'><q id='PCGj2'></q></dir></style></legend>
              <i id='PCGj2'><tr id='PCGj2'><dt id='PCGj2'><q id='PCGj2'><span id='PCGj2'><b id='PCGj2'><form id='PCGj2'><ins id='PCGj2'></ins><ul id='PCGj2'></ul><sub id='PCGj2'></sub></form><legend id='PCGj2'></legend><bdo id='PCGj2'><pre id='PCGj2'><center id='PCGj2'></center></pre></bdo></b><th id='PCGj2'></th></span></q></dt></tr></i><div id='PCGj2'><tfoot id='PCGj2'></tfoot><dl id='PCGj2'><fieldset id='PCGj2'></fieldset></dl></div>
                <tbody id='PCGj2'></tbody>
                <bdo id='PCGj2'></bdo><ul id='PCGj2'></ul>

                  <tfoot id='PCGj2'></tfoot>

                • <small id='PCGj2'></small><noframes id='PCGj2'>

                  本文介绍了通过 Java 更新 LDAP 时如何指定哈希算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当您使用 Java API 更新 Open LDAP 目录时,有没有办法指定哈希算法(MD5、SHA1 等)用于存储密码,代码如下:

                  Is there a way to specify the hash algorithm (MD5, SHA1, etc.) to use for storing the passwords when you update an Open LDAP directory using Java APIs with code like this:

                  private void resetPassword(String principal, String newPassword) throws NamingException {
                  InitialDirContext ctxAdmin = null;
                      Hashtable<String, String> ctxData = new Hashtable<String, String>();
                      ctxData.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                      ctxData.put(Context.PROVIDER_URL, "ldap://myserver:389");
                      ctxData.put(Context.SECURITY_AUTHENTICATION, "simple");
                      ctxData.put(Context.SECURITY_PRINCIPAL, "admin_dn");
                      ctxData.put(Context.SECURITY_CREDENTIALS, "admin_passwd");
                      InitialDirContext ctxAdmin = new InitialDirContext(ctxData);
                      if (newPassword == null || newPassword.equals("")) {
                          String msg = "Password can't be null";
                          throw new NamingException(msg);
                      } else {
                          if (principal == null || principal.equals("")) {
                              String msg = "Principal can't be null";
                              throw new NamingException(msg);
                          } else {
                          if (ctxAdmin == null) {
                              String errCtx = "Can't get LDAP context";
                              throw new NamingException(errCtx);
                              }
                          }
                      }   
                      BasicAttribute attr = new BasicAttribute("userpassword", newPassword);
                      ModificationItem modItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
                      ModificationItem[] items = new ModificationItem[1];
                      items[0] = modItem;
                      ctxAdmin.modifyAttributes("cn=" + principal + ",ou=Users,dc=com", items);
                  }
                  

                  推荐答案

                  应该这样做:(MD5)显示

                  Something along these lines should do it: (MD5) Shown

                  context.setAttributeValue("userPassword", digestMd5("newPassword));
                  
                  private String digestMd5(final String password) {
                    String base64;
                    try {
                       MessageDigest digest = MessageDigest.getInstance("MD5");
                       digest.update(password.getBytes());
                       base64 = new BASE64Encoder().encode(digest.digest());
                    }
                    catch (NoSuchAlgorithmException e) {
                       throw new RuntimeException(e);
                    }
                    return "{MD5}" + base64;
                  }
                  

                  -吉姆

                  这篇关于通过 Java 更新 LDAP 时如何指定哈希算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 JNDI 添加 LDAP 条目 下一篇:使用 JNDI/Java 中的当前用户在 LDAP 上进行身份验证

                  相关文章

                • <i id='cVMOq'><tr id='cVMOq'><dt id='cVMOq'><q id='cVMOq'><span id='cVMOq'><b id='cVMOq'><form id='cVMOq'><ins id='cVMOq'></ins><ul id='cVMOq'></ul><sub id='cVMOq'></sub></form><legend id='cVMOq'></legend><bdo id='cVMOq'><pre id='cVMOq'><center id='cVMOq'></center></pre></bdo></b><th id='cVMOq'></th></span></q></dt></tr></i><div id='cVMOq'><tfoot id='cVMOq'></tfoot><dl id='cVMOq'><fieldset id='cVMOq'></fieldset></dl></div>
                • <small id='cVMOq'></small><noframes id='cVMOq'>

                  • <bdo id='cVMOq'></bdo><ul id='cVMOq'></ul>

                      <tfoot id='cVMOq'></tfoot>

                      <legend id='cVMOq'><style id='cVMOq'><dir id='cVMOq'><q id='cVMOq'></q></dir></style></legend>