Solved

<jsp:setProperty Problem

Posted on 2003-11-20
9
592 Views
Last Modified: 2010-04-01
I'm really stumped on using setProperty for jsp......

This is my initial login page:

<HTML>
<BODY>
<h2>Login</h2>
<FORM METHOD=POST ACTION="Authentication2.jsp">
ID: <INPUT TYPE=TEXT NAME=uid SIZE=20><BR>
Password: <INPUT TYPE=PASSWORD NAME=pw SIZE=20><BR>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
----------------_----------------_----------------_----------------

<jsp:useBean id="auth" class="com.wrox.auth.Authenticate" scope="session"/>
<jsp:setProperty name="auth" property="*"/>
<HTML>
<BODY>
<%
if(auth.checkEntry())
{
     %>
     <A HREF="Logged.jsp">Continue</A>
     <%
}
else
{
     %>
     <A HREF="LoginPage.jsp">Invalid! Continue</A>
     <%
}
%>
</BODY>
</HTML>

----------------_----------------_----------------_--------------------------------_----------------_----------------_----------------


I checked my logs and basically it says that my username and password variables were never initialized....
here's my java code for Authenticate


----------------_----------------_----------------_--------------------------------_----------------_----------------_----------------


package com.wrox.auth;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;


public class Authenticate
{
     String uid;
     String pw;
     String url = "ldap://127.0.0.1:389/";
     String BDN = "o=rcms2";

     public void setUid(String value)
     {
          uid = "uid="+value+", "+BDN;
     }

     public void setPw(String value)
     {
          pw = value;    
     }

     public String getUid()
     {
          return uid;
     }


     public boolean checkEntry()
     {
          Hashtable env = new Hashtable(11);
          env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, url);

          //Authenticate
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          System.out.println("TEST: "+uid);
          env.put(Context.SECURITY_PRINCIPAL, uid);
          env.put(Context.SECURITY_CREDENTIALS, pw);
          try
          {
                   // Create initial context
                   DirContext ctx = new InitialDirContext(env);
                   ctx.close();
          }
          catch (AuthenticationException e1)
          {
               //System.out.println("Invalid Password.");
               return false;
          }
          catch (NamingException e)
          {
                   e.printStackTrace();
          }
          return true;
     }
}



Any pointers? Thanks Sorry my points offering is so low, that's all i have =(.  I jsut know that my problem is that my two variables in my java class (uid and pw).  If i am doing it incorrectly, can someone please show me how to do it properlY? Thanks.
0
Comment
Question by:lapchern
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:jarasa
ID: 9786184
Hi Lapchern.

I'm not really good at Beans but shouldn't you need a constructor on your Bean which would set the value of uid & pw. Well if that was a normal class you should initialize those variable on a constructor like this

public void Authenticate (String myUid, String myPw)
     {
          uid = myUid;
          pw = myPw;
     }

and you should call that constructor with the form, but as I told you I'm not common with Beans so I can assure you that's your problem.

Maybe it will work if you initialize uid & pw at the declaration, like this:

String uid = "";
String pw = "";



Hope it helps anyway.

Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9786203
>>and you should call that constructor with the form, but as I told you I'm not common with Beans so I can assure you that's your problem.

Can't assure you that's your problem, sorry.

Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9786363
Hi again.
I've been reading, ha, yes reading, incredible, I think you must have a constructor but without parameters on your bean and initilize there all the fields of your bean, something like this.

public void Authenticate ()
     {
          uid = null;
          pw = null;
     }

I think That may be the problem.

regards
Javier
0
 

Author Comment

by:lapchern
ID: 9786644
Hi jarasa, I really appreciate your effort and thanks.

I'm very new at this, but according to this tutorial I've been following at http://www.jsptut.com/Forms.jsp

you do not need a constructor. I verified this by testing the provided sample code myself and it ran perfectly fine. i'm really dumbfounded by my problem... i'm trying to pretty much follow the example of this site...but my variables aren't initialized properly via "set" methods as the site says.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:jarasa
ID: 9786844
Hi again.

I have tryed the code you have here without the LDAP part I just put this:

package com.wrox.auth;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;


public class Authenticate
{
     String uid;
     String pw;
     String url = "ldap://127.0.0.1:389/";
     String BDN = "o=rcms2";

     public void setUid(String value)
     {
          uid = "uid="+value+", "+BDN;
     }

     public void setPw(String value)
     {
          pw = value;    
     }

     public String getUid()
     {
          return uid;
     }


     public boolean checkEntry()
     {
           
      System.out.println(uid);
      System.out.println(pw);
     
      if(user.equals("uid=Javier, o=rcms2"))
                  return true;
      else
                  return false;
                  
/*                  
          Hashtable env = new Hashtable(11);
          env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, url);

          //Authenticate
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          System.out.println("TEST: "+uid);
          env.put(Context.SECURITY_PRINCIPAL, uid);
          env.put(Context.SECURITY_CREDENTIALS, pw);
          try
          {
                   // Create initial context
                   DirContext ctx = new InitialDirContext(env);
                   ctx.close();
          }
          catch (AuthenticationException e1)
          {
               //System.out.println("Invalid Password.");
               return false;
          }
          catch (NamingException e)
          {
                   e.printStackTrace();
          }
          return true;
          */
     }
}


And works fine with Tomcat 4. maybe you should see if you are doing well the LDAP check.

Javier
0
 

Accepted Solution

by:
webhsu earned 25 total points
ID: 9787929
I dont' know, but don't you need a getPw() method also?

To agree with someones' comments above, I've written a lot of these forms and a constructor is not necessary.
0
 

Author Comment

by:lapchern
ID: 9791102
Damn thank yoU!!!!!!!
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9795539
Just Curious.
did you solve your problem, putting the getPw() ??
Javier.
0
 

Author Comment

by:lapchern
ID: 9802008
yeah
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSP Popup page 2 106
java.util.concurrent.locks in java 3 185
mask rule in struts validation.xml 5 85
countXY challenge 28 144
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Facing problems with you memory card? Cannot access your memory card? All stored data, images, videos are lost? If these are your questions...than this small article might help you out in retrieving your lost or inaccessible data.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now