• 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

Getting acegi Authentication object in Jsp

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


I'm trying to get the authentication object of the acegi security in the jsp using
(UserMaster)SecurityContextHolder.getContext().getAuthentication().getPrincipal()

i'm getting this object if this is put in <% %>

but if i'm using the same by

<c:set var="user" value="${SecurityContextHolder.getContext().getAuthentication().getPrincipal()}" />

i'm getting following exception

org.apache.jasper.JasperException: /WEB-INF/pages/Search.jsp(235,6) The function getContext must be used with a prefix when a default namespace is not specified
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)



Does anybody experienced this scenario? What i can do to get the user in my jstl variable?
 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.. all

This reply is just for sharing the solution..

<c:set var="authentication" value="${sessionScope['ACEGI_SECURITY_CONTEXT'].authentication}"/>

This is acegi's authentication object. And you can access the User object using

<c:set var="userName" value="${authentication.principal.userName}"/>

Hope this may help
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for sharing,
but is it a good thing to access the user principal from jsp ?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
but is it a good thing to access the user principal from jsp ?



Right. Its not recommended. Filter is meant for this kind of things.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the clarification
 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Actually i'm in need of welcoming the user by his name to home page after login. After login i need to show the home page. As acegi does the login, the success page is the home page and i'm having only the authentication object from the acegi. Thats why i accessed the principal in the jsp.

Can any one suggest how i can solve this problem securely

Thanks
Elizabath
 
reply
    Bookmark Topic Watch Topic
  • New Topic