Hi Can someone help me with writing to LDAP. The following code is the JAVA sample which needs to be converted to ASP. This JAVA code makes connection to the LDAP server using userid and password and section two writes the information to LDAP(Via LAD). I need the same function to be written in ASP. Please help
URL url = new URL(" + ldapProps.getProperty("host") + ":" + ldapProps.getProperty("port") + "/CON?app
=ApplicationName&uid=" + ldapProps.getProperty("sess_user") + "&pwd=" + ldapProps.getProperty("sess_pwd") + "&rtype=nvpairs");
StringBuffer sb = new StringBuffer();
InputStreamReader isr = new InputStreamReader(url.openStream());
char[] data = new char[4096];
int n = 0;
while((n=isr.read(data, 0, 4096)) != -1)
sb.append(data, 0, n);
isr.close();
String xmlInput = "<?xml version=\"1.0\"?>\n" + sb.toString();
DOMParser parser = (DOMParser)Class.forName("org.apache.xerces.parsers.DOMParser").newInstance();
parser.parse(new InputSource(new StringReader(xmlInput)));
Document doc = parser.getDocument();
if(doc.hasChildNodes()){
Node top = doc.getFirstChild();
String name = top.getNodeName();
if(name.equals("CON")){
boolean found = false;
if(top.hasChildNodes()){
for(Node ch = top.getFirstChild();ch != null; ch = ch.getNextSibling()){
if(ch.getNodeName().equals("sess")){
sessionId = ch.getFirstChild().getNodeValue();
found = true;
}
if(ch.getNodeName().equals("reason")){
if(ch.getFirstChild().getNodeValue().equals("user already in session")
){
found = true;
expireSession();
}
}
}
}
if(!found)
throw new Exception("Session ID could not be obtained:\n" + xmlInput);
}
}
}
Section 2
Adding User to the group in LDAP
{
String usr = "/AUG?app=%sess%&grp=" + gname + "&uid=" + userid + "&pwd=”+password+”&rtype=nvpairs";
Object[] st = WeisXMLParser.TagIdValues(usr, "status");
for(int i=0; i<st.length; i++){
System.out.println((new java.util.Date()).toString() + " " + (String)st);
}
if(((String)st[0]).equals("OK")){
System.out.println((new java.util.Date()).toString() + " successful to get the result ");
return true;
}else{
Object[] reason = WeisXMLParser.TagIdValues(usr, "reason");
description = (String) reason[0];
return false;
}
}catch(Exception e){
e.printStackTrace();
return false;
}
URL url = new URL(" + ldapProps.getProperty("host") + ":" + ldapProps.getProperty("port") + "/CON?app
=ApplicationName&uid=" + ldapProps.getProperty("sess_user") + "&pwd=" + ldapProps.getProperty("sess_pwd") + "&rtype=nvpairs");
StringBuffer sb = new StringBuffer();
InputStreamReader isr = new InputStreamReader(url.openStream());
char[] data = new char[4096];
int n = 0;
while((n=isr.read(data, 0, 4096)) != -1)
sb.append(data, 0, n);
isr.close();
String xmlInput = "<?xml version=\"1.0\"?>\n" + sb.toString();
DOMParser parser = (DOMParser)Class.forName("org.apache.xerces.parsers.DOMParser").newInstance();
parser.parse(new InputSource(new StringReader(xmlInput)));
Document doc = parser.getDocument();
if(doc.hasChildNodes()){
Node top = doc.getFirstChild();
String name = top.getNodeName();
if(name.equals("CON")){
boolean found = false;
if(top.hasChildNodes()){
for(Node ch = top.getFirstChild();ch != null; ch = ch.getNextSibling()){
if(ch.getNodeName().equals("sess")){
sessionId = ch.getFirstChild().getNodeValue();
found = true;
}
if(ch.getNodeName().equals("reason")){
if(ch.getFirstChild().getNodeValue().equals("user already in session")
){
found = true;
expireSession();
}
}
}
}
if(!found)
throw new Exception("Session ID could not be obtained:\n" + xmlInput);
}
}
}
Section 2
Adding User to the group in LDAP
{
String usr = "/AUG?app=%sess%&grp=" + gname + "&uid=" + userid + "&pwd=”+password+”&rtype=nvpairs";
Object[] st = WeisXMLParser.TagIdValues(usr, "status");
for(int i=0; i<st.length; i++){
System.out.println((new java.util.Date()).toString() + " " + (String)st);
}
if(((String)st[0]).equals("OK")){
System.out.println((new java.util.Date()).toString() + " successful to get the result ");
return true;
}else{
Object[] reason = WeisXMLParser.TagIdValues(usr, "reason");
description = (String) reason[0];
return false;
}
}catch(Exception e){
e.printStackTrace();
return false;
}