Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

imp.- j_security_check authenticates .. but how to set session as well ..?

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i have a login page, this has a form with two textfields for username, password
<form action=j_security_check>
upon submission, this mechanism works and checks if username and password exists in database and then allows the user to go on.
PROBLEM: I also need to setAttribute for a session at this point, so that in the subsequent pages I know who the user is (ie. via the username) .. in order to do that however, I would need to first 'get' the value of username field, and then 'set' the session. however my form action .. goes to this unknown j_security_check and not to a page where I have control.
so how can i incorporate some code to also set session as the value of the user as entered in the username Textfield.
thanks
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sarim
Use the HttpServletRequest method getUserPrinciple to get a java.security.Principle object then use the getName method on it.
req.getUserPrinciple().getName()
Where req is the HttpServletRequest object passed in.
hope that helps
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or request.getRemoteUser()
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic