<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FJNDI_LDAP%2FAttributes</id>
		<title>Java/JNDI LDAP/Attributes - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FJNDI_LDAP%2FAttributes"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/JNDI_LDAP/Attributes&amp;action=history"/>
		<updated>2026-04-21T20:36:53Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/JNDI_LDAP/Attributes&amp;diff=6853&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/JNDI_LDAP/Attributes&amp;diff=6853&amp;oldid=prev"/>
				<updated>2010-06-01T06:33:11Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:33, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/JNDI_LDAP/Attributes&amp;diff=6852&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/JNDI_LDAP/Attributes&amp;diff=6852&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:44Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== how to discover a server&amp;quot;s supported SASL mechanisms ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import javax.naming.NamingException;&lt;br /&gt;
import javax.naming.directory.Attributes;&lt;br /&gt;
import javax.naming.directory.DirContext;&lt;br /&gt;
import javax.naming.directory.InitialDirContext;&lt;br /&gt;
/**&lt;br /&gt;
 * Demonstrates how to discover a server&amp;quot;s supported SASL mechanisms.&lt;br /&gt;
 * &lt;br /&gt;
 * usage: java ServerSasl&lt;br /&gt;
 */&lt;br /&gt;
class ServerSasl {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    try {&lt;br /&gt;
      // Create initial context&lt;br /&gt;
      DirContext ctx = new InitialDirContext();&lt;br /&gt;
      // Read supportedSASLMechanisms from root DSE&lt;br /&gt;
      Attributes attrs = ctx.getAttributes(&amp;quot;ldap://localhost:389&amp;quot;,&lt;br /&gt;
          new String[] { &amp;quot;supportedSASLMechanisms&amp;quot; });&lt;br /&gt;
      System.out.println(attrs);&lt;br /&gt;
      // Close the context when we&amp;quot;re done&lt;br /&gt;
      ctx.close();&lt;br /&gt;
    } catch (NamingException e) {&lt;br /&gt;
      e.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== how to make modifications to an object&amp;quot;s attributes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.Hashtable;&lt;br /&gt;
import javax.naming.Context;&lt;br /&gt;
import javax.naming.NamingEnumeration;&lt;br /&gt;
import javax.naming.NamingException;&lt;br /&gt;
import javax.naming.directory.Attribute;&lt;br /&gt;
import javax.naming.directory.Attributes;&lt;br /&gt;
import javax.naming.directory.BasicAttribute;&lt;br /&gt;
import javax.naming.directory.DirContext;&lt;br /&gt;
import javax.naming.directory.InitialDirContext;&lt;br /&gt;
import javax.naming.directory.ModificationItem;&lt;br /&gt;
/**&lt;br /&gt;
 * Demonstrates how to make modifications to an object&amp;quot;s attributes. It remove&lt;br /&gt;
 * an attribute, adds an attribute value, and replaces an attribute value. After&lt;br /&gt;
 * making the modifications, it replaces the object&amp;quot;s attributes with its&lt;br /&gt;
 * original attributes.&lt;br /&gt;
 * &lt;br /&gt;
 * usage: java ModAttrs&lt;br /&gt;
 */&lt;br /&gt;
class ModAttrs {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    // Set up the environment for creating the initial context&lt;br /&gt;
    Hashtable&amp;lt;String, Object&amp;gt; env = new Hashtable&amp;lt;String, Object&amp;gt;(11);&lt;br /&gt;
    env&lt;br /&gt;
        .put(Context.INITIAL_CONTEXT_FACTORY,&lt;br /&gt;
            &amp;quot;com.sun.jndi.ldap.LdapCtxFactory&amp;quot;);&lt;br /&gt;
    env.put(Context.PROVIDER_URL, &amp;quot;ldap://localhost:389/o=JNDITutorial&amp;quot;);&lt;br /&gt;
    try {&lt;br /&gt;
      // Create the initial context&lt;br /&gt;
      DirContext ctx = new InitialDirContext(env);&lt;br /&gt;
      String name = &amp;quot;cn=Ted Geisel, ou=People&amp;quot;;&lt;br /&gt;
      // Save original attributes&lt;br /&gt;
      Attributes orig = ctx.getAttributes(name, new String[] { &amp;quot;mail&amp;quot;,&lt;br /&gt;
          &amp;quot;telephonenumber&amp;quot;, &amp;quot;jpegphoto&amp;quot; });&lt;br /&gt;
      // Specify the changes to make&lt;br /&gt;
      ModificationItem[] mods = new ModificationItem[3];&lt;br /&gt;
      // Replace the &amp;quot;mail&amp;quot; attribute with a new value&lt;br /&gt;
      mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,&lt;br /&gt;
          new BasicAttribute(&amp;quot;mail&amp;quot;, &amp;quot;geisel@wizards.ru&amp;quot;));&lt;br /&gt;
      // Add additional value to &amp;quot;telephonenumber&amp;quot;&lt;br /&gt;
      mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE,&lt;br /&gt;
          new BasicAttribute(&amp;quot;telephonenumber&amp;quot;, &amp;quot;+1 555 555 5555&amp;quot;));&lt;br /&gt;
      // Remove the &amp;quot;jpegphoto&amp;quot; attribute&lt;br /&gt;
      mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE,&lt;br /&gt;
          new BasicAttribute(&amp;quot;jpegphoto&amp;quot;));&lt;br /&gt;
      // Perform the requested modifications on the named object&lt;br /&gt;
      ctx.modifyAttributes(name, mods);&lt;br /&gt;
      // Check attributes&lt;br /&gt;
      System.out.println(&amp;quot;**** new attributes *****&amp;quot;);&lt;br /&gt;
      printAttrs(ctx.getAttributes(name));&lt;br /&gt;
      // Revert changes&lt;br /&gt;
      ctx.modifyAttributes(name, DirContext.REPLACE_ATTRIBUTE, orig);&lt;br /&gt;
      // Check that the attributes got restored&lt;br /&gt;
      System.out.println(&amp;quot;**** reverted to original attributes *****&amp;quot;);&lt;br /&gt;
      printAttrs(ctx.getAttributes(name));&lt;br /&gt;
      // Close the context when we&amp;quot;re done&lt;br /&gt;
      ctx.close();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      e.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  static void printAttrs(Attributes attrs) {&lt;br /&gt;
    if (attrs == null) {&lt;br /&gt;
      System.out.println(&amp;quot;No attributes&amp;quot;);&lt;br /&gt;
    } else {&lt;br /&gt;
      /* Print each attribute */&lt;br /&gt;
      try {&lt;br /&gt;
        for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {&lt;br /&gt;
          Attribute attr = (Attribute) ae.next();&lt;br /&gt;
          System.out.println(&amp;quot;attribute: &amp;quot; + attr.getID());&lt;br /&gt;
          /* print each value */&lt;br /&gt;
          for (NamingEnumeration e = attr.getAll(); e.hasMore(); System.out&lt;br /&gt;
              .println(&amp;quot;value: &amp;quot; + e.next()))&lt;br /&gt;
            ;&lt;br /&gt;
        }&lt;br /&gt;
      } catch (NamingException e) {&lt;br /&gt;
        e.printStackTrace();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== how to retrieve all attributes of a named object ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.Hashtable;&lt;br /&gt;
import javax.naming.Context;&lt;br /&gt;
import javax.naming.NamingEnumeration;&lt;br /&gt;
import javax.naming.NamingException;&lt;br /&gt;
import javax.naming.directory.Attribute;&lt;br /&gt;
import javax.naming.directory.Attributes;&lt;br /&gt;
import javax.naming.directory.DirContext;&lt;br /&gt;
import javax.naming.directory.InitialDirContext;&lt;br /&gt;
/**&lt;br /&gt;
 * Demonstrates how to retrieve all attributes of a named object.&lt;br /&gt;
 * &lt;br /&gt;
 * usage: java GetAllAttrs&lt;br /&gt;
 */&lt;br /&gt;
class GetAllAttrs {&lt;br /&gt;
  static void printAttrs(Attributes attrs) {&lt;br /&gt;
    if (attrs == null) {&lt;br /&gt;
      System.out.println(&amp;quot;No attributes&amp;quot;);&lt;br /&gt;
    } else {&lt;br /&gt;
      /* Print each attribute */&lt;br /&gt;
      try {&lt;br /&gt;
        for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {&lt;br /&gt;
          Attribute attr = (Attribute) ae.next();&lt;br /&gt;
          System.out.println(&amp;quot;attribute: &amp;quot; + attr.getID());&lt;br /&gt;
          /* print each value */&lt;br /&gt;
          for (NamingEnumeration e = attr.getAll(); e.hasMore(); System.out&lt;br /&gt;
              .println(&amp;quot;value: &amp;quot; + e.next()))&lt;br /&gt;
            ;&lt;br /&gt;
        }&lt;br /&gt;
      } catch (NamingException e) {&lt;br /&gt;
        e.printStackTrace();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    // Set up the environment for creating the initial context&lt;br /&gt;
    Hashtable&amp;lt;String, Object&amp;gt; env = new Hashtable&amp;lt;String, Object&amp;gt;(11);&lt;br /&gt;
    env&lt;br /&gt;
        .put(Context.INITIAL_CONTEXT_FACTORY,&lt;br /&gt;
            &amp;quot;com.sun.jndi.ldap.LdapCtxFactory&amp;quot;);&lt;br /&gt;
    env.put(Context.PROVIDER_URL, &amp;quot;ldap://localhost:389/o=JNDITutorial&amp;quot;);&lt;br /&gt;
    try {&lt;br /&gt;
      // Create the initial context&lt;br /&gt;
      DirContext ctx = new InitialDirContext(env);&lt;br /&gt;
      // Get all the attributes of named object&lt;br /&gt;
      Attributes answer = ctx.getAttributes(&amp;quot;cn=Ted Geisel, ou=People&amp;quot;);&lt;br /&gt;
      // Print the answer&lt;br /&gt;
      printAttrs(answer);&lt;br /&gt;
      // Close the context when we&amp;quot;re done&lt;br /&gt;
      ctx.close();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      e.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== how to retrieve selected attributes of a named object ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.Hashtable;&lt;br /&gt;
import javax.naming.Context;&lt;br /&gt;
import javax.naming.NamingEnumeration;&lt;br /&gt;
import javax.naming.NamingException;&lt;br /&gt;
import javax.naming.directory.Attribute;&lt;br /&gt;
import javax.naming.directory.Attributes;&lt;br /&gt;
import javax.naming.directory.DirContext;&lt;br /&gt;
import javax.naming.directory.InitialDirContext;&lt;br /&gt;
/**&lt;br /&gt;
 * Demonstrates how to retrieve selected attributes of a named object.&lt;br /&gt;
 * &lt;br /&gt;
 * usage: java GetAttrs&lt;br /&gt;
 */&lt;br /&gt;
class GetAttrs {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    // Set up the environment for creating the initial context&lt;br /&gt;
    Hashtable&amp;lt;String, Object&amp;gt; env = new Hashtable&amp;lt;String, Object&amp;gt;(11);&lt;br /&gt;
    env&lt;br /&gt;
        .put(Context.INITIAL_CONTEXT_FACTORY,&lt;br /&gt;
            &amp;quot;com.sun.jndi.ldap.LdapCtxFactory&amp;quot;);&lt;br /&gt;
    env.put(Context.PROVIDER_URL, &amp;quot;ldap://localhost:389/o=JNDITutorial&amp;quot;);&lt;br /&gt;
    try {&lt;br /&gt;
      // Create initial context&lt;br /&gt;
      DirContext ctx = new InitialDirContext(env);&lt;br /&gt;
      // Specify the ids of the attributes to return&lt;br /&gt;
      String[] attrIDs = { &amp;quot;sn&amp;quot;, &amp;quot;telephonenumber&amp;quot;, &amp;quot;golfhandicap&amp;quot;, &amp;quot;mail&amp;quot; };&lt;br /&gt;
      // Get the attributes requested&lt;br /&gt;
      Attributes answer = ctx&lt;br /&gt;
          .getAttributes(&amp;quot;cn=Ted Geisel, ou=People&amp;quot;, attrIDs);&lt;br /&gt;
      // Print the answer&lt;br /&gt;
      printAttrs(answer);&lt;br /&gt;
      // Close the context when we&amp;quot;re done&lt;br /&gt;
      ctx.close();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      e.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  static void printAttrs(Attributes attrs) {&lt;br /&gt;
    if (attrs == null) {&lt;br /&gt;
      System.out.println(&amp;quot;No attributes&amp;quot;);&lt;br /&gt;
    } else {&lt;br /&gt;
      /* Print each attribute */&lt;br /&gt;
      try {&lt;br /&gt;
        for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {&lt;br /&gt;
          Attribute attr = (Attribute) ae.next();&lt;br /&gt;
          System.out.println(&amp;quot;attribute: &amp;quot; + attr.getID());&lt;br /&gt;
          /* print each value */&lt;br /&gt;
          for (NamingEnumeration e = attr.getAll(); e.hasMore(); System.out&lt;br /&gt;
              .println(&amp;quot;value: &amp;quot; + e.next()))&lt;br /&gt;
            ;&lt;br /&gt;
        }&lt;br /&gt;
      } catch (NamingException e) {&lt;br /&gt;
        e.printStackTrace();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>