We authenticate some users of our web application via Shibboleth. The application is built using the Play framework. I want to bind the headers that come from Shibboleth to a Play form. According to the the documentation, data binding is performed using Spring.
Usually, binding just works. If you have a form model class like
public User {
public String name;
}
then binding a form with a name field will match the two fields automatically.
One header that comes from Shibboleth is of the form Shib-Identity-Provider. I'd like to bind that to a field of my form model, but hyphens are not legal characters for field names in Java. Is there a way I can map the header name to a legal Java field name? This applies more generally too, can I configure the data binding so that I don't need to use identical form field names and Java class field names to get binding to work?
You can definitely create a class with different field names from the data binding.
For example you can create a case class Shib as follow:
case class Shib (provider: String)
and define the data binding function from the Play mapping
val formMapping = mapping(
"Shib-Identity-Provider" -> text
)(Shib.apply)(Shib.unapply)
then in your controller you can bind the data directly from the request.
You can also implement a custom Reads which will doing a similar thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With