aspose file tools*
The moose likes Servlets and the fly likes Unable to write filter that passes autheticated user data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to write filter that passes autheticated user data" Watch "Unable to write filter that passes autheticated user data" New topic
Author

Unable to write filter that passes autheticated user data

Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 169

I'm trying to write a filter which gets the currently authenticated user data and uses it in the application. For now I simply want to pass the authenticated user data to System.out.println which just displays the username of the authenticated user. I'm writing the following classes:



I get confused trying to write the LoginMatcher which should search through the database and match the remoteUser to the right record on the database, using only the username :



I'm not sure if the argument of the find method should be passed as a String or LoginFilter object or Member object. No matter which one of these types I set remoteUser in in the LoginMatcher class I get:

Member member = memsearch.find(remoteUser);
required: Member
found: String
reason: actual argument String cannot be converted to Member by method invocation conversion

Would really appreciate any advice on what I'm doing wrong and how to correctly write the LoginMatcher class. Thanks!
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2505
    
    8

Looking in the find method in LoginMatcher, why is it returning find(remoteUser) again when now the remoteUser is an Object? Is this find another overloaded method?

Also the provided find method doesn't return a Member but a LoginFilter. But in your filter class it's returning a Member.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 169

Dear Tsang,

Thanks for your response.

Looking in the find method in LoginMatcher, why is it returning find(remoteUser) again when now the remoteUser is an Object? Is this find another overloaded method?



I don't think find() is an overloaded method, since it is intended to return a remoteUser which is of object type Member. I'm not even sure it overrides an existing find method (looking at the APIs of the imports).


Also the provided find method doesn't return a Member but a LoginFilter. But in your filter class it's returning a Member


Yes, it needs to return a Member as mentioned above. So, I would like to know how to correctly write the LoginMatcher class so that it iterates through the DB records, provides a match between the remoreUser String and the member object in the database and returns the remoteUser based on the identified member object. Please let me know if that flow logic makes sense.

If not I'll just go back to the drawing board. Thank you!
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 169

So writing the LoginMatcher class as follows fixes the compilation error since remoteUser is written as object type Member. The problem now is that this throws a NulPointerException error.

java.lang.NullPointerException
admin.filters.LoginFilter.doFilter(LoginFilter.java:28)


So my question now is how do I ensure that the remoteUser value is correctly passed from the LoginFilter class to LoginMatcher?



The selectLogin method in the DAO class is:

Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 169

The solution is that LoginFilter works as a single class and there is no need for LoginMatcher for simply picking up the authenticated user session.


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unable to write filter that passes autheticated user data