Solved

<jsp:setProperty Problem

Posted on 2003-11-20
9
591 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

21 Experts available now in Live!

Get 1:1 Help Now