にパスワードを持つユーザーを追加するこれは私の初めてのStackOverflowです。私はここでいくつかの回答を得ることを願っています。 私はWindows Active Directory 2008を使用して、spring-ldap APIを使用してJavaから新しいユーザーを保存していますActive Directory LDAP
私の問題は、パスワードをユーザーに追加できないことです。パスワードを設定するにはADのどこかを読んで、unicodePwd
属性を使用する必要があります。出典: 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();
}
が、それは私がADでユーザーパスワードを設定する方法を私は知らない、エラーコード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
を与えられました。私はunicodePwdを設定する場所もいくつか読んでいますが、これが必要な場合には私はSSLを必要とする場合があります。この問題を解決するための方法はありますか?
これをテストしているときに、「Unicode」エンコードとBOMのストリッピングを使用する代わりに、エンコーディングとして「UTF-16LE」を使用することができます。 ( '' '' + password + '"').getBytes(" UTF-16LE ")。 –