<%@page import="javax.naming.NamingEnumeration"%>
<%@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.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" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h3>Rubrica:</h3>
<!-- SEARCH ENTRY -->
<h3>Search Entry:</h3>
<form method="post">
Search Entry: <input type="text" name="search""><br>
<input type="submit" value="search">
</form>
<br><br>
<%
//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");
DirContext ctx = new InitialDirContext(env);
String searchName = (String)request.getParameter("search");
try{
request.getParameter("search");
Attributes attrs = ctx.getAttributes("cn = " + searchName);
out.println(attrs.get("cn").get());
out.println(" telephone number: "+attrs.get("telephonenumber").get());
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br>------------------------------------</br>
<!-- ADD ENTRY -->
<h3>Add Entry:</h3>
<form method="post">
Add Entry:<br><br>
Full Name: <input type="text" name="addcn"><br>
Surname: <input type="text" name="surname"><br>
PhoneNumber: <input type="text" name="pn"><br>
<input type="submit" value="addEntry">
</form><br><br>
<%
String addcn = (String)request.getParameter("addcn");
String surname = (String)request.getParameter("surname");
String pn = (String)request.getParameter("pn");
try{
//Create new set of attributes
BasicAttributes attrs1 = new BasicAttributes();
//(The item is a person)
Attribute classes = new BasicAttribute("objectClass");
// classes.add("top");
classes.add("person");
// classes.add("organizationalPerson");
// Add the objectClass attribute to the attribute set
attrs1.put(classes);
// Store the other attributes in the attribute set
attrs1.put("sn", surname);
attrs1.put("telephonenumber", pn);
// Add the new entry to the directory server
ctx.createSubcontext("ldap://localhost:1389/cn="+addcn+",o=Rubrica,dc=example,dc=com", attrs1);
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br>------------------------------------</br>
<!-- REMOVE ENTRY -->
<h3>Remove Entry:</h3>
<form method="post">
Insert Entry To Remove: <input type="text" name="delUser""><br>
<input type="submit" value="Remove">
</form><br><br>
<%
String delUser = (String)request.getParameter("delUser");
try
{
ctx.destroySubcontext("cn="+delUser);
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<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...
-
My intent is to configure SSO on Keycloak and Liferay. I have createad a docker-compose environment with Keycloak: #####################...
-
Precondizione: La precondizione di un metodo e' una condizione che deve essere verificata prima che quel metodo sia invocato. Le preco...
Nessun commento:
Posta un commento