You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by wild_oscar <mi...@almeida.at> on 2010/03/12 18:20:57 UTC

How can one use OGNL on custom .tag files?

I have a custom tag file called with:

<help:date dateField="death.deathDate" label="Date of Death (dd-MM-yyyy)"/>

Inside the tag I want to have:
<s:date name="${dateField}.date" var="dt" format="${dateField}.format" />		
<s:textfield value="%{#dt}"/>

However, EL security doesn't allow for expressions in the s:date tag. I am
failing to make the s:date get the name from death.deathDate.date field. 

I've tried several alternatives in the name attribute of date:
%{#attr.dateField}.date, %{attr.dateField}.date, and I even tried:

<s:set var="aaa" >${dateField}.date</s:set>
<s:date name="%{#aaa}" var="dt" />		

None works. Can anyone point me to the right format?
-- 
View this message in context: http://old.nabble.com/How-can-one-use-OGNL-on-custom-.tag-files--tp27880257p27880257.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Getting the authenticated user from Spring Security for use in an Action

Posted by Lance Hill <la...@baldhead.com>.
I used the same method to obtain the Authentication, but it returns as null.
The user is logged in since it gets to the protected page I am accessing.
Any thoughts on how to get the properly populated SecurityContext? 


-----Original Message-----
From: Wes Wannemacher [mailto:wesw@wantii.com] 
Sent: Tuesday, March 16, 2010 5:54 PM
To: Struts Users Mailing List
Subject: Re: Getting the authenticated user from Spring Security for use in
an Action

I use -

SecurityContextHolder.getContext().getAuthentication()

I assume that if the object returned is null, then the user isn't logged in.

I am using spring-security 2.0.4.

-Wes

On Tue, Mar 16, 2010 at 5:42 PM, Lance Hill <la...@baldhead.com> wrote:
> I have Spring Security set up to use CasAutheticationProvider to provide a
> UserDetails object.
>
> I did find an example that uses the SecurityContext to obtain an
> Authentication object and grab the UserDetails from there. I am not sure
how
> to get access to the populated SecurityContext since
> SecurityContextHolder.getContext() is returning an empty SecurityContext
and
> I am not sure if that is the best way to access the user.
>
>
> -----Original Message-----
> From: Wes Wannemacher [mailto:wesw@wantii.com]
> Sent: Tuesday, March 16, 2010 5:16 PM
> To: Struts Users Mailing List
> Subject: Re: Getting the authenticated user from Spring Security for use
in
> an Action
>
> What mechanism are you using to handle authentication/authorization?
>
> -Wes
>
> On Tue, Mar 16, 2010 at 5:14 PM, Lance Hill <la...@baldhead.com> wrote:
>> I need to access information about the currently logged in user. I don't
>> think putting the user into the session during login is how it is
supposed
>> to be done, but I have not found examples of how to get access to the
>> current user from Spring/Spring Security. Can someone please provide a
> link
>> or brief example of the best practice?
>>
>>
>> Thank you.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Getting the authenticated user from Spring Security for use in an Action

Posted by Wes Wannemacher <we...@wantii.com>.
I use -

SecurityContextHolder.getContext().getAuthentication()

I assume that if the object returned is null, then the user isn't logged in.

I am using spring-security 2.0.4.

-Wes

On Tue, Mar 16, 2010 at 5:42 PM, Lance Hill <la...@baldhead.com> wrote:
> I have Spring Security set up to use CasAutheticationProvider to provide a
> UserDetails object.
>
> I did find an example that uses the SecurityContext to obtain an
> Authentication object and grab the UserDetails from there. I am not sure how
> to get access to the populated SecurityContext since
> SecurityContextHolder.getContext() is returning an empty SecurityContext and
> I am not sure if that is the best way to access the user.
>
>
> -----Original Message-----
> From: Wes Wannemacher [mailto:wesw@wantii.com]
> Sent: Tuesday, March 16, 2010 5:16 PM
> To: Struts Users Mailing List
> Subject: Re: Getting the authenticated user from Spring Security for use in
> an Action
>
> What mechanism are you using to handle authentication/authorization?
>
> -Wes
>
> On Tue, Mar 16, 2010 at 5:14 PM, Lance Hill <la...@baldhead.com> wrote:
>> I need to access information about the currently logged in user. I don't
>> think putting the user into the session during login is how it is supposed
>> to be done, but I have not found examples of how to get access to the
>> current user from Spring/Spring Security. Can someone please provide a
> link
>> or brief example of the best practice?
>>
>>
>> Thank you.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Getting the authenticated user from Spring Security for use in an Action

Posted by Lance Hill <la...@baldhead.com>.
I have Spring Security set up to use CasAutheticationProvider to provide a
UserDetails object. 

I did find an example that uses the SecurityContext to obtain an
Authentication object and grab the UserDetails from there. I am not sure how
to get access to the populated SecurityContext since
SecurityContextHolder.getContext() is returning an empty SecurityContext and
I am not sure if that is the best way to access the user.


-----Original Message-----
From: Wes Wannemacher [mailto:wesw@wantii.com] 
Sent: Tuesday, March 16, 2010 5:16 PM
To: Struts Users Mailing List
Subject: Re: Getting the authenticated user from Spring Security for use in
an Action

What mechanism are you using to handle authentication/authorization?

-Wes

On Tue, Mar 16, 2010 at 5:14 PM, Lance Hill <la...@baldhead.com> wrote:
> I need to access information about the currently logged in user. I don't
> think putting the user into the session during login is how it is supposed
> to be done, but I have not found examples of how to get access to the
> current user from Spring/Spring Security. Can someone please provide a
link
> or brief example of the best practice?
>
>
> Thank you.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Getting the authenticated user from Spring Security for use in an Action

Posted by Wes Wannemacher <we...@wantii.com>.
What mechanism are you using to handle authentication/authorization?

-Wes

On Tue, Mar 16, 2010 at 5:14 PM, Lance Hill <la...@baldhead.com> wrote:
> I need to access information about the currently logged in user. I don't
> think putting the user into the session during login is how it is supposed
> to be done, but I have not found examples of how to get access to the
> current user from Spring/Spring Security. Can someone please provide a link
> or brief example of the best practice?
>
>
> Thank you.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Getting the authenticated user from Spring Security for use in an Action

Posted by Lance Hill <la...@baldhead.com>.
I tried using that, but SecurityContextHolder.getContext() returns a null
value. Any thoughts on how to fix that?

-----Original Message-----
From: Hoying, Ken [mailto:Ken_Hoying@PremierInc.com] 
Sent: Wednesday, March 17, 2010 7:36 AM
To: Struts Users Mailing List
Subject: RE: Getting the authenticated user from Spring Security for use in
an Action

Try:

SecurityContextHolder.getContext().getAuthentication().getPrincipal()

-----Original Message-----
From: Lance Hill [mailto:lance@baldhead.com] 
Sent: Tuesday, March 16, 2010 5:15 PM
To: 'Struts Users Mailing List'
Subject: Getting the authenticated user from Spring Security for use in an
Action

I need to access information about the currently logged in user. I don't
think putting the user into the session during login is how it is supposed
to be done, but I have not found examples of how to get access to the
current user from Spring/Spring Security. Can someone please provide a link
or brief example of the best practice?


Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

-----------------------------------------
***Note:The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader of
this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If you have
received this communication in error, please notify the Sender
immediately by replying to the message and deleting it from your
computer.  Thank you.  Premier Inc.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Getting the authenticated user from Spring Security for use in an Action

Posted by "Hoying, Ken" <Ke...@PremierInc.com>.
Try:

SecurityContextHolder.getContext().getAuthentication().getPrincipal()

-----Original Message-----
From: Lance Hill [mailto:lance@baldhead.com] 
Sent: Tuesday, March 16, 2010 5:15 PM
To: 'Struts Users Mailing List'
Subject: Getting the authenticated user from Spring Security for use in an Action

I need to access information about the currently logged in user. I don't
think putting the user into the session during login is how it is supposed
to be done, but I have not found examples of how to get access to the
current user from Spring/Spring Security. Can someone please provide a link
or brief example of the best practice?


Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

-----------------------------------------
***Note:The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader of
this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If you have
received this communication in error, please notify the Sender
immediately by replying to the message and deleting it from your
computer.  Thank you.  Premier Inc.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Getting the authenticated user from Spring Security for use in an Action

Posted by Lance Hill <la...@baldhead.com>.
I need to access information about the currently logged in user. I don't
think putting the user into the session during login is how it is supposed
to be done, but I have not found examples of how to get access to the
current user from Spring/Spring Security. Can someone please provide a link
or brief example of the best practice?


Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How can one use OGNL on custom .tag files?

Posted by Dale Newfield <da...@newfield.org>.
wild_oscar wrote:
> However, EL security doesn't allow for expressions in the s:date tag.

This is true no matter where the tag resides (.jsp or .tag).

If you have an EL value you can use c:set to put it someplace (request 
scope might be simplest) where you can also address it using ognl.

> <s:set var="aaa" >${dateField}.date</s:set>

Note this is setting the struts variable aaa to the string resulting 
from evaluating "${dateField}.date", not the date object.

try something like this:
<c:set var="dateInTag" scope="request" value="${dateField}"/>
<s:date name="%{#request.dateInTag}"/>

and make sure that you've got taglib directives in the .tag file for all 
the tag libraries you want to use.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org