Introduction to OGNL

Back
June 5, 2013

OGNL (or, if you spell it out, Object-Graph Navigation Language) can be a challenge the first time you use it to solve a problem. OGNL can be used in PingFederate to accomplish  mapping requirements that don't fit into a straight copy of one attribute value into another attribute. The biggest challenge is just getting through the basics of the language. Although OGNL looks and feels like Java, it's just different enough to make it a frustrating experience.

 

This article is part of a series I'm writing over the next few weeks to lay down the foundations of the language with concrete examples that you can execute in PingFederate. I'll be using the OGNL Language Guide on apache.com as a template for these topics, making them relevant to PingFederate.

 

You'll find the complete list of articles in my OGNL series at the end of this entry.

 

I will assume that you are familiar with coding in general and the Java language in particular, although you do not need to be an expert. Each example will be explained. I will provide code examples you can use to solve specific problems in PingFederate. Sometimes these code examples will just show the concept being discussed, but you can be sure that all the code examples provided will work in PingFederate. The Language Guide is a good starting point for some of the basics. Some things (for example, Constants) will not be covered in this series because the Guide does a good job. We will just use them as needed.

 

One question you may have is, 'why do I need to use OGNL?' Here are some possible reasons:

 

  • You only need to send a subset of the data in the attribute, for example you have a code value that contains department and division codes as one value but you only need the department code to be sent
  • You need to reformat the data, for example take a date that is MM/DD/YYYY and make it YYYY-MM-DD
  • The attribute value you have is not exactly what you need and it needs to be tweaked

 

The first step is to enable OGNL support in PingFederate. Refer to Enabling and disabling expressions in the PingFederate documentation for information about turning on OGNL support in your PingFederate server.

 

In the next issue in the series we will start with a simple OGNL example and learn how to fetch attributes in PingFederate. I hope that you find this series helpful, and I would be glad to hear from you on how this can be improved, or what additional topics on OGNL you would like to see.

 

OGNL Blog Series:

 

  1. Introduction to OGNL
  2. A simple OGNL expression
  3. Declaring variables in OGNL
  4. Method calls in OGNL
  5. Arrays in OGNL
  6. OGNL: What about those curly braces?
  7. Looping in OGNL
  8. Looping in OGNL take 2
  9. So what exactly is #this in OGNL?
  10. A continuing look at #this variable in OGNL
  11. Functions in OGNL
  12. Misc Topics in OGNL

 

John DaSilva develops training and solutions at Ping Identity.

 

This article is part of a series I'm writing over the next few weeks to lay down the foundations of the language with concrete examples that you can execute in PingFederate. I'll be using the OGNL Language Guide on apache.com as a template for these topics, making them relevant to PingFederate.

 

I will assume that you are familiar with coding in general and the Java language in particular, although you do not need to be an expert. Each example will be explained. I will provide code examples you can use to solve specific problems in PingFederate. Sometimes these code examples will just show the concept being discussed, but you can be sure that all the code examples provided will work in PingFederate. The Language Guide is a good starting point for some of the basics. Some things (for example, Constants) will not be covered in this series because the Guide does a good job. We will just use them as needed.

 

One question you may have is, 'why do I need to use OGNL?' Here are some possible reasons:

 

  • You only need to send a subset of the data in the attribute, for example you have a code value that contains department and division codes as one value but you only need the department code to be sent
  • You need to reformat the data, for example take a date that is MM/DD/YYYY and make it YYYY-MM-DD
  • The attribute value you have is not exactly what you need and it needs to be tweaked

 

The first step is to enable OGNL support in PingFederate. Refer to Enabling and disabling expressions in the PingFederate documentation for information about turning on OGNL support in your PingFederate server.

 

In the next issue in the series we will start with a simple OGNL example and learn how to fetch attributes in PingFederate. I hope that you find this series helpful, and I would be glad to hear from you on how this can be improved, or what additional topics on OGNL you would like to see.

 

John DaSilva develops training and solutions at Ping Identity.