Help coderanch get a
new server
by contributing to the fundraiser

Yogesh Deshmukh

Greenhorn
+ Follow
since Dec 26, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Yogesh Deshmukh

I would like to know the compatibility issues of Weblogic on the Linux platform.
Yogi D
21 years ago
Can we use Collection instead of arrays?
23 years ago
I wanted to know whether Swing functions the same with JNDI as does AWT with JNDI?
23 years ago
Hello Bhupinder,
Thanks for the correction.
Even then, the same error as described in my earlier posting continues, with neither of the compilers giving me any error.
The JNDI-LDAP code still runs independently and gives the requisite output, when used with directory-specific entries(specific to my directory server i.e in place of strUserName, I have an entry, say "YDeshmukh" and in place of strPassword, I have an entry, say, "ydeshmukh" in the DN 'ou=People,o=yogesh.com').
But it doesn't take the inputs supplied by the JSP (i.e. strUserName and strPassword)
On the other hand, JSP gives erroneous output - executing both IF and ELSE blocks.
Yogesh
23 years ago
Hello Sandeep,
When I press Submit from the HTML page, I get both the outputs i.e. of the IF block as well as the ELSE block.
Also, the validaiton is not taking place.
I added the line you had posted. But with the same result.
Yogesh
if(bRetVal)
{
String strUser = request.getParameter("username");
...
...
out.println("<a href=\"javascript:bestsellers()\"> Best Sellers </a>");
}
else
{
out.println("<p align=center>");
...
...
out.println("<p>");
}
23 years ago
Hello Bhupinder, Sandeep
Following is the code of the JSP:
Please let me know if there are any errors
Thanks
<%@ page import="java.sql.*" %>
<%@ page session="true" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="shoppingcart.*" %>

<HTML>
<HEAD>
<TITLE>
Validating.............
</TITLE>
</HEAD>
<BODY bgcolor=Thistle >
<%
String strUserName = request.getParameter("username");
String strPassword = request.getParameter("password");
JNDISearch call = new JNDISearch();
boolean bRetVal = call.method1(strUserName,strPassword);
if(bRetVal)
{
String strUser = request.getParameter("username");
out.println("<h2>Hello!!!\" + strUser + \"</h2>");
out.println("<h4> What do u want to do??? </h4>");
out.println("<a href=\"getdata.jsp\"> View already selected items? </a><br><br>");
out.println("Choose new items from the following categories <br>");
out.println("<a href=\"javascript:autobio()\"> Autobiographies </a> <br>");
out.println("<a href=\"javascript:charles()\"> Charles Dickens </a> <br>");
out.println("<a href=\"javascript:bestsellers()\"> Best Sellers </a>");
}
else
{
out.println("<p align=center>");
out.println("<b> Invalid User!!! <br>");
out.println("Check ur UserName and Password </b><br><br>");
out.println("<a href=\"../shoppingcart/login.htm\"> Back </a>");
out.println("<p>");
}
%>

<form name=session1 method=get action="charles.jsp">
<input type=hidden name=char id=char value= <%= request.getParameter("username") %> >
</form>
<form name=session2 method=get action="bestsellers.jsp">
<input type=hidden name=char id=char value= <%= request.getParameter("username") %> >
</form>
<form name=session3 method=get action="autobio.jsp">
<input type=hidden name=char id=char value= <%= request.getParameter("username") %> >
</form>
<script>
function charles()
{
document.session1.submit();
//alert(document.session.char.value);
}
function bestsellers()
{
document.session2.submit();
//alert(document.session.char.value);
}
function autobio()
{
document.session3.submit();
//alert(document.session.char.value);
}
</script>

</BODY>
</html>
23 years ago
Here the variables strUsername and strPassword are entered on the login html page which are passed to JSP and then to JNDI-LDAP code given below.
I replaced the above two variables with a specific information which I had created in the directory of the Server , the code then works.
import java.util.Hashtable;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.naming.directory.*;
public class JNDISearch
{
// initial context implementation
public static final String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
public static final String MY_HOST = "ldap://wnctg53.yogesh.com:389";
public static String MY_SEARCHBASE = "ou=People,o=yogesh.com";
//specify which attributes we are looking for
public boolean String MY_ATTRS[] = {"uid"};
/*public static void main(String args[])
{
JNDISearch obj = new JNDISearch();
obj.method1();
}*/
public String method1(strUserName, strPassword)
{
boolean flag = true;
String MGR_PW = strPassword;
String MGR_DN = "uid="+strUserName+",ou=People,o=yogesh.com";
String MY_FILTER = "(uid="+strUserName+")";
try
{
//Hashtable for environmental information
Hashtable env = new Hashtable();
//Specify which class to use for our JNDI provider
env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
// Specify host and port to use for directory service
env.put(Context.PROVIDER_URL, MY_HOST);
// Setting the securit level
env.put(Context.SECURITY_AUTHENTICATION, "simple");
// Verifying the username
env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
// Verifying the password
env.put(Context.SECURITY_CREDENTIALS, MGR_PW);
//return flag;
//System.out.println("Hi, you are in method1");
//now step through the search results

//Get a reference to a directory context
DirContext ctx = new InitialDirContext(env);
//specify the scope of the search
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
//perform the actual search
//we give it a searchbase, a filter and constraints
//containing the scope of the search
NamingEnumeration results =
ctx.search(MY_SEARCHBASE, MY_FILTER,constraints);
//now step through the search results
while (results != null && results.hasMore())
{
SearchResult sr = (SearchResult) results.next();
String dn = sr.getName() + "," + MY_SEARCHBASE;
//System.out.println("Distinguished Name is "+dn);
Attributes ar = ctx.getAttributes(dn, MY_ATTRS);
if (ar == null)
{
flag = false;
}
else {
for (int i =0;i<MY_ATTRS.length;i++)
{
Attribute attr = ar.get(MY_ATTRS[i]);
String check = (String)attr.get();
if ( check.equalsIgnoreCase(strUserName))
{
flag = true;
}
else
{
flag = false;
}
}
}
}

}
catch(Exception e)
{
e.printStackTrace();
}
//System.out.println("**** The flag : " + flag);
return flag;
}
}
23 years ago
I want to authenticate a user from the login page using a JSP-JNDI-LDAP combination.
i am using the iPlanet Directory server which comes with the iPlanet App server 6.0 Evaluation version.
The JNDI-LDAP code gives me the authentication but hen combined with JSP, I am not able to get any output.
What do I do?
Please help.
Thanks
Yogesh
23 years ago
How does the DOM parser vary in function from SAX parser?
What is the scope of J2ME in today's scenario and in the future?
How is J2ME different from the conventional java programming?
23 years ago
What is the scope of J2ME in today's scenario and in the future?
How is J2ME different from the conventional java programming?
23 years ago
How do we access the XSLT to give HTML from XML?
Can we use XML instead of HTML while using JSP?
23 years ago
How extensively is JINI being used in the enterprises today?
Is it related to EJB in any manner?
------------------
23 years ago
I am basically not able to understand the significance of patterns.
Please explain
------------------