• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accesing request.getRemoteUser() using EL expressions

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Is there an elegant way to access information about username and possibly roles assigned to him using EL expressions??

In my JSPs I use conditionals to display different page contents to different users. The best solution to me would be something like this...

<c:choose>
<c:when test="${sessionScope.remoteUser==null}">
page content for user that has not logged in yet...
</c:when>
<c therwise>
Hello <c ut value="${sessionScope.remoteUser}"/> etc...
</c therwise>
</c:choose>

However the problem is that there is no sessionScope.remoteUser after the user has logged in (I know requestScope.remoteUser looks like it might work but it does not).

To make the above JSP work, a following scriptlet must be added before the JSTL conditionals:

<%
String user = request.getRemoteUser();
if(user!=null && request.getSession(false)!=null && session.getAttribute("remoteUser")==null)
session.setAttribute("remoteUser", user);

%>

How can I achieve my goal without that scriptlet??
Again the finnset solution would be if the code setting the remoteUser attribute ran only once, just after the user has successfuly loged in.

Is there a way to intercept the authentication procedure and smuggle some custom code there (for now I use form based authentication with JDBC Realm configured) ??

Thanx in advance for your suggestions.

Regards
Chris
 
Krzysiek Hycnar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> (I know requestScope.remoteUser looks like it might work but it does not).
Of course it's not supposed to work!! It's not a parameter neither an attribute <ashamed>
Chris
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably unnecessary: I guess you figured out ${request.remoteUser} then?

- Peter
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try ?
${pageContext.request.remoteUser}
 
Krzysiek Hycnar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
${pageContext.request.remoteUser} works!!
Thanx Rick
Chris

PS
Where can I read more about JSTL and EL expressions??
 
rick zorich
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got that out of "JSTL in Action" by Shawn Bayern.
But it only covers JSTL 1.0.
Does anybody have a book for JSTL 1.1 ?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I was learning JSTL, I kept a copy of this book handy. You can read about it in our JavaRanch Bunkhouse.

Once you understand how the EL interprets references, creating constructs like the above become quite second nature.
[ August 29, 2004: Message edited by: Bear Bibeault ]
 
rick zorich
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear, that book is a year old already.
What about JSTL 1.1 ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you could always do what I do and go straight to the specification. There's nothing quite like a peek into the horse's mouth.
 
reply
    Bookmark Topic Watch Topic
  • New Topic