LECTURE 5 ¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤Î°À­Êѹ¹

¡û ¤Ï¤¸¤á¤Ë

¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤ÎÅÐÏ¿/ºï½ü¡¢¥¨¥ó¥È¥ê¤Î¸¡º÷¤ÈÍ褿¤È¤³¤í¤Ç¡¢º£Å٤ϥ¨¥ó¥È¥ê¤Î°À­¤ËÂФ¹¤ëÁàºî¤ò¹Ô¤¦ÊýË¡¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤­¤¿¤¤¤È»×¤¤¤Þ¤¹¡£²Äǽ¤ÊÁàºî¤Ë¤Ï¡¢Äɲᢽ¤Àµ¡¢ºï½ü¤Î 3 ¼ïÎब¤¢¤ê¤Þ¤¹¡£

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à

LDAP ¥µ¡¼¥Ð¤ËÀܳ¤·¡¢»ØÄꤵ¤ì¤¿¥¨¥ó¥È¥ê¤Î°À­¤ËÂФ·¤Æ»ØÄꤵ¤ì¤¿Áàºî ( Äɲà / ½¤Àµ / ºï½ü ) ¤ò¹Ô¤¦¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à LDAPModify.java ¤Ç¤¹¡£

¥³¥ó¥Ñ¥¤¥ë¤¬½ªÎ»¤·¤¿¤é

java LDAPModify [LDAP¥µ¡¼¥Ð̾/IP¥¢¥É¥ì¥¹] \
                [bind¥æ¡¼¥¶¤ÎDN] \
                [bind¥æ¡¼¥¶¤Î¥Ñ¥¹¥ï¡¼¥É] \
                [add(ÄɲÃ) / mod(½¤Àµ) / del(ºï½ü)] \
                [°À­¤òÁàºî¤¹¤ë¥¨¥ó¥È¥ê¤ÎDN] \
                [Áàºî¤¹¤ë°À­Ì¾] \
                [¿·¤¿¤ËÀßÄꤹ¤ë°À­ÃÍ]

¤Ç¼Â¹Ô¤Ç¤¹¡£Àµ¾ï¤Ë½èÍý¤¬½ªÎ»¤·¤¿¾ì¹ç¤Ï¤½¤Î»Ý¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£²¿¤é¤«¤ÎÎã³°¤¬È¯À¸¤·¤¿¤é¡¢¤½¤ÎÆâÍƤ¬É½¼¨¤µ¤ì¤Þ¤¹¡£

¤Ê¤ª¡¢¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤éÁ´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

--- LDAPModify.java ---

    1	import org.ietf.ldap.LDAPAttribute;
    2	import org.ietf.ldap.LDAPConnection;
    3	import org.ietf.ldap.LDAPException;
    4	import org.ietf.ldap.LDAPModification;
    5	import org.ietf.ldap.LDAPModificationSet;
    6	
    7	
    8	/**
    9	 * LDAP ¥µ¡¼¥Ð¤ËÀܳ¤·¡¢»ØÄꤵ¤ì¤¿¥¨¥ó¥È¥ê¤Î°À­ÃͤËÂФ·¤ÆÁàºî¤ò¹Ô¤¦¡£
   10	 *
   11	 * @version 19 May 2002
   12	 * @author  Ryo Ichinose
   13	 */
   14	public class LDAPModify
   15	{
   16		/**
   17		 * LDAP Protocol Version 3
   18		 */
   19		public static final int LDAP_V3 = 3; // LDAPv3
   20	
   21	
   22		/**
   23		 * »ØÄꤵ¤ì¤¿ LDAP ¥µ¡¼¥Ð¤ËÀܳ¤·¡¢»ØÄꤵ¤ì¤¿ DN ¤Ç¼±Ê̤µ¤ì¤ë¥¨¥ó¥È¥ê
   24		 * ¤Î°À­¤ËÂФ·¤ÆÊѹ¹½èÍý¤ò¹Ô¤¦¡£Êѹ¹½èÍý¤Ë¤Ï¡¢Äɲà / ½¤Àµ / ºï½ü¤Î 
   25		 * 3 ¼ïÎà¤Î½èÍý¤¬´Þ¤Þ¤ì¤ë¡£
   26		 *
   27		 * @param host    ¥Û¥¹¥È̾¤â¤·¤¯¤Ï IP¥¢¥É¥ì¥¹
   28		 * @param binddn  bind ¥æ¡¼¥¶¤Î DN
   29		 * @param bindpw  bind ¥æ¡¼¥¶¤Î¥Ñ¥¹¥ï¡¼¥É
   30		 * @param cmd     ÄɲÃ( add )/½¤Àµ( mod )/ºï½ü( del )
   31		 * @param moddn   °À­¤òÁàºî¤¹¤ë¥¨¥ó¥È¥ê¤Î DN
   32		 * @param name    Áàºî¤¹¤ë°À­Ì¾
   33		 * @param value   ¿·¤¿¤ËÀßÄꤹ¤ë°À­ÃÍ
   34		 */
   35		public void modify( String host, String binddn, String bindpw,
   36				    String cmd,  String moddn,  
   37				    String name, String value )
   38		{
   39			LDAPModificationSet ms = new LDAPModificationSet();
   40			LDAPAttribute attr = new LDAPAttribute( name, value );
   41	
   42			// cmd ¤Ë±þ¤¸¤Æ LDAPModificationSet ¤ËÀßÄꤹ¤ëÁàºî¼ïÊ̤ò
   43			// Êѹ¹¤¹¤ë¡£
   44			if ( cmd.equals( "add" ) ) {
   45				ms.add( LDAPModification.ADD, attr );
   46			}
   47			else if ( cmd.equals( "mod" ) ) {
   48				ms.add( LDAPModification.REPLACE, attr );
   49			}
   50			else if ( cmd.equals( "del" ) ) {
   51				ms.add( LDAPModification.DELETE, attr );
   52			}
   53	
   54			LDAPConnection lc = new LDAPConnection();
   55			
   56			try {
   57				// LDAP ¥µ¡¼¥Ð¤ËÀܳ¤¹¤ë¡£¥Ý¡¼¥È¤Ï¥Ç¥Õ¥©¥ë¥È(389ÈÖ)¤ò»È¤¦¡£
   58				lc.connect( host, LDAPConnection.DEFAULT_PORT );
   59				System.out.println( "Connected to " + host );
   60				System.out.println();
   61	
   62	
   63				// »ØÄꤵ¤ì¤¿ DN ¤ª¤è¤Ó¥Ñ¥¹¥ï¡¼¥É¤Ç¥Ð¥¤¥ó¥É(ǧ¾Ú)¤¹¤ë¡£
   64				// ¤³¤ì¤ò¼Â¹Ô¤·¤Ê¤¤¾ì¹ç¡¢anonymous ¾õÂÖ¤ÇÁàºî¤¹¤ë¤³¤È¤Ë¤Ê¤ë¡£
   65				lc.bind( LDAPModify.LDAP_V3, binddn, bindpw );
   66	
   67	
   68				// »ØÄꥨ¥ó¥È¥ê¤Î°À­Áàºî¤ò¼Â¹Ô¤¹¤ë¡£
   69				lc.modify( moddn, ms );
   70				System.out.println( "Successfully modified" );
   71	
   72				// Àܳ¤òÀÚÃǤ¹¤ë¡£
   73				lc.disconnect();
   74				System.out.println();		
   75				System.out.println( "Disconnected" );
   76			}
   77			catch( LDAPException e ) {
   78				System.out.println( "LDAPException occured : " + 
   79						    e.toString() );
   80			}
   81		}
   82	
   83	
   84		/**
   85		 * ¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
   86		 *
   87		 * @param args 
   88		 *    <ul>
   89		 *      <li>args[0] --- ¥Û¥¹¥È̾¤â¤·¤¯¤Ï IP ¥¢¥É¥ì¥¹
   90		 *      <li>args[1] --- bind ¥æ¡¼¥¶¤Î DN
   91		 *      <li>args[2] --- bind ¥æ¡¼¥¶¤Î¥Ñ¥¹¥ï¡¼¥É
   92		 *      <li>args[3] --- ÄɲÃ( add )/½¤Àµ( mod )/ºï½ü( del )
   93		 *      <li>args[4] --- °À­¤òÁàºî¤¹¤ë¥¨¥ó¥È¥ê¤Î DN
   94		 *      <li>args[5] --- Áàºî¤¹¤ë°À­Ì¾
   95		 *      <li>args[6] --- ¿·¤¿¤ËÀßÄꤹ¤ë°À­ÃÍ
   96		 *    </ul>
   97		 */
   98		public static void main( String[] args )
   99		{
  100			LDAPModify obj = new LDAPModify();
  101			obj.modify( args[0], args[1], args[2], args[3], 
  102				    args[4], args[5], args[6] );
  103		}
  104	}


¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÀâÌÀ

¤Ç¤Ï¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤­¤Þ¤¹¡£

  • 1 ¡Á 5 ¹ÔÌÜ

    »ÈÍѤ¹¤ë¥¯¥é¥¹¥é¥¤¥Ö¥é¥ê¤Î¥Ñ¥Ã¥±¡¼¥¸»ØÄê¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£LDAPModify.java ¤Ç¤Ï¡¢¿·¤¿¤Ë LDAPModification¡¢LDAPModificationSet ¤Î 2 ¤Ä¤Î¥¯¥é¥¹¤ò»ÈÍѤ·¤Þ¤¹¡£

  • 22 ¡Á 81 ¹ÔÌÜ ( LDAPModify#modify() )

    LDAPModify#modify() ¥á¥½¥Ã¥É¤Ç¡¢»ØÄꤵ¤ì¤¿¥¨¥ó¥È¥ê¤Î°À­¤ËÂФ·¤ÆÁàºî¤ò¹Ô¤¤¤Þ¤¹¡£³Æ¥ö½ê ¤Ë¤Ä¤¤¤Æ°Ê¹ß¤ÇÀâÌÀ¤·¤Þ¤¹¡£

    • 39 ¹ÔÌÜ

      LDAPModificationSet ¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£²¿¤Î¤¿¤á¤Ë¤«¤È¸À¤¦¤È¡¢Áàºî¤¹¤ë °À­¤Î̾¾Î¤ÈÃÍ¤Ï LDAPAttribute ¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ËÀßÄꤷ¤Þ¤¹¤¬¡¢LDAP ¥µ¡¼¥Ð¤ËÂФ·¤ÆÍ× µá¤ò½Ð¤¹¤Ë¤Ï LDAPAttribute ¤ò¹¹¤Ë LDAPModification ¤â¤·¤¯¤Ï LDAPModificationSet ¥¯¥é¥¹¤Î ¥¤¥ó¥¹¥¿¥ó¥¹¤ËÀßÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£LDAPModification ¤ª¤è¤Ó LDAPModificationSet ¥¯¥é¥¹ ¤¬¡¢Â°À­¤ÎÁàºî¤ò¹Ô¤¦¾ì¹ç¤ÎÍ×µáñ°Ì¤Ë¤Ê¤ë¤ï¤±¤Ç¤¹¡£

      LDAPModification ¤È LDAPModificationSet ¤Î°ã¤¤¤Ï¡¢LDAPModification ¤¬Ã±°ì¤Î°À­¾ðÊó¤òÊÝ»ý ¤¹¤ë¤Î¤ËÂФ·¤Æ¡¢LDAPModificationSet ¤ÏÊ£¿ô¤Î°À­¾ðÊó¤òÊÝ»ý¤Ç¤­¤ë¤³¤È¤Ç¤¹¡£ ¤Ä¤Þ¤ê¡¢Ã±°ì°À­¤ÎÁàºî¤ò¹Ô¤¦¾ì¹ç¤Ï LDAPModification ¤ò¡¢Ê£¿ô°À­¤ÎÁàºî¤ò¹Ô¤¦¾ì¹ç¤Ï LDAPModificationSet ¤ò»ÈÍѤ¹¤ì¤ÐÎɤ¤¤È¤¤¤¦¤³¤È¤Ç¤¹¡£

      ¼Â¤Ï LDAPModify.java ¤Ç¤Ïñ°ì°À­¤ÎÁàºî¤·¤«¹Ô¤ï¤Ê¤¤¤¿¤á LDAPModification ¤ò»ÈÍѤ¹¤ì¤ÐÎɤ¤ ¤Î¤Ç¤¹¤¬¡¢²¿¸Î¤« LDAPModificationSet ¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£ ²¿¸Î¤«¤È¤¤¤¦¤È¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤òºîÀ®¤·¤¿»þÅÀ¤Ç¤Ï¤½¤ì¤òÃΤé¤Ê¤«¤Ã¤¿¤«¤é¤Ç¤¹¡£¡£¡£

    • 40 ¹ÔÌÜ

      °À­Ì¾¤È°À­ÃͤÎÁȤ«¤é¡¢LDAPAttribute ¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£ ¤³¤ì¤ò¾å¤ÇºîÀ®¤·¤¿ LDAPModificationSet ¤ËÀßÄꤹ¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

    • 42 ¡Á 52 ¹ÔÌÜ

      ´û¤ËºîÀ®¤·¤¿ LDAPAttribute ¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ò LDAPModificationSet ¤ËÀßÄꤷ¤Þ¤¹¡£ LDAPModificationSet ¤Ë°À­¾ðÊó¤òÀßÄꤹ¤ëºÝ¤Ë¤Ï¡¢¤½¤Î°À­¤ËÂФ¹¤ëÁàºî¼ïÊ̤âƱ»þ¤Ë ÀßÄꤷ¤Ê¤±¤ì¤Ð¤¤¤±¤Þ¤»¤ó( LDAPModification ¤Î¾ì¹ç¤âƱÍÍ )¡£Áàºî¼ïÊ̤ˤϰʲ¼¤Î¤¤¤º¤ì¤«¤ò ÀßÄê¤Ç¤­¤Þ¤¹¡£

      • LDAPModification.ADD ( Äɲà )
      • LDAPModification.DELETE ( ºï½ü )
      • LDAPModification.REPLACE ( ÃÖ´¹¡¢ÍפϽ¤Àµ )

      ¼ÂºÝ¤ËÀßÄꤹ¤ë¤Ë¤Ï¡¢LDAPModificationSet#add() ¤ò»È¤¤¤Þ¤¹¡£

        public void LDAPModificationSet#add( int op, LDAPAttribute attr )
      
        op   : Áàºî¼ïÊÌ
        attr : °À­¾ðÊó
      
      

      ¤Ê¤ª LDAPModification ¤ò»È¤¦¾ì¹ç¤Ï¡¢¥³¥ó¥¹¥È¥é¥¯¥¿¤Î°ú¿ô¤ËÁàºî¼ïÊ̤È°À­¾ðÊó¤òÍ¿¤¨¤Æ ¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤·¤Þ¤¹¡£

        (Îã)
        LDAPModification md = 
                   new LDAPModification( 
                           LDAPModification.ADD, 
                           new LDAPAttribute( name, value ));
      
      

    • 68 ¡Á 70 ¹ÔÌÜ

      LDAPConnection#modify() ¤ò»È¤Ã¤Æ¡¢Â°À­¤ËÂФ¹¤ëÁàºî¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ¤¹¡£

        public void LDAPConnection#modify( 
                                String              dn,
                                LDAPModificationSet mods )
           throws LDAPException
      
        dn   : °À­¤òÁàºî¤¹¤ë¥¨¥ó¥È¥ê¤Î DN
        mods : °À­¾ðÊó¤È¤½¤ì¤ËÂФ¹¤ëÁàºî¼ïÊ̤ÎÁȤ¬Ê£¿ô´Þ¤Þ¤ì¤ë
      
      

      ²¿¤é¤«¤ÎÍýͳ¤ÇÁàºî¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¡¢LDAPException ¤¬ throw ¤µ¤ì¤Þ¤¹¡£¤½¤ÎÆâÍƤˤĤ¤¤Æ¤Ï¸å½Ò ¤·¤Þ¤¹¡£

      modify() ¥á¥½¥Ã¥É¤Ï¾å¤Î·Á¼°°Ê³°¤Î·Á¤Ç¤¤¤¯¤Ä¤«¥ª¡¼¥Ð¡¼¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤½¤ì¤¾¤ì¤Î¾ÜºÙ¤Ë ¤Ä¤¤¤Æ¤Ï JLDAP ¤Î API ¥É¥­¥å¥á¥ó¥È¤ò»²¾È¤·¤Æ²¼¤µ¤¤¡£¤Ê¤ª¡¢LDAPModification ¤ò»È¤¦ºÝ¤Ë¤Ï ¥ª¡¼¥Ð¡¼¥í¡¼¥É¤µ¤ì¤Æ¤¤¤ë¥á¥½¥Ã¥É¤ò»ÈÍѤ¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

    • 77 ¡Á 80 ¹ÔÌÜ

      ¤³¤³¤Þ¤Ç¤Î½èÍý¤ÇȯÀ¸¤·¤¿ LDAPException ¤ò catch ¤·¤Æ¡¢ÆâÍƤòɽ¼¨¤·¤Æ¤¤¤Þ¤¹¡£º£²ó¤Î ¿·¤¿¤Ê½èÍý¤Ë¤è¤Ã¤ÆȯÀ¸¤¹¤ë²ÄǽÀ­¤Î¤¢¤ëÎã³°ÆâÍƤˤĤ¤¤Æ¡¢¼«Ê¬¤¬³Îǧ¤Ç¤­¤¿ÈÏ°Ï¤Ç °Ê²¼¤Ë¤Þ¤È¤á¤Æ¤ª¤­¤Þ¤¹¡£Îã¤Ë¤è¤Ã¤Æ¤³¤ì¤ÇÁ´¤Æ¤È¤¤¤¦°ÕÌ£¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£

      ÈÖ¹æ ¥¨¥é¡¼¥³¡¼¥É¤ÎÄê¿ô̾(LDAPException.XXX ¤Î·Á¤Ç»²¾È²Ä) ÆâÍÆ
      2 PROTOCOL_ERROR LDAP ¥µ¡¼¥Ð¤¬¥¯¥é¥¤¥¢¥ó¥È¤«¤éÉÔÀµ¤ÊÍ×µá¤ò¼õ¤±¼è¤Ã¤¿¡£LDAPModify.java ¤Î¾ì¹ç¡¢ Áàºî¼ïÊ̤ËÉÔÀµ¤ÊÃͤò»ØÄꤹ¤ë¤ÈȯÀ¸¤¹¤ë¡£
      16 NO_SUCH_ATTRIBUTE »ØÄꤵ¤ì¤¿Â°À­¤¬¥¨¥ó¥È¥êÆâ¤Ë¸ºß¤·¤Ê¤¤¡£ºï½ü¤¹¤ë¤¿¤á¤Ë°À­Ì¾¤È°À­Ãͤò»ØÄꤹ¤ëºÝ¤Ë¡¢ °À­Ì¾¤ËÂФ·¤Æ LDAP ¥µ¡¼¥Ð¦¤Ç´û¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë°À­ÃͤǤϤʤ¯Å¬Åö¤ÊÃͤòÀßÄꤹ¤ë¤È¡¢ ¤³¤ÎÎã³°¤¬È¯À¸¤¹¤ë¡£Â°À­Ì¾¤¬´Ö°ã¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï²¼¤Î UNDEFINED_ATTRIBUTE_TYPE ¤¬È¯À¸¤¹¤ë¡£
      17 UNDEFINED_ATTRIBUTE_TYPE »ØÄꤵ¤ì¤¿Â°À­¤¬ LDAP ¥µ¡¼¥Ð¦¤Î¥¹¥­¡¼¥Þ¤Ë¸ºß¤·¤Ê¤¤¡£¤Ä¤Þ¤ê¡¢LDAPAttributeSet ¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ËÀßÄꤷ¤¿Â°À­Ì¾¤¬Àµ¤·¤¯¤Ê¤¤¤³¤È¤òɽ¤·¤Æ¤¤¤ë¡£
      32 NO_SUCH_OBJECT modify() ¤Ë»ØÄꤷ¤¿ DN ¤Ç¼±Ê̤µ¤ì¤ë¥ª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤¹¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤ (¸ºß¤·¤Ê¤¤)¡£
      34 INVALID_DN_SYNTAX »ØÄꤷ¤¿ DN ¤Î¹½Ê¸¤¬Àµ¤·¤¯¤Ê¤¤¡£
      65 OBJECT_CLASS_VIOLATION ¥ª¥Ö¥¸¥§¥¯¥È¥¯¥é¥¹¤ËŬÍѤµ¤ì¤ëµ¬Â§¤ËÈ¿¤·¤¿½èÍý¤ò¹Ô¤ª¤¦¤È¤·¤Æ¤¤¤ë¡£ ɬ¿Ü°À­¤òºï½ü¤·¤è¤¦¤È¤·¤¿¾ì¹ç¤ËȯÀ¸¤¹¤ë¡£

°Ê¾å¤Ç LDAPModify.java ¤Ë¤Ä¤¤¤Æ¤ÎÀâÌÀ¤Ï½ª¤ï¤ê¤Ç¤¹¡£¼Â¤Ï¡¢º£¤Î½ê¤³¤³¤Þ¤Ç¾Ò²ð¤·¤Æ¤­¤¿½èÍý°Ê³°¤Î LDAP ¥¯¥é¥¤¥¢¥ó¥È¤ÎÍøÍÑÊýË¡¤ò¼«Ê¬¤¬»×¤¤ÉÕ¤­¤Þ¤»¤ó¡£¤Î¤Ç¡¢»×¤¤ÉÕ¤¯¤Þ¤Çº£¸å¤ÎͽÄê¤Ï̤Äê¡£¡£¡£