에 암호가있는 사용자를 추가하는 것은 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
을 부여. 우리가 SSL을 필요로한다면 unicodePwd를 설정할 위치를 읽습니다. 이 문제를 해결할 수있는 대안이 있습니까?
이것을 테스트하는 동안 "유니 코드"인코딩과 BOM 제거 대신 "UTF-16LE"를 인코딩으로 사용할 수 있다는 것을 알았습니다. ('' '+ password +' " ') .getBytes ("UTF-16LE "). –