4

StackOverflow を使用するのはこれが初めてです。ここで何らかの回答が得られることを願っています。spring-ldap APIを使用してJavaから新しいユーザーを保存するためにWindows Active Directory 2008を使用しています

私の問題は、パスワードでユーザーを追加できないことです。unicodePwdADでパスワードを設定するには、属性を使用する必要があることをどこかで読みました。ソース: http://geekswithblogs.net/lance/archive/2005/08/19/LdapAuthenticationASP.aspx

public void insertContact(ContactDTO contactDTO) {
    try{

     Attributes personAttributes = new BasicAttributes();
     BasicAttribute personBasicAttribute = new BasicAttribute("objectclass");
     personBasicAttribute.add("person");
     personBasicAttribute.add("user");
     personAttributes.put(personBasicAttribute);

      personAttributes.put("givenName", contactDTO.getCommonName());
      personAttributes.put("cn", contactDTO.getCommonName());
      personAttributes.put("sn", contactDTO.getLastName());
      personAttributes.put("description", contactDTO.getDescription());

      personAttributes.put("unicodePwd",
          this.createUnicodePassword(contactDTO.getPassword()) );
      personAttributes.put("userPrincipalName", contactDTO.getUserLoginName());
      personAttributes.put("sAMAccountName", contactDTO.getsAMAccountName());
      personAttributes.put("displayname", contactDTO.getDisplayname());
      //  personAttributes.put( "pwdLastSet", "0" );
      //  personAttributes.put( "LockOutTime", "0" );

      personAttributes.put("userAccountControl", "544");

      BasicAttribute roomAttribute = new BasicAttribute("roomNumber");
      for(String r : contactDTO.getRoomNumber())
      {
        roomAttribute.add(r);
      }

      personAttributes.put(roomAttribute);


      DistinguishedName newContactDN = new DistinguishedName();
      newContactDN.add("cn", contactDTO.getCommonName());

      ldapTemplate.bind(newContactDN, null, personAttributes);
    }

public byte[] createUnicodePassword(String password){
    return toUnicodeBytes(doubleQuoteString(password));
}

private byte[] toUnicodeBytes(String str){
    byte[] unicodeBytes = null;
    try{
        byte[] unicodeBytesWithQuotes = str.getBytes("Unicode");
        unicodeBytes = new byte[unicodeBytesWithQuotes.length - 2];
        System.arraycopy(unicodeBytesWithQuotes, 2, unicodeBytes, 0,
            unicodeBytesWithQuotes.length - 2);
    } catch(UnsupportedEncodingException e){
        // This should never happen.
        e.printStackTrace();
    }
    return unicodeBytes;
}

private String doubleQuoteString(String str){
    StringBuffer sb = new StringBuffer();
    sb.append("\"");
    sb.append(str);
    sb.append("\"");
    return sb.toString();
}

しかし、それは私にエラーコード53を与えました

enter code here: org.springframework.ldap.UncategorizedLdapException: Operation failed; nested exception is javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000001F: SvcErr: DSID-031A11E5, problem 5003 (WILL_NOT_PERFORM), data 0

ADでユーザーパスワードを設定する方法がわかりません。また、unicodePwd を設定する場所をいくつか読みました。これが必要な場合は、SSL が必要です。この問題を解決する代替手段はありますか 助けてください

4

1 に答える 1

2

はい、WILL_NOT_PERFORM エラーは AD であり、パスワードを設定するには SSL 接続を使用する必要があることを示しています。


SSL 接続を確立するには、次のような URL を使用する必要がありますldaps://your.ldap.server:636(「ldaps」に注意してください)。証明書の検証エラーが発生した場合は、「keytool」を使用して AD サーバーの証明書を Java キーストアにインポートする必要があります。これにより、Java アプリケーションは証明書を有効なものとして認識します。

于 2010-12-01T08:10:37.287 に答える