venerdì 12 giugno 2015
List All Entries in a LDAP Directory with JSP/JNDI
<%@page import="java.util.*" %>
<%@page import="javax.naming.ldap.*" %>
<%@page import="javax.naming.directory.*"%>
<%@page import="javax.naming.directory.InitialDirContext"%>
<%@page import="javax.naming.directory.DirContext"%>
<%@page import="javax.naming.Context" %>
<%@page import="javax.naming.InitialContext" %>
<%@page import="javax.naming.NamingException" %>
<%@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="java.util.*" %>
<%@page import="javax.naming.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h3>Rubrica:</h3>
<%
//CREATING AN INITIAL CONTEXT for search function:
//context = objects whose state is a set of bindings (=ldap entries), that have distinct atomic names.
//The Hashtable class represents the environments properties parameters
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:1389/o=Rubrica,dc=example,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS, "secret");
//create initial context
DirContext ctx = new InitialDirContext(env);
try {
//get listing of context
NamingEnumeration list = ctx.list(""); //class Context.list: contains object name + class name
// NamingEnumeration bindings = ctx.listBindings(""); //class Context.listbindings: contains object name + class name + object
while (list.hasMore()) {
NameClassPair ncPair = (NameClassPair) list.next(); //ClassPair= name + class name
out.print("<b>" + ncPair.getName() + "</b> </br>");
Attributes attrs = ctx.getAttributes(ncPair.getName());
for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {
Attribute attr = (Attribute) ae.next();
out.println(attr.getID());
for (NamingEnumeration e = attr.getAll(); e.hasMore();) {
out.println(": " + e.next() + "<br>");
}
}
out.println("------------------------------------------------------<br><br>");
// Binding bd = (Binding)bindings.next();
// out.println(bd.getName() + ":</br></br> " + bd.getObject());
}
ctx.close();
} catch (NamingException e) {
out.println("List failed: " + e);
}
%>
<br><br><br>
</body>
</html>
Iscriviti a:
Commenti sul post (Atom)
How to deploy Podman images to OpenShift Container Platform (CRC on localhost)
I have a microservice on localhost and I want to deploy its Podman image on OCP, which I am running using CRC on localhost. 1. Get the...
-
Precondizione: La precondizione di un metodo e' una condizione che deve essere verificata prima che quel metodo sia invocato. Le preco...
-
My intent is to configure SSO on Keycloak and Liferay. I have createad a docker-compose environment with Keycloak: #####################...
Nessun commento:
Posta un commento