index.jsp


Dosyayı İndir
<%-- 
    Document   : index
    Created on : Feb 26, 2009, 1:05:55 PM
    Author     : onder
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="javax.naming.*"%>
<%@page import="javax.naming.directory.*"%>
<%@page import="javax.naming.ldap.*"%>
<%@page import="java.util.*"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
  </head>
  <body>
    <h2>JNDI LDAP Test!</h2>
    <%

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=godoro,dc=com");


    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
    env.put(Context.SECURITY_CREDENTIALS, "godoro");
    DirContext context = new InitialDirContext(env);
    %>
    <h1>Liste</h1>
    <%
    String dir="ou=developer,o=swdev";
    NamingEnumeration<NameClassPair> results = context.list(dir);

    while (results.hasMore()) {
      NameClassPair pair = results.next();
    %>
    Name : <%=pair.getName()%><br/>
    Attributes <br/>
      <%  
        String name=pair.getName()+",ou=developer,o=swdev";
          Attributes attributes = context.getAttributes(name);
          NamingEnumeration a = attributes.getAll();
          while (a.hasMore()) {
            Attribute attribute = (Attribute) a.next();
            %>
            Id : <%=attribute.getID()%>
            <%
              NamingEnumeration v = attribute.getAll();
              while (v.hasMore()) {
                  Object value = v.next();
                  %><%=value%><%
               }
              %><br/><%
            }
          %>
    <%}%>
    
  <h1>Arama</h1>
    <%
    String filter="sn=Teker";
    SearchControls controls = new SearchControls();

    NamingEnumeration<SearchResult> searchResults = context.search(dir,filter,controls);

    while (searchResults.hasMore()) {
      SearchResult searchResult = searchResults.next();
    %>
    Name : <%=searchResult.getName()%><br/>
    Attributes <br/>
      <%  
          Attributes attributes = searchResult.getAttributes();
          NamingEnumeration a = attributes.getAll();
          while (a.hasMore()) {
            Attribute attribute = (Attribute) a.next();
            %>
            Id : <%=attribute.getID()%>
            <%
              NamingEnumeration v = attribute.getAll();
              while (v.hasMore()) {
                  Object value = v.next();
                  %><%=value%><%
               }
              %><br/><%
            }
          %>
    <%}%>
  </body>
</html>

				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir