Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting acegi Authentication object in Jsp  RSS feed

 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing,
but is it a good thing to access the user principal from jsp ?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification
 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!