database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
ㆍLDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
LDAP Q&A 3239 게시물 읽기
No. 3239
Active Directory PassWord변경시 에러 질문드립니다.
작성자
김인성(일각천금)
작성일
2012-05-15 11:21
조회수
7,495

  
 
import java.util.Hashtable;  
import javax.naming.*;  
import javax.naming.directory.*;  

import org.w3c.dom.Attr;
 
import java.io.*;  
 
public class Setpass2 {  
    @SuppressWarnings("unchecked")  
    public static void main(String[] args) {  
 
        Hashtable env = new Hashtable(); 
   String ldapHost = "123.4.123.123"; //
   String domain = "test.com"; //
   String port = "389"; // default Port
   String urlDC = "ldap://" + ldapHost + ":" + port + "/";    
        String adminName = "dev@test.com";     
        String adminPassword = "xptmxm12#";     
        String userName = "CN=dev";     
        String oldPassword = "xptmxm12@";     
        String newPassword = "xptmxm12$";     
        String searchBase = "DC=test,DC=com";      
  
        env.put(Context.INITIAL_CONTEXT_FACTORY,   "com.sun.jndi.ldap.LdapCtxFactory");          

        env.put(Context.SECURITY_AUTHENTICATION, "simple");  
        env.put(Context.SECURITY_PRINCIPAL, adminName);  
        env.put(Context.SECURITY_CREDENTIALS, adminPassword);  

        env.put(Context.PROVIDER_URL, urlDC);  
       

        try {  
 
            // Create the initial directory context  
            DirContext ctx = new InitialDirContext(env);  
              
            // Create the search controls  
            SearchControls searchCtls = new SearchControls();  
 
            // Specify the search scope  
            searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);  
 
            // Specify the attributes to return  
            String returnedAtts[] = { "cn=dev" };  
            searchCtls.setReturningAttributes(returnedAtts);
 
            // initialize counter to total the results  
            int totalResults = 0;  
 
            // Search for objects using the filter  
            NamingEnumeration dirObjects = ctx.search(searchBase, "(sAMAccountName=dev)",
              searchCtls);
 
            //while (answer.hasMoreElements()) {  
            SearchResult sr = (SearchResult) dirObjects.next();  
 
            totalResults++;  
 
            System.out.println(">>>" + sr.getName());  
 
           // }  
            ModificationItem[] mods = new ModificationItem[1];  
           
            //Replace the "unicdodePwd" attribute with a new value  
            //Password must be both Unicode and a quoted string  
            String oldQuotedPassword = "\"" + oldPassword + "\"";  
            byte[] oldUnicodePassword = oldQuotedPassword.getBytes("UTF-16LE");  
            String newQuotedPassword = "\"" + newPassword + "\"";  
            byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");  
          
           // mods[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("unicodePwd", oldUnicodePassword));  
            mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("unicodePwd", newUnicodePassword));  
           
           
            if (mods == null) {  
                System.out.println("Mods is empty");  
 
            } else {  
                System.out.println(mods);  
            }  
 
            // Perform the update  
            ctx.modifyAttributes("CN=dev,CN=Users,DC=test,DC=com", mods);  
    
 
            // Check attributes  
           
           
            //Attributes attrs = sr.getAttributes();  
            //System.out.println(attrs.toString());
            //ctx.modifyAttributes(userName, DirContext.REPLACE_ATTRIBUTE, attrs);  
                
 
            System.out.println("Reset Password for: " + userName);  
            ctx.close();  
 
        } catch (NamingException e) {  
            System.out.println("Problem resetting password: " + e);  
 
        } catch (UnsupportedEncodingException e) {  
            System.out.println("Problem encoding password: " + e);  
        }  
 
    }  
 

비밀번호 변경하는중입니다 .

AD서버는 windows2008 입니다.
다음과 같은 코드에서 에러가 생깁니다. ㅠ

Problem resetting password: javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000001F: SvcErr: DSID-031A11E5, problem 5003 (WILL_NOT_PERFORM), data 0'

remaning name "cn=dev, cn=Users, dc=test,dc=com" 
보니까 modifyAttributes에서 에러가 나는데 그 이유를 잘 모르겠습니다.

함수를 찾아봐도 별로 잘못쓴게 없는거 같은데 에러가 나는 이유는 뭔지 고수님들 부탁드립니다.

LDAP 접한지 이제 일주일된 초보입니다.ㅠ

이 글에 대한 댓글이 총 2건 있습니다.

JAVA에서 AD 비밀번호 변경시에 AD에서 인증서를 받아서 SSL통신으로 해야

패스워드를 바꿀 수 있습니다. 636포트로 접근을 해야겠지요...

송상준(sjsong)님이 2012-05-16 13:38에 작성한 댓글입니다.

송상준님 감사합니다.

성공하였습니다.

SSL인증받는 부분이 처음이라그런지 많이 헤메이긴 했지만요 ^^

김인성(일각천금)님이 2012-05-17 10:17에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
3242질문입니다. 디렉토리서버 java검색 질문입니다. [5]
열심히
2012-06-07
5339
3241질문입니다.CER을DER로 변환 할 수 있는지요. [1]
열심히
2012-06-06
5331
3240OID에서 suffix와콘텍스트와 관련된 java검색에 대하여 질문 [2]
열심히
2012-05-22
5456
3239Active Directory PassWord변경시 에러 질문드립니다. [2]
김인성
2012-05-15
7495
3238ldap 11g 설치시 오류 [1]
ldap
2012-05-14
5286
3237LDAP err 관련 질문 드립니다. [1]
김효섭
2012-05-11
6198
3236openldap 라이브러리 사용시 TLS/SSL 사용 방법 문의 [1]
자운몽
2012-04-19
4535
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.051초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다