URL encoding the entity ID in Velocity
Wessel, Keith
kwessel at illinois.edu
Wed Feb 3 15:29:52 EST 2016
Thanks, gentlemen. Should have paid more attention and realized I needed to set the value to a bean instead of just a class name. That was apparent in the comments.
I've tried, and I'm closer, but I think I still need a hint for bean creation. I've got a bean with an id element of custom.urlEncoder and a class of java.net.URLEncoder.
<bean id="custom.urlEncoder" class="java.net.URLEncoder" />
I'm assuming it needs some properties associated with it. Because, if I try to use it in my login template as:
$custom(urlEncoder).encode("$entityID","utf-8")
I get:
{urlEncoder=custom.urlEncoder}("urlEncoder).encode("<SP-entityID-here>","utf-8")
Am I missing something from the bean definition? Or from the way I'm calling it? Or both?
My apologies for the elementary questions; this is a part of Java that I _should_ know more about.
Keith
From: users [mailto:users-bounces at shibboleth.net] On Behalf Of Brent Putman
Sent: Wednesday, February 03, 2016 1:55 PM
To: users at shibboleth.net
Subject: Re: URL encoding the entity ID in Velocity
On 2/3/16 2:33 PM, Wessel, Keith wrote:
Thanks, Scott. An excellent enhancement. I wondered exactly what the "custom" variable meant at the top in the comments.
I'm having some trouble getting it working. I've uncommented the block you mentioned in global.xml and set the key to urlEncoder, the value to java.net.URLEncoder. I restarted Jetty to re-read global.xml. But when I put $urlEncoder.encode("$entityID", "utf-8") in my login.vm, Velocity gives me back a literal string. Same for when I make it $custom.urlEncoder.encode("$entityID","utf-8").
What am I doing wrong?
The bean is exposed in the template as a variable called "custom". [1] For some detailed discussion and examples, see the original Jira issue. [2]
Since in this case the custom object is a Map, if you defined an entry in the map with key "foo", you reference in the Velocity template like:
$custom.get("foo")
and Velocity supports some syntactic sugar variations for some types, like lists arrays and maps:
$custom["foo"]
Full usage possibilities you can glean from the Velocity user guide docs. [3]
[1] https://wiki.shibboleth.net/confluence/display/IDP30/VelocityVariables
[2] https://issues.shibboleth.net/jira/browse/IDP-774
[3] https://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html
More information about the users
mailing list